diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-04-24 15:16:04 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-04-25 10:24:22 +0200 |
commit | 41f1c5c6b1403306535f308d2656a3ba94fb9a5c (patch) | |
tree | 125ed924281e37422e4c01d79a2b633b9ecbd9ae /framework/src/domain/mime/mimetreeparser | |
parent | 14e46bdc5647c03e667a88676916ef414adf69f3 (diff) | |
download | kube-41f1c5c6b1403306535f308d2656a3ba94fb9a5c.tar.gz kube-41f1c5c6b1403306535f308d2656a3ba94fb9a5c.zip |
Deal with rfc822 header parts
As inserted by autocrypt enabled clients.
Diffstat (limited to 'framework/src/domain/mime/mimetreeparser')
4 files changed, 63 insertions, 14 deletions
diff --git a/framework/src/domain/mime/mimetreeparser/bodypartformatter_impl.cpp b/framework/src/domain/mime/mimetreeparser/bodypartformatter_impl.cpp index 532a906e..a6713fef 100644 --- a/framework/src/domain/mime/mimetreeparser/bodypartformatter_impl.cpp +++ b/framework/src/domain/mime/mimetreeparser/bodypartformatter_impl.cpp | |||
@@ -92,34 +92,48 @@ class MessageRfc822BodyPartFormatter | |||
92 | { | 92 | { |
93 | static const MessageRfc822BodyPartFormatter *self; | 93 | static const MessageRfc822BodyPartFormatter *self; |
94 | public: | 94 | public: |
95 | MessagePart::Ptr process(Interface::BodyPart &) const Q_DECL_OVERRIDE; | 95 | MessagePart::Ptr process(Interface::BodyPart &part) const Q_DECL_OVERRIDE |
96 | static const MimeTreeParser::Interface::BodyPartFormatter *create(); | 96 | { |
97 | return MessagePart::Ptr(new EncapsulatedRfc822MessagePart(part.objectTreeParser(), part.content(), part.content()->bodyAsMessage())); | ||
98 | } | ||
99 | |||
100 | static const MimeTreeParser::Interface::BodyPartFormatter *create() | ||
101 | { | ||
102 | if (!self) { | ||
103 | self = new MessageRfc822BodyPartFormatter(); | ||
104 | } | ||
105 | return self; | ||
106 | } | ||
97 | }; | 107 | }; |
98 | 108 | ||
99 | const MessageRfc822BodyPartFormatter *MessageRfc822BodyPartFormatter::self; | 109 | const MessageRfc822BodyPartFormatter *MessageRfc822BodyPartFormatter::self; |
100 | 110 | ||
101 | const MimeTreeParser::Interface::BodyPartFormatter *MessageRfc822BodyPartFormatter::create() | 111 | class HeadersBodyPartFormatter |
112 | : public MimeTreeParser::Interface::BodyPartFormatter | ||
102 | { | 113 | { |
103 | if (!self) { | 114 | static const HeadersBodyPartFormatter *self; |
104 | self = new MessageRfc822BodyPartFormatter(); | 115 | public: |
116 | MessagePart::Ptr process(Interface::BodyPart &part) const Q_DECL_OVERRIDE | ||
117 | { | ||
118 | return MessagePart::Ptr(new HeadersPart(part.objectTreeParser(), part.content())); | ||
105 | } | 119 | } |
106 | return self; | ||
107 | } | ||
108 | 120 | ||
109 | MessagePart::Ptr MessageRfc822BodyPartFormatter::process(Interface::BodyPart &part) const | 121 | static const MimeTreeParser::Interface::BodyPartFormatter *create() { |
110 | { | 122 | if (!self) { |
111 | const KMime::Message::Ptr message = part.content()->bodyAsMessage(); | 123 | self = new HeadersBodyPartFormatter(); |
112 | return MessagePart::Ptr(new EncapsulatedRfc822MessagePart(part.objectTreeParser(), part.content(), message)); | 124 | } |
113 | } | 125 | return self; |
126 | } | ||
127 | }; | ||
114 | 128 | ||
115 | typedef TextPlainBodyPartFormatter ApplicationPgpBodyPartFormatter; | 129 | const HeadersBodyPartFormatter *HeadersBodyPartFormatter::self = nullptr; |
116 | 130 | ||
117 | } // anon namespace | 131 | } // anon namespace |
118 | 132 | ||
119 | void BodyPartFormatterBaseFactoryPrivate::messageviewer_create_builtin_bodypart_formatters() | 133 | void BodyPartFormatterBaseFactoryPrivate::messageviewer_create_builtin_bodypart_formatters() |
120 | { | 134 | { |
121 | insert("application", "octet-stream", AnyTypeBodyPartFormatter::create()); | 135 | insert("application", "octet-stream", AnyTypeBodyPartFormatter::create()); |
122 | insert("application", "pgp", ApplicationPgpBodyPartFormatter::create()); | 136 | insert("application", "pgp", TextPlainBodyPartFormatter::create()); |
123 | insert("application", "pkcs7-mime", ApplicationPkcs7MimeBodyPartFormatter::create()); | 137 | insert("application", "pkcs7-mime", ApplicationPkcs7MimeBodyPartFormatter::create()); |
124 | insert("application", "x-pkcs7-mime", ApplicationPkcs7MimeBodyPartFormatter::create()); | 138 | insert("application", "x-pkcs7-mime", ApplicationPkcs7MimeBodyPartFormatter::create()); |
125 | insert("application", "pgp-encrypted", ApplicationPGPEncryptedBodyPartFormatter::create()); | 139 | insert("application", "pgp-encrypted", ApplicationPGPEncryptedBodyPartFormatter::create()); |
@@ -129,6 +143,7 @@ void BodyPartFormatterBaseFactoryPrivate::messageviewer_create_builtin_bodypart_ | |||
129 | insert("text", "rtf", AnyTypeBodyPartFormatter::create()); | 143 | insert("text", "rtf", AnyTypeBodyPartFormatter::create()); |
130 | insert("text", "plain", MailmanBodyPartFormatter::create()); | 144 | insert("text", "plain", MailmanBodyPartFormatter::create()); |
131 | insert("text", "plain", TextPlainBodyPartFormatter::create()); | 145 | insert("text", "plain", TextPlainBodyPartFormatter::create()); |
146 | insert("text", "rfc822-headers", HeadersBodyPartFormatter::create()); | ||
132 | insert("text", "*", MailmanBodyPartFormatter::create()); | 147 | insert("text", "*", MailmanBodyPartFormatter::create()); |
133 | insert("text", "*", TextPlainBodyPartFormatter::create()); | 148 | insert("text", "*", TextPlainBodyPartFormatter::create()); |
134 | 149 | ||
diff --git a/framework/src/domain/mime/mimetreeparser/messagepart.cpp b/framework/src/domain/mime/mimetreeparser/messagepart.cpp index 541efd7f..17719ff8 100644 --- a/framework/src/domain/mime/mimetreeparser/messagepart.cpp +++ b/framework/src/domain/mime/mimetreeparser/messagepart.cpp | |||
@@ -1160,3 +1160,13 @@ QDateTime EncapsulatedRfc822MessagePart::date() const | |||
1160 | } | 1160 | } |
1161 | return {}; | 1161 | return {}; |
1162 | } | 1162 | } |
1163 | |||
1164 | HeadersPart::HeadersPart(ObjectTreeParser *otp, KMime::Content *node) | ||
1165 | : MessagePart(otp, QString(), node) | ||
1166 | { | ||
1167 | } | ||
1168 | |||
1169 | HeadersPart::~HeadersPart() | ||
1170 | { | ||
1171 | |||
1172 | } | ||
diff --git a/framework/src/domain/mime/mimetreeparser/messagepart.h b/framework/src/domain/mime/mimetreeparser/messagepart.h index 1d416e8f..c039637a 100644 --- a/framework/src/domain/mime/mimetreeparser/messagepart.h +++ b/framework/src/domain/mime/mimetreeparser/messagepart.h | |||
@@ -375,6 +375,15 @@ protected: | |||
375 | friend class ::PartPrivate; | 375 | friend class ::PartPrivate; |
376 | }; | 376 | }; |
377 | 377 | ||
378 | class HeadersPart : public MessagePart | ||
379 | { | ||
380 | Q_OBJECT | ||
381 | public: | ||
382 | typedef QSharedPointer<HeadersPart> Ptr; | ||
383 | HeadersPart(ObjectTreeParser *otp, KMime::Content *node); | ||
384 | virtual ~HeadersPart(); | ||
385 | }; | ||
386 | |||
378 | } | 387 | } |
379 | 388 | ||
380 | #endif //__MIMETREEPARSER_MESSAGEPART_H__ | 389 | #endif //__MIMETREEPARSER_MESSAGEPART_H__ |
diff --git a/framework/src/domain/mime/mimetreeparser/tests/mimetreeparsertest.cpp b/framework/src/domain/mime/mimetreeparser/tests/mimetreeparsertest.cpp index 961dbf9a..90a07a7c 100644 --- a/framework/src/domain/mime/mimetreeparser/tests/mimetreeparsertest.cpp +++ b/framework/src/domain/mime/mimetreeparser/tests/mimetreeparsertest.cpp | |||
@@ -371,6 +371,21 @@ private slots: | |||
371 | QCOMPARE(part->signatureState(), MimeTreeParser::KMMsgFullySigned); | 371 | QCOMPARE(part->signatureState(), MimeTreeParser::KMMsgFullySigned); |
372 | QVERIFY(otp.plainTextContent().contains(QString::fromUtf8("encrypted message text"))); | 372 | QVERIFY(otp.plainTextContent().contains(QString::fromUtf8("encrypted message text"))); |
373 | } | 373 | } |
374 | |||
375 | void testOpenpgpMultipartEmbedded() | ||
376 | { | ||
377 | MimeTreeParser::ObjectTreeParser otp; | ||
378 | otp.parseObjectTree(readMailFromFile("openpgp-multipart-embedded.mbox")); | ||
379 | otp.print(); | ||
380 | otp.decryptParts(); | ||
381 | otp.print(); | ||
382 | auto partList = otp.collectContentParts(); | ||
383 | QCOMPARE(partList.size(), 1); | ||
384 | auto part = partList[0].dynamicCast<MimeTreeParser::MessagePart>(); | ||
385 | QCOMPARE(part->encryptions().size(), 1); | ||
386 | QCOMPARE(part->encryptionState(), MimeTreeParser::KMMsgFullyEncrypted); | ||
387 | QCOMPARE(otp.plainTextContent(), QString::fromUtf8("sdflskjsdf\n\n-- \nThis is a HTML signature.\n")); | ||
388 | } | ||
374 | }; | 389 | }; |
375 | 390 | ||
376 | QTEST_GUILESS_MAIN(InterfaceTest) | 391 | QTEST_GUILESS_MAIN(InterfaceTest) |