summaryrefslogtreecommitdiffstats
path: root/framework/src/domain/mimetreeparser/otp/multipartencrypted.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/domain/mimetreeparser/otp/multipartencrypted.cpp')
-rw-r--r--framework/src/domain/mimetreeparser/otp/multipartencrypted.cpp111
1 files changed, 111 insertions, 0 deletions
diff --git a/framework/src/domain/mimetreeparser/otp/multipartencrypted.cpp b/framework/src/domain/mimetreeparser/otp/multipartencrypted.cpp
new file mode 100644
index 00000000..7a049318
--- /dev/null
+++ b/framework/src/domain/mimetreeparser/otp/multipartencrypted.cpp
@@ -0,0 +1,111 @@
1/*
2 Copyright (c) 2016 Sandro Knauß <sknauss@kde.org>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include "multipartencrypted.h"
21
22#include "utils.h"
23
24#include "objecttreeparser.h"
25#include "messagepart.h"
26
27#include <KMime/Content>
28
29#include <QGpgME/Protocol>
30
31#include "mimetreeparser_debug.h"
32
33using namespace MimeTreeParser;
34
35const MultiPartEncryptedBodyPartFormatter *MultiPartEncryptedBodyPartFormatter::self;
36
37const Interface::BodyPartFormatter *MultiPartEncryptedBodyPartFormatter::create()
38{
39 if (!self) {
40 self = new MultiPartEncryptedBodyPartFormatter();
41 }
42 return self;
43}
44Interface::BodyPartFormatter::Result MultiPartEncryptedBodyPartFormatter::format(Interface::BodyPart *part, HtmlWriter *writer) const
45{
46 Q_UNUSED(writer)
47 const auto p = process(*part);
48 const auto mp = static_cast<MessagePart *>(p.data());
49 if (mp) {
50 mp->html(false);
51 return Ok;
52 }
53 return Failed;
54}
55
56Interface::MessagePart::Ptr MultiPartEncryptedBodyPartFormatter::process(Interface::BodyPart &part) const
57{
58 KMime::Content *node = part.content();
59
60 if (node->contents().isEmpty()) {
61 Q_ASSERT(false);
62 return MessagePart::Ptr();
63 }
64
65 const QGpgME::Protocol *useThisCryptProto = nullptr;
66
67 /*
68 ATTENTION: This code is to be replaced by the new 'auto-detect' feature. --------------------------------------
69 */
70 KMime::Content *data = findTypeInDirectChilds(node, "application/octet-stream");
71 if (data) {
72 useThisCryptProto = QGpgME::openpgp();
73 }
74 if (!data) {
75 data = findTypeInDirectChilds(node, "application/pkcs7-mime");
76 if (data) {
77 useThisCryptProto = QGpgME::smime();
78 }
79 }
80 /*
81 ---------------------------------------------------------------------------------------------------------------
82 */
83
84 if (!data) {
85 return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), node->contents().at(0), false));
86 }
87
88 part.nodeHelper()->setEncryptionState(node, KMMsgFullyEncrypted);
89
90 EncryptedMessagePart::Ptr mp(new EncryptedMessagePart(part.objectTreeParser(),
91 data->decodedText(), useThisCryptProto,
92 part.nodeHelper()->fromAsString(data), node));
93 mp->setIsEncrypted(true);
94 mp->setDecryptMessage(part.source()->decryptMessage());
95 PartMetaData *messagePart(mp->partMetaData());
96 if (!part.source()->decryptMessage()) {
97 part.nodeHelper()->setNodeProcessed(data, false); // Set the data node to done to prevent it from being processed
98 } else if (KMime::Content *newNode = part.nodeHelper()->decryptedNodeForContent(data)) {
99 // if we already have a decrypted node for part.objectTreeParser() encrypted node, don't do the decryption again
100 return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), newNode, true));
101 } else {
102 mp->startDecryption(data);
103
104 qCDebug(MIMETREEPARSER_LOG) << "decrypted, signed?:" << messagePart->isSigned;
105
106 if (!messagePart->inProgress) {
107 part.nodeHelper()->setNodeProcessed(data, false); // Set the data node to done to prevent it from being processed
108 }
109 }
110 return mp;
111}