diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-05-23 19:34:39 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-05-23 19:34:39 +0200 |
commit | 79fd78dd1bd0968bd7a8aee70093e514b0729afd (patch) | |
tree | 66aa949b874276ec2152ccb41ca36f7c4fe02089 /framework/src | |
parent | b968ea8ed364238c57c3e74cf2c122cb897cfbea (diff) | |
download | kube-79fd78dd1bd0968bd7a8aee70093e514b0729afd.tar.gz kube-79fd78dd1bd0968bd7a8aee70093e514b0729afd.zip |
Dropped in body-part formatters
Diffstat (limited to 'framework/src')
19 files changed, 1361 insertions, 124 deletions
diff --git a/framework/src/domain/mimetreeparser/otp/CMakeLists.txt b/framework/src/domain/mimetreeparser/otp/CMakeLists.txt index fcbe574f..f79277c8 100644 --- a/framework/src/domain/mimetreeparser/otp/CMakeLists.txt +++ b/framework/src/domain/mimetreeparser/otp/CMakeLists.txt | |||
@@ -6,7 +6,6 @@ find_package(Qt5 COMPONENTS REQUIRED Core Gui) | |||
6 | find_package(KF5Mime "4.87.0" CONFIG REQUIRED) | 6 | find_package(KF5Mime "4.87.0" CONFIG REQUIRED) |
7 | find_package(QGpgme CONFIG REQUIRED) | 7 | find_package(QGpgme CONFIG REQUIRED) |
8 | find_package(KF5Codecs CONFIG REQUIRED) | 8 | find_package(KF5Codecs CONFIG REQUIRED) |
9 | find_package(KF5Package CONFIG REQUIRED) | ||
10 | find_package(KF5I18n CONFIG REQUIRED) | 9 | find_package(KF5I18n CONFIG REQUIRED) |
11 | 10 | ||
12 | #add_definitions(-DTRANSLATION_DOMAIN=\"libmimetreeparser\") | 11 | #add_definitions(-DTRANSLATION_DOMAIN=\"libmimetreeparser\") |
@@ -14,18 +13,20 @@ find_package(KF5I18n CONFIG REQUIRED) | |||
14 | # target_include_directories does not handle empty include paths | 13 | # target_include_directories does not handle empty include paths |
15 | include_directories(${GPGME_INCLUDES}) | 14 | include_directories(${GPGME_INCLUDES}) |
16 | 15 | ||
17 | set(libmimetreeparser_main_SRCS | 16 | set(libmimetreeparser_SRCS |
18 | objecttreeparser.cpp | 17 | objecttreeparser.cpp |
19 | #bodyformatter/applicationpgpencrypted.cpp | 18 | |
20 | #bodyformatter/applicationpkcs7mime.cpp | 19 | #Bodyformatter |
21 | #bodyformatter/mailman.cpp | 20 | applicationpgpencrypted.cpp |
22 | #bodyformatter/multipartalternative.cpp | 21 | applicationpkcs7mime.cpp |
23 | #bodyformatter/multipartencrypted.cpp | 22 | mailman.cpp |
24 | #bodyformatter/multipartmixed.cpp | 23 | multipartalternative.cpp |
25 | #bodyformatter/multipartsigned.cpp | 24 | multipartencrypted.cpp |
26 | #bodyformatter/textplain.cpp | 25 | multipartmixed.cpp |
27 | #bodyformatter/texthtml.cpp | 26 | multipartsigned.cpp |
28 | #bodyformatter/utils.cpp | 27 | textplain.cpp |
28 | texthtml.cpp | ||
29 | utils.cpp | ||
29 | 30 | ||
30 | #Interfaces | 31 | #Interfaces |
31 | bodypartformatter.cpp | 32 | bodypartformatter.cpp |
@@ -39,7 +40,6 @@ set(libmimetreeparser_main_SRCS | |||
39 | cryptohelper.cpp | 40 | cryptohelper.cpp |
40 | nodehelper.cpp | 41 | nodehelper.cpp |
41 | messagepart.cpp | 42 | messagepart.cpp |
42 | utils.cpp | ||
43 | partnodebodypart.cpp | 43 | partnodebodypart.cpp |
44 | #Mementos | 44 | #Mementos |
45 | cryptobodypartmemento.cpp | 45 | cryptobodypartmemento.cpp |
@@ -57,104 +57,8 @@ set(libmimetreeparser_main_SRCS | |||
57 | attachmenttemporaryfilesdirs.cpp | 57 | attachmenttemporaryfilesdirs.cpp |
58 | ) | 58 | ) |
59 | 59 | ||
60 | #ecm_generate_headers(MimeTreeParser_Camelcaseviewer_HEADERS | ||
61 | # HEADER_NAMES | ||
62 | # AttachmentStrategy | ||
63 | # BodyPartFormatterBaseFactory | ||
64 | # Enums | ||
65 | # MessagePart | ||
66 | # NodeHelper | ||
67 | # ObjectTreeParser | ||
68 | # PartMetaData | ||
69 | # PartNodeBodyPart | ||
70 | # REQUIRED_HEADERS MimeTreeParser_viewer_HEADERS | ||
71 | # PREFIX MimeTreeParser | ||
72 | # RELATIVE viewer | ||
73 | # ) | ||
74 | # | ||
75 | #ecm_generate_headers(MimeTreeParser_Camelcaseutils_HEADERS | ||
76 | # HEADER_NAMES | ||
77 | # Util | ||
78 | # REQUIRED_HEADERS MimeTreeParser_utils_HEADERS | ||
79 | # PREFIX MimeTreeParser | ||
80 | # RELATIVE utils | ||
81 | # ) | ||
82 | # | ||
83 | #ecm_generate_headers(MimeTreeParser_Camelcaseinterfaces_HEADERS | ||
84 | # HEADER_NAMES | ||
85 | # BodyPartFormatter | ||
86 | # BodyPart | ||
87 | # HtmlWriter | ||
88 | # MessagePartRenderer | ||
89 | # ObjectTreeSource | ||
90 | # REQUIRED_HEADERS MimeTreeParser_interfaces_HEADERS | ||
91 | # PREFIX MimeTreeParser | ||
92 | # RELATIVE interfaces | ||
93 | # ) | ||
94 | # | ||
95 | #ecm_generate_headers(MimeTreeParser_Camelcasehtmlwriter_HEADERS | ||
96 | # HEADER_NAMES | ||
97 | # FileHtmlWriter | ||
98 | # QueueHtmlWriter | ||
99 | # REQUIRED_HEADERS MimeTreeParser_htmlwriter_HEADERS | ||
100 | # PREFIX MimeTreeParser | ||
101 | # RELATIVE htmlwriter | ||
102 | # ) | ||
103 | # | ||
104 | #ecm_generate_headers(MimeTreeParser_Camelcasetemporaryfile_HEADERS | ||
105 | # HEADER_NAMES | ||
106 | # AttachmentTemporaryFilesDirs | ||
107 | # REQUIRED_HEADERS MimeTreeParser_temporaryfile_HEADERS | ||
108 | # PREFIX MimeTreeParser | ||
109 | # RELATIVE temporaryfile | ||
110 | # ) | ||
111 | |||
112 | #install(FILES | ||
113 | # ${MimeTreeParser_Camelcasehtmlwriter_HEADERS} | ||
114 | # ${MimeTreeParser_Camelcaseutils_HEADERS} | ||
115 | # ${MimeTreeParser_Camelcaseinterfaces_HEADERS} | ||
116 | # ${MimeTreeParser_Camelcaseviewer_HEADERS} | ||
117 | # ${MimeTreeParser_Camelcasetemporaryfile_HEADERS} | ||
118 | # DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/MimeTreeParser | ||
119 | # COMPONENT Devel | ||
120 | # ) | ||
121 | # | ||
122 | #install(FILES | ||
123 | # ${MimeTreeParser_htmlwriter_HEADERS} | ||
124 | # ${MimeTreeParser_utils_HEADERS} | ||
125 | # ${MimeTreeParser_interfaces_HEADERS} | ||
126 | # ${MimeTreeParser_viewer_HEADERS} | ||
127 | # ${MimeTreeParser_temporaryfile_HEADERS} | ||
128 | # ${CMAKE_CURRENT_BINARY_DIR}/mimetreeparser_export.h | ||
129 | # ${CMAKE_CURRENT_BINARY_DIR}/mimetreeparser_debug.h | ||
130 | # | ||
131 | # DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/mimetreeparser | ||
132 | # COMPONENT Devel | ||
133 | # ) | ||
134 | # | ||
135 | #ecm_generate_pri_file(BASE_NAME MimeTreeParser | ||
136 | # LIB_NAME KF5MimeTreeParser | ||
137 | # FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/MimeTreeParser | ||
138 | # ) | ||
139 | # | ||
140 | #install(FILES | ||
141 | # ${PRI_FILENAME} | ||
142 | # DESTINATION ${ECM_MKSPECS_INSTALL_DIR} | ||
143 | # ) | ||
144 | |||
145 | set(libmimetreeparser_SRCS | ||
146 | ${libmimetreeparser_main_SRCS} | ||
147 | ) | ||
148 | |||
149 | #ecm_qt_declare_logging_category(libmimetreeparser_SRCS HEADER mimetreeparser_debug.h IDENTIFIER MIMETREEPARSER_LOG CATEGORY_NAME org.kde.pim.mimetreeparser) | ||
150 | |||
151 | add_library(kube_otp ${libmimetreeparser_SRCS}) | 60 | add_library(kube_otp ${libmimetreeparser_SRCS}) |
152 | 61 | ||
153 | #generate_export_header(KF5MimeTreeParser BASE_NAME mimetreeparser) | ||
154 | |||
155 | #set(mimetreeparser_LINK_LIBRARIES | ||
156 | # ) | ||
157 | |||
158 | target_link_libraries(kube_otp | 62 | target_link_libraries(kube_otp |
159 | PRIVATE | 63 | PRIVATE |
160 | QGpgme | 64 | QGpgme |
@@ -162,19 +66,5 @@ target_link_libraries(kube_otp | |||
162 | KF5::I18n | 66 | KF5::I18n |
163 | KF5::Mime | 67 | KF5::Mime |
164 | Qt5::Gui | 68 | Qt5::Gui |
165 | ) | 69 | ) |
166 | install(TARGETS kube_otp DESTINATION ${LIB_INSTALL_DIR}) | 70 | install(TARGETS kube_otp DESTINATION ${LIB_INSTALL_DIR}) |
167 | |||
168 | #install(TARGETS | ||
169 | # KF5MimeTreeParser | ||
170 | # EXPORT KF5MimeTreeParserTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS} ${LIBRARY_NAMELINK} | ||
171 | # ) | ||
172 | # | ||
173 | #set_target_properties(KF5MimeTreeParser PROPERTIES | ||
174 | # VERSION ${MIMETREEPARSER_VERSION_STRING} | ||
175 | # SOVERSION ${MIMETREEPARSER_SOVERSION} | ||
176 | # EXPORT_NAME MimeTreeParser | ||
177 | # ) | ||
178 | # | ||
179 | #target_include_directories(KF5MimeTreeParser INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR_KF5}/MimeTreeParser/;${KDE_INSTALL_INCLUDEDIR_KF5}/mimetreeparser>") | ||
180 | # | ||
diff --git a/framework/src/domain/mimetreeparser/otp/applicationpgpencrypted.cpp b/framework/src/domain/mimetreeparser/otp/applicationpgpencrypted.cpp new file mode 100644 index 00000000..e0f8e30c --- /dev/null +++ b/framework/src/domain/mimetreeparser/otp/applicationpgpencrypted.cpp | |||
@@ -0,0 +1,98 @@ | |||
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 "applicationpgpencrypted.h" | ||
21 | |||
22 | #include "utils.h" | ||
23 | |||
24 | #include "objecttreeparser.h" | ||
25 | #include "messagepart.h" | ||
26 | |||
27 | #include <QGpgME/Protocol> | ||
28 | |||
29 | #include <KMime/Content> | ||
30 | |||
31 | #include "mimetreeparser_debug.h" | ||
32 | |||
33 | using namespace MimeTreeParser; | ||
34 | |||
35 | const ApplicationPGPEncryptedBodyPartFormatter *ApplicationPGPEncryptedBodyPartFormatter::self; | ||
36 | |||
37 | const Interface::BodyPartFormatter *ApplicationPGPEncryptedBodyPartFormatter::create() | ||
38 | { | ||
39 | if (!self) { | ||
40 | self = new ApplicationPGPEncryptedBodyPartFormatter(); | ||
41 | } | ||
42 | return self; | ||
43 | } | ||
44 | |||
45 | Interface::BodyPartFormatter::Result ApplicationPGPEncryptedBodyPartFormatter::format(Interface::BodyPart *part, HtmlWriter *writer) const | ||
46 | { | ||
47 | Q_UNUSED(writer) | ||
48 | const auto p = process(*part); | ||
49 | const auto mp = static_cast<MessagePart *>(p.data()); | ||
50 | if (mp) { | ||
51 | mp->html(false); | ||
52 | return Ok; | ||
53 | } | ||
54 | return Failed; | ||
55 | } | ||
56 | |||
57 | Interface::MessagePart::Ptr ApplicationPGPEncryptedBodyPartFormatter::process(Interface::BodyPart &part) const | ||
58 | { | ||
59 | KMime::Content *node(part.content()); | ||
60 | |||
61 | if (node->decodedContent().trimmed() != "Version: 1") { | ||
62 | qCWarning(MIMETREEPARSER_LOG) << "Unknown PGP Version String:" << node->decodedContent().trimmed(); | ||
63 | } | ||
64 | |||
65 | if (!part.content()->parent()) { | ||
66 | return MessagePart::Ptr(); | ||
67 | } | ||
68 | |||
69 | KMime::Content *data = findTypeInDirectChilds(part.content()->parent(), "application/octet-stream"); | ||
70 | |||
71 | if (!data) { | ||
72 | return MessagePart::Ptr(); //new MimeMessagePart(part.objectTreeParser(), node, false)); | ||
73 | } | ||
74 | |||
75 | part.nodeHelper()->setEncryptionState(node, KMMsgFullyEncrypted); | ||
76 | |||
77 | EncryptedMessagePart::Ptr mp(new EncryptedMessagePart(part.objectTreeParser(), | ||
78 | data->decodedText(), QGpgME::openpgp(), | ||
79 | part.nodeHelper()->fromAsString(data), node)); | ||
80 | mp->setIsEncrypted(true); | ||
81 | mp->setDecryptMessage(part.source()->decryptMessage()); | ||
82 | PartMetaData *messagePart(mp->partMetaData()); | ||
83 | if (!part.source()->decryptMessage()) { | ||
84 | part.nodeHelper()->setNodeProcessed(data, false); // Set the data node to done to prevent it from being processed | ||
85 | } else if (KMime::Content *newNode = part.nodeHelper()->decryptedNodeForContent(data)) { | ||
86 | // if we already have a decrypted node for this encrypted node, don't do the decryption again | ||
87 | return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), newNode, part.objectTreeParser()->showOnlyOneMimePart())); | ||
88 | } else { | ||
89 | mp->startDecryption(data); | ||
90 | if (!messagePart->inProgress) { | ||
91 | part.nodeHelper()->setNodeProcessed(data, false); // Set the data node to done to prevent it from being processed | ||
92 | if (messagePart->isDecryptable && messagePart->isSigned) { | ||
93 | part.nodeHelper()->setSignatureState(node, KMMsgFullySigned); | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | return mp; | ||
98 | } | ||
diff --git a/framework/src/domain/mimetreeparser/otp/applicationpgpencrypted.h b/framework/src/domain/mimetreeparser/otp/applicationpgpencrypted.h new file mode 100644 index 00000000..f0f4865c --- /dev/null +++ b/framework/src/domain/mimetreeparser/otp/applicationpgpencrypted.h | |||
@@ -0,0 +1,41 @@ | |||
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 | #ifndef __MIMETREEPARSER_BODYFORAMATTER_APPLICATIONPGPENCYPTED_H__ | ||
21 | #define __MIMETREEPARSER_BODYFORAMATTER_APPLICATIONPGPENCYPTED_H__ | ||
22 | |||
23 | #include "bodypartformatter.h" | ||
24 | #include "bodypart.h" | ||
25 | |||
26 | namespace MimeTreeParser | ||
27 | { | ||
28 | |||
29 | class ApplicationPGPEncryptedBodyPartFormatter : public Interface::BodyPartFormatter | ||
30 | { | ||
31 | static const ApplicationPGPEncryptedBodyPartFormatter *self; | ||
32 | public: | ||
33 | Interface::MessagePart::Ptr process(Interface::BodyPart &part) const Q_DECL_OVERRIDE; | ||
34 | Interface::BodyPartFormatter::Result format(Interface::BodyPart *, HtmlWriter *) const Q_DECL_OVERRIDE; | ||
35 | using Interface::BodyPartFormatter::format; | ||
36 | static const Interface::BodyPartFormatter *create(); | ||
37 | }; | ||
38 | |||
39 | } | ||
40 | |||
41 | #endif | ||
diff --git a/framework/src/domain/mimetreeparser/otp/applicationpkcs7mime.cpp b/framework/src/domain/mimetreeparser/otp/applicationpkcs7mime.cpp new file mode 100644 index 00000000..bcfc0616 --- /dev/null +++ b/framework/src/domain/mimetreeparser/otp/applicationpkcs7mime.cpp | |||
@@ -0,0 +1,178 @@ | |||
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 "applicationpkcs7mime.h" | ||
21 | |||
22 | #include "utils.h" | ||
23 | |||
24 | #include "attachmentstrategy.h" | ||
25 | #include "objecttreeparser.h" | ||
26 | #include "messagepart.h" | ||
27 | |||
28 | #include <QGpgME/Protocol> | ||
29 | |||
30 | #include <KMime/Content> | ||
31 | |||
32 | #include <QTextCodec> | ||
33 | |||
34 | #include "mimetreeparser_debug.h" | ||
35 | |||
36 | using namespace MimeTreeParser; | ||
37 | |||
38 | const ApplicationPkcs7MimeBodyPartFormatter *ApplicationPkcs7MimeBodyPartFormatter::self; | ||
39 | |||
40 | const Interface::BodyPartFormatter *ApplicationPkcs7MimeBodyPartFormatter::create() | ||
41 | { | ||
42 | if (!self) { | ||
43 | self = new ApplicationPkcs7MimeBodyPartFormatter(); | ||
44 | } | ||
45 | return self; | ||
46 | } | ||
47 | Interface::BodyPartFormatter::Result ApplicationPkcs7MimeBodyPartFormatter::format(Interface::BodyPart *part, HtmlWriter *writer) const | ||
48 | { | ||
49 | Q_UNUSED(writer) | ||
50 | const auto p = process(*part); | ||
51 | const auto mp = static_cast<MessagePart *>(p.data()); | ||
52 | if (mp) { | ||
53 | mp->html(false); | ||
54 | return Ok; | ||
55 | } | ||
56 | return Failed; | ||
57 | } | ||
58 | |||
59 | Interface::MessagePart::Ptr ApplicationPkcs7MimeBodyPartFormatter::process(Interface::BodyPart &part) const | ||
60 | { | ||
61 | KMime::Content *node = part.content(); | ||
62 | |||
63 | if (node->head().isEmpty()) { | ||
64 | return MessagePart::Ptr(); | ||
65 | } | ||
66 | |||
67 | const auto smimeCrypto = QGpgME::smime(); | ||
68 | if (!smimeCrypto) { | ||
69 | return MessagePart::Ptr(); | ||
70 | } | ||
71 | |||
72 | const QString smimeType = node->contentType()->parameter(QStringLiteral("smime-type")).toLower(); | ||
73 | |||
74 | if (smimeType == QLatin1String("certs-only")) { | ||
75 | part.processResult()->setNeverDisplayInline(true); | ||
76 | |||
77 | CertMessagePart::Ptr mp(new CertMessagePart(part.objectTreeParser(), node, smimeCrypto, part.source()->autoImportKeys())); | ||
78 | return mp; | ||
79 | } | ||
80 | |||
81 | bool isSigned = (smimeType == QLatin1String("signed-data")); | ||
82 | bool isEncrypted = (smimeType == QLatin1String("enveloped-data")); | ||
83 | |||
84 | // Analyze "signTestNode" node to find/verify a signature. | ||
85 | // If zero part.objectTreeParser() verification was successfully done after | ||
86 | // decrypting via recursion by insertAndParseNewChildNode(). | ||
87 | KMime::Content *signTestNode = isEncrypted ? nullptr : node; | ||
88 | |||
89 | // We try decrypting the content | ||
90 | // if we either *know* that it is an encrypted message part | ||
91 | // or there is neither signed nor encrypted parameter. | ||
92 | MessagePart::Ptr mp; | ||
93 | if (!isSigned) { | ||
94 | if (isEncrypted) { | ||
95 | qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime == S/MIME TYPE: enveloped (encrypted) data"; | ||
96 | } else { | ||
97 | qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime - type unknown - enveloped (encrypted) data ?"; | ||
98 | } | ||
99 | |||
100 | auto _mp = EncryptedMessagePart::Ptr(new EncryptedMessagePart(part.objectTreeParser(), | ||
101 | node->decodedText(), smimeCrypto, | ||
102 | part.nodeHelper()->fromAsString(node), node)); | ||
103 | mp = _mp; | ||
104 | _mp->setIsEncrypted(true); | ||
105 | _mp->setDecryptMessage(part.source()->decryptMessage()); | ||
106 | PartMetaData *messagePart(_mp->partMetaData()); | ||
107 | if (!part.source()->decryptMessage()) { | ||
108 | isEncrypted = true; | ||
109 | signTestNode = nullptr; // PENDING(marc) to be abs. sure, we'd need to have to look at the content | ||
110 | } else { | ||
111 | _mp->startDecryption(); | ||
112 | if (messagePart->isDecryptable) { | ||
113 | qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime - encryption found - enveloped (encrypted) data !"; | ||
114 | isEncrypted = true; | ||
115 | part.nodeHelper()->setEncryptionState(node, KMMsgFullyEncrypted); | ||
116 | signTestNode = nullptr; | ||
117 | |||
118 | } else { | ||
119 | // decryption failed, which could be because the part was encrypted but | ||
120 | // decryption failed, or because we didn't know if it was encrypted, tried, | ||
121 | // and failed. If the message was not actually encrypted, we continue | ||
122 | // assuming it's signed | ||
123 | if (_mp->passphraseError() || (smimeType.isEmpty() && messagePart->isEncrypted)) { | ||
124 | isEncrypted = true; | ||
125 | signTestNode = nullptr; | ||
126 | } | ||
127 | |||
128 | if (isEncrypted) { | ||
129 | qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime - ERROR: COULD NOT DECRYPT enveloped data !"; | ||
130 | } else { | ||
131 | qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime - NO encryption found"; | ||
132 | } | ||
133 | } | ||
134 | } | ||
135 | |||
136 | if (isEncrypted) { | ||
137 | part.nodeHelper()->setEncryptionState(node, KMMsgFullyEncrypted); | ||
138 | } | ||
139 | } | ||
140 | |||
141 | // We now try signature verification if necessarry. | ||
142 | if (signTestNode) { | ||
143 | if (isSigned) { | ||
144 | qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime == S/MIME TYPE: opaque signed data"; | ||
145 | } else { | ||
146 | qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime - type unknown - opaque signed data ?"; | ||
147 | } | ||
148 | |||
149 | const QTextCodec *aCodec(part.objectTreeParser()->codecFor(signTestNode)); | ||
150 | const QByteArray signaturetext = signTestNode->decodedContent(); | ||
151 | auto _mp = SignedMessagePart::Ptr(new SignedMessagePart(part.objectTreeParser(), | ||
152 | aCodec->toUnicode(signaturetext), smimeCrypto, | ||
153 | part.nodeHelper()->fromAsString(node), signTestNode)); | ||
154 | mp = _mp; | ||
155 | //mp->setDecryptMessage(part.source()->decryptMessage()); | ||
156 | PartMetaData *messagePart(mp->partMetaData()); | ||
157 | if (smimeCrypto) { | ||
158 | _mp->startVerificationDetached(signaturetext, nullptr, QByteArray()); | ||
159 | } else { | ||
160 | messagePart->auditLogError = GpgME::Error(GPG_ERR_NOT_IMPLEMENTED); | ||
161 | } | ||
162 | |||
163 | if (_mp->isSigned()) { | ||
164 | if (!isSigned) { | ||
165 | qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime - signature found - opaque signed data !"; | ||
166 | isSigned = true; | ||
167 | } | ||
168 | |||
169 | if (signTestNode != node) { | ||
170 | part.nodeHelper()->setSignatureState(node, KMMsgFullySigned); | ||
171 | } | ||
172 | } else { | ||
173 | qCDebug(MIMETREEPARSER_LOG) << "pkcs7 mime - NO signature found :-("; | ||
174 | } | ||
175 | } | ||
176 | |||
177 | return mp; | ||
178 | } | ||
diff --git a/framework/src/domain/mimetreeparser/otp/applicationpkcs7mime.h b/framework/src/domain/mimetreeparser/otp/applicationpkcs7mime.h new file mode 100644 index 00000000..a9a33f7c --- /dev/null +++ b/framework/src/domain/mimetreeparser/otp/applicationpkcs7mime.h | |||
@@ -0,0 +1,41 @@ | |||
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 | #ifndef __MIMETREEPARSER_BODYFORAMATTER_APPLICATIONPKCS7MIME_H__ | ||
21 | #define __MIMETREEPARSER_BODYFORAMATTER_APPLICATIONPKCS7MIME_H__ | ||
22 | |||
23 | #include "bodypartformatter.h" | ||
24 | #include "bodypart.h" | ||
25 | |||
26 | namespace MimeTreeParser | ||
27 | { | ||
28 | |||
29 | class ApplicationPkcs7MimeBodyPartFormatter : public Interface::BodyPartFormatter | ||
30 | { | ||
31 | static const ApplicationPkcs7MimeBodyPartFormatter *self; | ||
32 | public: | ||
33 | Interface::MessagePart::Ptr process(Interface::BodyPart &part) const Q_DECL_OVERRIDE; | ||
34 | Interface::BodyPartFormatter::Result format(Interface::BodyPart *, HtmlWriter *) const Q_DECL_OVERRIDE; | ||
35 | using Interface::BodyPartFormatter::format; | ||
36 | static const Interface::BodyPartFormatter *create(); | ||
37 | }; | ||
38 | |||
39 | } | ||
40 | |||
41 | #endif | ||
diff --git a/framework/src/domain/mimetreeparser/otp/mailman.cpp b/framework/src/domain/mimetreeparser/otp/mailman.cpp new file mode 100644 index 00000000..e79ef0fa --- /dev/null +++ b/framework/src/domain/mimetreeparser/otp/mailman.cpp | |||
@@ -0,0 +1,183 @@ | |||
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 "mailman.h" | ||
21 | |||
22 | #include "utils.h" | ||
23 | |||
24 | #include "objecttreeparser.h" | ||
25 | #include "messagepart.h" | ||
26 | |||
27 | #include <KMime/Content> | ||
28 | |||
29 | #include "mimetreeparser_debug.h" | ||
30 | |||
31 | using namespace MimeTreeParser; | ||
32 | |||
33 | const MailmanBodyPartFormatter *MailmanBodyPartFormatter::self; | ||
34 | |||
35 | const Interface::BodyPartFormatter *MailmanBodyPartFormatter::create() | ||
36 | { | ||
37 | if (!self) { | ||
38 | self = new MailmanBodyPartFormatter(); | ||
39 | } | ||
40 | return self; | ||
41 | } | ||
42 | Interface::BodyPartFormatter::Result MailmanBodyPartFormatter::format(Interface::BodyPart *part, HtmlWriter *writer) const | ||
43 | { | ||
44 | Q_UNUSED(writer) | ||
45 | const auto p = process(*part); | ||
46 | const auto mp = static_cast<MessagePart *>(p.data()); | ||
47 | if (mp) { | ||
48 | mp->html(false); | ||
49 | return Ok; | ||
50 | } | ||
51 | return Failed; | ||
52 | } | ||
53 | |||
54 | bool MailmanBodyPartFormatter::isMailmanMessage(KMime::Content *curNode) const | ||
55 | { | ||
56 | if (!curNode || curNode->head().isEmpty()) { | ||
57 | return false; | ||
58 | } | ||
59 | if (curNode->hasHeader("X-Mailman-Version")) { | ||
60 | return true; | ||
61 | } | ||
62 | if (KMime::Headers::Base *header = curNode->headerByType("X-Mailer")) { | ||
63 | if (header->asUnicodeString().contains(QStringLiteral("MAILMAN"), Qt::CaseInsensitive)) { | ||
64 | return true; | ||
65 | } | ||
66 | } | ||
67 | return false; | ||
68 | } | ||
69 | |||
70 | Interface::MessagePart::Ptr MailmanBodyPartFormatter::process(Interface::BodyPart &part) const | ||
71 | { | ||
72 | KMime::Content *curNode = part.content(); | ||
73 | |||
74 | if (!isMailmanMessage(curNode)) { | ||
75 | return MessagePart::Ptr(); | ||
76 | } | ||
77 | |||
78 | const QString str = QString::fromLatin1(curNode->decodedContent()); | ||
79 | |||
80 | //### | ||
81 | const QLatin1String delim1("--__--__--\n\nMessage:"); | ||
82 | const QLatin1String delim2("--__--__--\r\n\r\nMessage:"); | ||
83 | const QLatin1String delimZ2("--__--__--\n\n_____________"); | ||
84 | const QLatin1String delimZ1("--__--__--\r\n\r\n_____________"); | ||
85 | QString partStr, digestHeaderStr; | ||
86 | int thisDelim = str.indexOf(delim1, Qt::CaseInsensitive); | ||
87 | if (thisDelim == -1) { | ||
88 | thisDelim = str.indexOf(delim2, Qt::CaseInsensitive); | ||
89 | } | ||
90 | if (thisDelim == -1) { | ||
91 | return MessagePart::Ptr(); | ||
92 | } | ||
93 | |||
94 | int nextDelim = str.indexOf(delim1, thisDelim + 1, Qt::CaseInsensitive); | ||
95 | if (-1 == nextDelim) { | ||
96 | nextDelim = str.indexOf(delim2, thisDelim + 1, Qt::CaseInsensitive); | ||
97 | } | ||
98 | if (-1 == nextDelim) { | ||
99 | nextDelim = str.indexOf(delimZ1, thisDelim + 1, Qt::CaseInsensitive); | ||
100 | } | ||
101 | if (-1 == nextDelim) { | ||
102 | nextDelim = str.indexOf(delimZ2, thisDelim + 1, Qt::CaseInsensitive); | ||
103 | } | ||
104 | if (nextDelim < 0) { | ||
105 | return MessagePart::Ptr(); | ||
106 | } | ||
107 | |||
108 | //if ( curNode->mRoot ) | ||
109 | // curNode = curNode->mRoot; | ||
110 | |||
111 | // at least one message found: build a mime tree | ||
112 | digestHeaderStr = QStringLiteral("Content-Type: text/plain\nContent-Description: digest header\n\n"); | ||
113 | digestHeaderStr += str.midRef(0, thisDelim); | ||
114 | |||
115 | MessagePartList::Ptr mpl(new MessagePartList(part.objectTreeParser())); | ||
116 | mpl->appendSubPart(createAndParseTempNode(part, part.topLevelContent(), digestHeaderStr.toLatin1().constData(), "Digest Header")); | ||
117 | //mReader->queueHtml("<br><hr><br>"); | ||
118 | // temporarily change curent node's Content-Type | ||
119 | // to get our embedded RfC822 messages properly inserted | ||
120 | curNode->contentType()->setMimeType("multipart/digest"); | ||
121 | while (-1 < nextDelim) { | ||
122 | int thisEoL = str.indexOf(QLatin1String("\nMessage:"), thisDelim, Qt::CaseInsensitive); | ||
123 | if (-1 < thisEoL) { | ||
124 | thisDelim = thisEoL + 1; | ||
125 | } else { | ||
126 | thisEoL = str.indexOf(QLatin1String("\n_____________"), thisDelim, Qt::CaseInsensitive); | ||
127 | if (-1 < thisEoL) { | ||
128 | thisDelim = thisEoL + 1; | ||
129 | } | ||
130 | } | ||
131 | thisEoL = str.indexOf(QLatin1Char('\n'), thisDelim); | ||
132 | if (-1 < thisEoL) { | ||
133 | thisDelim = thisEoL + 1; | ||
134 | } else { | ||
135 | thisDelim = thisDelim + 1; | ||
136 | } | ||
137 | //while( thisDelim < cstr.size() && '\n' == cstr[thisDelim] ) | ||
138 | // ++thisDelim; | ||
139 | |||
140 | partStr = QStringLiteral("Content-Type: message/rfc822\nContent-Description: embedded message\n\n"); | ||
141 | partStr += str.midRef(thisDelim, nextDelim - thisDelim); | ||
142 | QString subject = QStringLiteral("embedded message"); | ||
143 | QString subSearch = QStringLiteral("\nSubject:"); | ||
144 | int subPos = partStr.indexOf(subSearch, 0, Qt::CaseInsensitive); | ||
145 | if (-1 < subPos) { | ||
146 | subject = partStr.mid(subPos + subSearch.length()); | ||
147 | thisEoL = subject.indexOf(QLatin1Char('\n')); | ||
148 | if (-1 < thisEoL) { | ||
149 | subject.truncate(thisEoL); | ||
150 | } | ||
151 | } | ||
152 | qCDebug(MIMETREEPARSER_LOG) << " embedded message found: \"" << subject; | ||
153 | mpl->appendSubPart(createAndParseTempNode(part, part.topLevelContent(), partStr.toLatin1().constData(), subject.toLatin1().constData())); | ||
154 | //mReader->queueHtml("<br><hr><br>"); | ||
155 | thisDelim = nextDelim + 1; | ||
156 | nextDelim = str.indexOf(delim1, thisDelim, Qt::CaseInsensitive); | ||
157 | if (-1 == nextDelim) { | ||
158 | nextDelim = str.indexOf(delim2, thisDelim, Qt::CaseInsensitive); | ||
159 | } | ||
160 | if (-1 == nextDelim) { | ||
161 | nextDelim = str.indexOf(delimZ1, thisDelim, Qt::CaseInsensitive); | ||
162 | } | ||
163 | if (-1 == nextDelim) { | ||
164 | nextDelim = str.indexOf(delimZ2, thisDelim, Qt::CaseInsensitive); | ||
165 | } | ||
166 | } | ||
167 | // reset curent node's Content-Type | ||
168 | curNode->contentType()->setMimeType("text/plain"); | ||
169 | int thisEoL = str.indexOf(QLatin1String("_____________"), thisDelim); | ||
170 | if (-1 < thisEoL) { | ||
171 | thisDelim = thisEoL; | ||
172 | thisEoL = str.indexOf(QLatin1Char('\n'), thisDelim); | ||
173 | if (-1 < thisEoL) { | ||
174 | thisDelim = thisEoL + 1; | ||
175 | } | ||
176 | } else { | ||
177 | thisDelim = thisDelim + 1; | ||
178 | } | ||
179 | partStr = QStringLiteral("Content-Type: text/plain\nContent-Description: digest footer\n\n"); | ||
180 | partStr += str.midRef(thisDelim); | ||
181 | mpl->appendSubPart(createAndParseTempNode(part, part.topLevelContent(), partStr.toLatin1().constData(), "Digest Footer")); | ||
182 | return mpl; | ||
183 | } | ||
diff --git a/framework/src/domain/mimetreeparser/otp/mailman.h b/framework/src/domain/mimetreeparser/otp/mailman.h new file mode 100644 index 00000000..742830b2 --- /dev/null +++ b/framework/src/domain/mimetreeparser/otp/mailman.h | |||
@@ -0,0 +1,44 @@ | |||
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 | #ifndef __MIMETREEPARSER_BODYFORAMATTER_MAILMAN_H__ | ||
21 | #define __MIMETREEPARSER_BODYFORAMATTER_MAILMAN_H__ | ||
22 | |||
23 | #include "bodypartformatter.h" | ||
24 | #include "bodypart.h" | ||
25 | |||
26 | namespace MimeTreeParser | ||
27 | { | ||
28 | |||
29 | class MailmanBodyPartFormatter : public Interface::BodyPartFormatter | ||
30 | { | ||
31 | static const MailmanBodyPartFormatter *self; | ||
32 | public: | ||
33 | Interface::MessagePart::Ptr process(Interface::BodyPart &part) const Q_DECL_OVERRIDE; | ||
34 | Interface::BodyPartFormatter::Result format(Interface::BodyPart *, HtmlWriter *) const Q_DECL_OVERRIDE; | ||
35 | using Interface::BodyPartFormatter::format; | ||
36 | static const Interface::BodyPartFormatter *create(); | ||
37 | |||
38 | private: | ||
39 | bool isMailmanMessage(KMime::Content *curNode) const; | ||
40 | }; | ||
41 | |||
42 | } | ||
43 | |||
44 | #endif | ||
diff --git a/framework/src/domain/mimetreeparser/otp/multipartalternative.cpp b/framework/src/domain/mimetreeparser/otp/multipartalternative.cpp new file mode 100644 index 00000000..42c70e28 --- /dev/null +++ b/framework/src/domain/mimetreeparser/otp/multipartalternative.cpp | |||
@@ -0,0 +1,94 @@ | |||
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 "multipartalternative.h" | ||
21 | |||
22 | #include "utils.h" | ||
23 | |||
24 | #include "objecttreeparser.h" | ||
25 | #include "messagepart.h" | ||
26 | |||
27 | #include <KMime/Content> | ||
28 | |||
29 | #include "mimetreeparser_debug.h" | ||
30 | |||
31 | using namespace MimeTreeParser; | ||
32 | |||
33 | const MultiPartAlternativeBodyPartFormatter *MultiPartAlternativeBodyPartFormatter::self; | ||
34 | |||
35 | const Interface::BodyPartFormatter *MultiPartAlternativeBodyPartFormatter::create() | ||
36 | { | ||
37 | if (!self) { | ||
38 | self = new MultiPartAlternativeBodyPartFormatter(); | ||
39 | } | ||
40 | return self; | ||
41 | } | ||
42 | Interface::BodyPartFormatter::Result MultiPartAlternativeBodyPartFormatter::format(Interface::BodyPart *part, HtmlWriter *writer) const | ||
43 | { | ||
44 | Q_UNUSED(writer) | ||
45 | const auto p = process(*part); | ||
46 | const auto mp = static_cast<MessagePart *>(p.data()); | ||
47 | if (mp) { | ||
48 | mp->html(false); | ||
49 | return Ok; | ||
50 | } | ||
51 | return Failed; | ||
52 | } | ||
53 | |||
54 | Interface::MessagePart::Ptr MultiPartAlternativeBodyPartFormatter::process(Interface::BodyPart &part) const | ||
55 | { | ||
56 | KMime::Content *node = part.content(); | ||
57 | if (node->contents().isEmpty()) { | ||
58 | return MessagePart::Ptr(); | ||
59 | } | ||
60 | |||
61 | auto preferredMode = part.source()->preferredMode(); | ||
62 | AlternativeMessagePart::Ptr mp(new AlternativeMessagePart(part.objectTreeParser(), node, preferredMode)); | ||
63 | if (mp->mChildNodes.isEmpty()) { | ||
64 | MimeMessagePart::Ptr _mp(new MimeMessagePart(part.objectTreeParser(), node->contents().at(0), false)); | ||
65 | return _mp; | ||
66 | } | ||
67 | |||
68 | KMime::Content *dataIcal = mp->mChildNodes.contains(Util::MultipartIcal) ? mp->mChildNodes[Util::MultipartIcal] : nullptr; | ||
69 | KMime::Content *dataHtml = mp->mChildNodes.contains(Util::MultipartHtml) ? mp->mChildNodes[Util::MultipartHtml] : nullptr; | ||
70 | KMime::Content *dataPlain = mp->mChildNodes.contains(Util::MultipartPlain) ? mp->mChildNodes[Util::MultipartPlain] : nullptr; | ||
71 | |||
72 | // Make sure that in default ical is prefered over html and plain text | ||
73 | if (dataIcal && ((preferredMode != Util::MultipartHtml && preferredMode != Util::MultipartPlain))) { | ||
74 | if (dataHtml) { | ||
75 | part.nodeHelper()->setNodeProcessed(dataHtml, false); | ||
76 | } | ||
77 | if (dataPlain) { | ||
78 | part.nodeHelper()->setNodeProcessed(dataPlain, false); | ||
79 | } | ||
80 | preferredMode = Util::MultipartIcal; | ||
81 | } else if ((dataHtml && (preferredMode == Util::MultipartHtml || preferredMode == Util::Html)) || | ||
82 | (dataHtml && dataPlain && dataPlain->body().isEmpty())) { | ||
83 | if (dataPlain) { | ||
84 | part.nodeHelper()->setNodeProcessed(dataPlain, false); | ||
85 | } | ||
86 | preferredMode = Util::MultipartHtml; | ||
87 | } else if (!(preferredMode == Util::MultipartHtml) && dataPlain) { | ||
88 | part.nodeHelper()->setNodeProcessed(dataHtml, false); | ||
89 | preferredMode = Util::MultipartPlain; | ||
90 | } | ||
91 | part.source()->setHtmlMode(preferredMode, mp->availableModes()); | ||
92 | mp->mPreferredMode = preferredMode; | ||
93 | return mp; | ||
94 | } | ||
diff --git a/framework/src/domain/mimetreeparser/otp/multipartalternative.h b/framework/src/domain/mimetreeparser/otp/multipartalternative.h new file mode 100644 index 00000000..78e5ef38 --- /dev/null +++ b/framework/src/domain/mimetreeparser/otp/multipartalternative.h | |||
@@ -0,0 +1,41 @@ | |||
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 | #ifndef __MIMETREEPARSER_BODYFORAMATTER_MULTIPARTALTERNATIVE_H__ | ||
21 | #define __MIMETREEPARSER_BODYFORAMATTER_MULTIPARTALTERNATIVE_H__ | ||
22 | |||
23 | #include "bodypartformatter.h" | ||
24 | #include "bodypart.h" | ||
25 | |||
26 | namespace MimeTreeParser | ||
27 | { | ||
28 | |||
29 | class MultiPartAlternativeBodyPartFormatter : public Interface::BodyPartFormatter | ||
30 | { | ||
31 | static const MultiPartAlternativeBodyPartFormatter *self; | ||
32 | public: | ||
33 | Interface::MessagePart::Ptr process(Interface::BodyPart &part) const Q_DECL_OVERRIDE; | ||
34 | Interface::BodyPartFormatter::Result format(Interface::BodyPart *, HtmlWriter *) const Q_DECL_OVERRIDE; | ||
35 | using Interface::BodyPartFormatter::format; | ||
36 | static const Interface::BodyPartFormatter *create(); | ||
37 | }; | ||
38 | |||
39 | } | ||
40 | |||
41 | #endif | ||
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 | |||
33 | using namespace MimeTreeParser; | ||
34 | |||
35 | const MultiPartEncryptedBodyPartFormatter *MultiPartEncryptedBodyPartFormatter::self; | ||
36 | |||
37 | const Interface::BodyPartFormatter *MultiPartEncryptedBodyPartFormatter::create() | ||
38 | { | ||
39 | if (!self) { | ||
40 | self = new MultiPartEncryptedBodyPartFormatter(); | ||
41 | } | ||
42 | return self; | ||
43 | } | ||
44 | Interface::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 | |||
56 | Interface::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 | } | ||
diff --git a/framework/src/domain/mimetreeparser/otp/multipartencrypted.h b/framework/src/domain/mimetreeparser/otp/multipartencrypted.h new file mode 100644 index 00000000..0d2e01a8 --- /dev/null +++ b/framework/src/domain/mimetreeparser/otp/multipartencrypted.h | |||
@@ -0,0 +1,41 @@ | |||
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 | #ifndef __MIMETREEPARSER_BODYFORAMATTER_MULTIPARTENCRYPTED_H__ | ||
21 | #define __MIMETREEPARSER_BODYFORAMATTER_MULTIPARTENCRYPTED_H__ | ||
22 | |||
23 | #include "bodypartformatter.h" | ||
24 | #include "bodypart.h" | ||
25 | |||
26 | namespace MimeTreeParser | ||
27 | { | ||
28 | |||
29 | class MultiPartEncryptedBodyPartFormatter : public Interface::BodyPartFormatter | ||
30 | { | ||
31 | static const MultiPartEncryptedBodyPartFormatter *self; | ||
32 | public: | ||
33 | Interface::MessagePart::Ptr process(Interface::BodyPart &part) const Q_DECL_OVERRIDE; | ||
34 | Interface::BodyPartFormatter::Result format(Interface::BodyPart *, HtmlWriter *) const Q_DECL_OVERRIDE; | ||
35 | using Interface::BodyPartFormatter::format; | ||
36 | static const Interface::BodyPartFormatter *create(); | ||
37 | }; | ||
38 | |||
39 | } | ||
40 | |||
41 | #endif | ||
diff --git a/framework/src/domain/mimetreeparser/otp/multipartmixed.cpp b/framework/src/domain/mimetreeparser/otp/multipartmixed.cpp new file mode 100644 index 00000000..43056e51 --- /dev/null +++ b/framework/src/domain/mimetreeparser/otp/multipartmixed.cpp | |||
@@ -0,0 +1,61 @@ | |||
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 "multipartmixed.h" | ||
21 | |||
22 | #include "objecttreeparser.h" | ||
23 | #include "messagepart.h" | ||
24 | |||
25 | #include <KMime/Content> | ||
26 | |||
27 | #include "mimetreeparser_debug.h" | ||
28 | |||
29 | using namespace MimeTreeParser; | ||
30 | |||
31 | const MultiPartMixedBodyPartFormatter *MultiPartMixedBodyPartFormatter::self; | ||
32 | |||
33 | const Interface::BodyPartFormatter *MultiPartMixedBodyPartFormatter::create() | ||
34 | { | ||
35 | if (!self) { | ||
36 | self = new MultiPartMixedBodyPartFormatter(); | ||
37 | } | ||
38 | return self; | ||
39 | } | ||
40 | Interface::BodyPartFormatter::Result MultiPartMixedBodyPartFormatter::format(Interface::BodyPart *part, HtmlWriter *writer) const | ||
41 | { | ||
42 | Q_UNUSED(writer) | ||
43 | const auto p = process(*part); | ||
44 | const auto mp = static_cast<MessagePart *>(p.data()); | ||
45 | if (mp) { | ||
46 | mp->html(false); | ||
47 | return Ok; | ||
48 | } | ||
49 | return Failed; | ||
50 | } | ||
51 | |||
52 | Interface::MessagePart::Ptr MultiPartMixedBodyPartFormatter::process(Interface::BodyPart &part) const | ||
53 | { | ||
54 | if (part.content()->contents().isEmpty()) { | ||
55 | return MessagePart::Ptr(); | ||
56 | } | ||
57 | |||
58 | // normal treatment of the parts in the mp/mixed container | ||
59 | MimeMessagePart::Ptr mp(new MimeMessagePart(part.objectTreeParser(), part.content()->contents().at(0), false)); | ||
60 | return mp; | ||
61 | } | ||
diff --git a/framework/src/domain/mimetreeparser/otp/multipartmixed.h b/framework/src/domain/mimetreeparser/otp/multipartmixed.h new file mode 100644 index 00000000..0029501b --- /dev/null +++ b/framework/src/domain/mimetreeparser/otp/multipartmixed.h | |||
@@ -0,0 +1,41 @@ | |||
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 | #ifndef __MIMETREEPARSER_BODYFORAMATTER_MULTIPARTMIXED_H__ | ||
21 | #define __MIMETREEPARSER_BODYFORAMATTER_MULTIPARTMIXED_H__ | ||
22 | |||
23 | #include "bodypartformatter.h" | ||
24 | #include "bodypart.h" | ||
25 | |||
26 | namespace MimeTreeParser | ||
27 | { | ||
28 | |||
29 | class MultiPartMixedBodyPartFormatter : public Interface::BodyPartFormatter | ||
30 | { | ||
31 | static const MultiPartMixedBodyPartFormatter *self; | ||
32 | public: | ||
33 | Interface::MessagePart::Ptr process(Interface::BodyPart &part) const Q_DECL_OVERRIDE; | ||
34 | Interface::BodyPartFormatter::Result format(Interface::BodyPart *, HtmlWriter *) const Q_DECL_OVERRIDE; | ||
35 | using Interface::BodyPartFormatter::format; | ||
36 | static const Interface::BodyPartFormatter *create(); | ||
37 | }; | ||
38 | |||
39 | } | ||
40 | |||
41 | #endif | ||
diff --git a/framework/src/domain/mimetreeparser/otp/multipartsigned.cpp b/framework/src/domain/mimetreeparser/otp/multipartsigned.cpp new file mode 100644 index 00000000..cb0def6c --- /dev/null +++ b/framework/src/domain/mimetreeparser/otp/multipartsigned.cpp | |||
@@ -0,0 +1,114 @@ | |||
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 "multipartsigned.h" | ||
21 | |||
22 | #include "objecttreeparser.h" | ||
23 | #include "messagepart.h" | ||
24 | |||
25 | #include <KMime/Content> | ||
26 | |||
27 | #include <QGpgME/Protocol> | ||
28 | |||
29 | #include "mimetreeparser_debug.h" | ||
30 | |||
31 | #include <QTextCodec> | ||
32 | |||
33 | using namespace MimeTreeParser; | ||
34 | |||
35 | const MultiPartSignedBodyPartFormatter *MultiPartSignedBodyPartFormatter::self; | ||
36 | |||
37 | const Interface::BodyPartFormatter *MultiPartSignedBodyPartFormatter::create() | ||
38 | { | ||
39 | if (!self) { | ||
40 | self = new MultiPartSignedBodyPartFormatter(); | ||
41 | } | ||
42 | return self; | ||
43 | } | ||
44 | Interface::BodyPartFormatter::Result MultiPartSignedBodyPartFormatter::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 | |||
56 | Interface::MessagePart::Ptr MultiPartSignedBodyPartFormatter::process(Interface::BodyPart &part) const | ||
57 | { | ||
58 | KMime::Content *node = part.content(); | ||
59 | if (node->contents().size() != 2) { | ||
60 | qCDebug(MIMETREEPARSER_LOG) << "mulitpart/signed must have exactly two child parts!" << endl | ||
61 | << "processing as multipart/mixed"; | ||
62 | if (!node->contents().isEmpty()) { | ||
63 | return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), node->contents().at(0), false)); | ||
64 | } else { | ||
65 | return MessagePart::Ptr(); | ||
66 | } | ||
67 | } | ||
68 | |||
69 | KMime::Content *signedData = node->contents().at(0); | ||
70 | KMime::Content *signature = node->contents().at(1); | ||
71 | Q_ASSERT(signedData); | ||
72 | Q_ASSERT(signature); | ||
73 | |||
74 | QString protocolContentType = node->contentType()->parameter(QStringLiteral("protocol")).toLower(); | ||
75 | const QString signatureContentType = QLatin1String(signature->contentType()->mimeType().toLower()); | ||
76 | if (protocolContentType.isEmpty()) { | ||
77 | qCWarning(MIMETREEPARSER_LOG) << "Message doesn't set the protocol for the multipart/signed content-type, " | ||
78 | "using content-type of the signature:" << signatureContentType; | ||
79 | protocolContentType = signatureContentType; | ||
80 | } | ||
81 | |||
82 | const QGpgME::Protocol *protocol = nullptr; | ||
83 | if (protocolContentType == QLatin1String("application/pkcs7-signature") || | ||
84 | protocolContentType == QLatin1String("application/x-pkcs7-signature")) { | ||
85 | protocol = QGpgME::smime(); | ||
86 | } else if (protocolContentType == QLatin1String("application/pgp-signature") || | ||
87 | protocolContentType == QLatin1String("application/x-pgp-signature")) { | ||
88 | protocol = QGpgME::openpgp(); | ||
89 | } | ||
90 | |||
91 | if (!protocol) { | ||
92 | return MessagePart::Ptr(new MimeMessagePart(part.objectTreeParser(), signedData, false)); | ||
93 | } | ||
94 | |||
95 | part.nodeHelper()->setNodeProcessed(signature, true); | ||
96 | |||
97 | part.nodeHelper()->setSignatureState(node, KMMsgFullySigned); | ||
98 | |||
99 | const QByteArray cleartext = KMime::LFtoCRLF(signedData->encodedContent()); | ||
100 | const QTextCodec *aCodec(part.objectTreeParser()->codecFor(signedData)); | ||
101 | |||
102 | SignedMessagePart::Ptr mp(new SignedMessagePart(part.objectTreeParser(), | ||
103 | aCodec->toUnicode(cleartext), protocol, | ||
104 | part.nodeHelper()->fromAsString(node), signature)); | ||
105 | PartMetaData *messagePart(mp->partMetaData()); | ||
106 | |||
107 | if (protocol) { | ||
108 | mp->startVerificationDetached(cleartext, signedData, signature->decodedContent()); | ||
109 | } else { | ||
110 | messagePart->auditLogError = GpgME::Error(GPG_ERR_NOT_IMPLEMENTED); | ||
111 | } | ||
112 | |||
113 | return mp; | ||
114 | } | ||
diff --git a/framework/src/domain/mimetreeparser/otp/multipartsigned.h b/framework/src/domain/mimetreeparser/otp/multipartsigned.h new file mode 100644 index 00000000..4b8921ad --- /dev/null +++ b/framework/src/domain/mimetreeparser/otp/multipartsigned.h | |||
@@ -0,0 +1,41 @@ | |||
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 | #ifndef __MIMETREEPARSER_BODYFORAMATTER_MULTIPARTSIGNED_H__ | ||
21 | #define __MIMETREEPARSER_BODYFORAMATTER_MULTIPARTSIGNED_H__ | ||
22 | |||
23 | #include "bodypartformatter.h" | ||
24 | #include "bodypart.h" | ||
25 | |||
26 | namespace MimeTreeParser | ||
27 | { | ||
28 | |||
29 | class MultiPartSignedBodyPartFormatter : public Interface::BodyPartFormatter | ||
30 | { | ||
31 | static const MultiPartSignedBodyPartFormatter *self; | ||
32 | public: | ||
33 | Interface::MessagePart::Ptr process(Interface::BodyPart &part) const Q_DECL_OVERRIDE; | ||
34 | Interface::BodyPartFormatter::Result format(Interface::BodyPart *, HtmlWriter *) const Q_DECL_OVERRIDE; | ||
35 | using Interface::BodyPartFormatter::format; | ||
36 | static const Interface::BodyPartFormatter *create(); | ||
37 | }; | ||
38 | |||
39 | } | ||
40 | |||
41 | #endif | ||
diff --git a/framework/src/domain/mimetreeparser/otp/texthtml.cpp b/framework/src/domain/mimetreeparser/otp/texthtml.cpp new file mode 100644 index 00000000..51332cff --- /dev/null +++ b/framework/src/domain/mimetreeparser/otp/texthtml.cpp | |||
@@ -0,0 +1,58 @@ | |||
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 "texthtml.h" | ||
21 | |||
22 | #include "attachmentstrategy.h" | ||
23 | #include "objecttreeparser.h" | ||
24 | #include "messagepart.h" | ||
25 | |||
26 | #include <KMime/Content> | ||
27 | |||
28 | #include "mimetreeparser_debug.h" | ||
29 | |||
30 | using namespace MimeTreeParser; | ||
31 | |||
32 | const TextHtmlBodyPartFormatter *TextHtmlBodyPartFormatter::self; | ||
33 | |||
34 | const Interface::BodyPartFormatter *TextHtmlBodyPartFormatter::create() | ||
35 | { | ||
36 | if (!self) { | ||
37 | self = new TextHtmlBodyPartFormatter(); | ||
38 | } | ||
39 | return self; | ||
40 | } | ||
41 | Interface::BodyPartFormatter::Result TextHtmlBodyPartFormatter::format(Interface::BodyPart *part, HtmlWriter *writer) const | ||
42 | { | ||
43 | Q_UNUSED(writer) | ||
44 | const auto p = process(*part); | ||
45 | const auto mp = static_cast<MessagePart *>(p.data()); | ||
46 | if (mp) { | ||
47 | mp->html(false); | ||
48 | return Ok; | ||
49 | } | ||
50 | return Failed; | ||
51 | } | ||
52 | |||
53 | Interface::MessagePart::Ptr TextHtmlBodyPartFormatter::process(Interface::BodyPart &part) const | ||
54 | { | ||
55 | KMime::Content *node = part.content(); | ||
56 | HtmlMessagePart::Ptr mp(new HtmlMessagePart(part.objectTreeParser(), node, part.source())); | ||
57 | return mp; | ||
58 | } | ||
diff --git a/framework/src/domain/mimetreeparser/otp/texthtml.h b/framework/src/domain/mimetreeparser/otp/texthtml.h new file mode 100644 index 00000000..a03cfe50 --- /dev/null +++ b/framework/src/domain/mimetreeparser/otp/texthtml.h | |||
@@ -0,0 +1,41 @@ | |||
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 | #ifndef __MIMETREEPARSER_BODYFORAMATTER_TEXTHTML_H__ | ||
21 | #define __MIMETREEPARSER_BODYFORAMATTER_TEXTHTML_H__ | ||
22 | |||
23 | #include "bodypartformatter.h" | ||
24 | #include "bodypart.h" | ||
25 | |||
26 | namespace MimeTreeParser | ||
27 | { | ||
28 | |||
29 | class TextHtmlBodyPartFormatter : public Interface::BodyPartFormatter | ||
30 | { | ||
31 | static const TextHtmlBodyPartFormatter *self; | ||
32 | public: | ||
33 | Interface::MessagePart::Ptr process(Interface::BodyPart &part) const Q_DECL_OVERRIDE; | ||
34 | Interface::BodyPartFormatter::Result format(Interface::BodyPart *, HtmlWriter *) const Q_DECL_OVERRIDE; | ||
35 | using Interface::BodyPartFormatter::format; | ||
36 | static const Interface::BodyPartFormatter *create(); | ||
37 | }; | ||
38 | |||
39 | } | ||
40 | |||
41 | #endif | ||
diff --git a/framework/src/domain/mimetreeparser/otp/textplain.cpp b/framework/src/domain/mimetreeparser/otp/textplain.cpp new file mode 100644 index 00000000..d3437f04 --- /dev/null +++ b/framework/src/domain/mimetreeparser/otp/textplain.cpp | |||
@@ -0,0 +1,78 @@ | |||
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 "textplain.h" | ||
21 | |||
22 | #include "attachmentstrategy.h" | ||
23 | #include "objecttreeparser.h" | ||
24 | #include "messagepart.h" | ||
25 | |||
26 | #include <KMime/Content> | ||
27 | |||
28 | #include "mimetreeparser_debug.h" | ||
29 | |||
30 | using namespace MimeTreeParser; | ||
31 | |||
32 | const TextPlainBodyPartFormatter *TextPlainBodyPartFormatter::self; | ||
33 | |||
34 | const Interface::BodyPartFormatter *TextPlainBodyPartFormatter::create() | ||
35 | { | ||
36 | if (!self) { | ||
37 | self = new TextPlainBodyPartFormatter(); | ||
38 | } | ||
39 | return self; | ||
40 | } | ||
41 | Interface::BodyPartFormatter::Result TextPlainBodyPartFormatter::format(Interface::BodyPart *part, HtmlWriter *writer) const | ||
42 | { | ||
43 | Q_UNUSED(writer) | ||
44 | const auto p = process(*part); | ||
45 | const auto mp = static_cast<MessagePart *>(p.data()); | ||
46 | if (mp) { | ||
47 | mp->html(false); | ||
48 | return Ok; | ||
49 | } | ||
50 | return Failed; | ||
51 | } | ||
52 | |||
53 | Interface::MessagePart::Ptr TextPlainBodyPartFormatter::process(Interface::BodyPart &part) const | ||
54 | { | ||
55 | KMime::Content *node = part.content(); | ||
56 | const bool isFirstTextPart = (node->topLevel()->textContent() == node); | ||
57 | |||
58 | QString label = NodeHelper::fileName(node); | ||
59 | |||
60 | const bool bDrawFrame = !isFirstTextPart | ||
61 | && !part.objectTreeParser()->showOnlyOneMimePart() | ||
62 | && !label.isEmpty(); | ||
63 | const QString fileName = part.nodeHelper()->writeNodeToTempFile(node); | ||
64 | |||
65 | TextMessagePart::Ptr mp; | ||
66 | if (isFirstTextPart) { | ||
67 | mp = TextMessagePart::Ptr(new TextMessagePart(part.objectTreeParser(), node, bDrawFrame, fileName.isEmpty(), part.source()->decryptMessage())); | ||
68 | } else { | ||
69 | mp = TextMessagePart::Ptr(new AttachmentMessagePart(part.objectTreeParser(), node, bDrawFrame, fileName.isEmpty(), part.source()->decryptMessage())); | ||
70 | } | ||
71 | |||
72 | part.processResult()->setInlineSignatureState(mp->signatureState()); | ||
73 | part.processResult()->setInlineEncryptionState(mp->encryptionState()); | ||
74 | |||
75 | part.nodeHelper()->setNodeDisplayedEmbedded(node, true); | ||
76 | |||
77 | return mp; | ||
78 | } | ||
diff --git a/framework/src/domain/mimetreeparser/otp/textplain.h b/framework/src/domain/mimetreeparser/otp/textplain.h new file mode 100644 index 00000000..c97a6aec --- /dev/null +++ b/framework/src/domain/mimetreeparser/otp/textplain.h | |||
@@ -0,0 +1,41 @@ | |||
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 | #ifndef __MIMETREEPARSER_BODYFORAMATTER_TEXTPLAIN_H__ | ||
21 | #define __MIMETREEPARSER_BODYFORAMATTER_TEXTPLAIN_H__ | ||
22 | |||
23 | #include "bodypartformatter.h" | ||
24 | #include "bodypart.h" | ||
25 | |||
26 | namespace MimeTreeParser | ||
27 | { | ||
28 | |||
29 | class TextPlainBodyPartFormatter : public Interface::BodyPartFormatter | ||
30 | { | ||
31 | static const TextPlainBodyPartFormatter *self; | ||
32 | public: | ||
33 | Interface::MessagePart::Ptr process(Interface::BodyPart &part) const Q_DECL_OVERRIDE; | ||
34 | Interface::BodyPartFormatter::Result format(Interface::BodyPart *, HtmlWriter *) const Q_DECL_OVERRIDE; | ||
35 | using Interface::BodyPartFormatter::format; | ||
36 | static const Interface::BodyPartFormatter *create(); | ||
37 | }; | ||
38 | |||
39 | } | ||
40 | |||
41 | #endif | ||