diff options
author | Rémi Nicole <nicole@kolabsystems.com> | 2018-03-08 12:09:25 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-03-08 12:11:03 +0100 |
commit | 4f006ff552a5ecf4550554d53ece8f4e9c1b9dc0 (patch) | |
tree | d367daa985f82a0673cf2f5c4140c1a81e90152e /framework/src/domain/mime/tests/mailtemplatetest.cpp | |
parent | fa04490373f4f09dfadfdc3450eb98a4514072e7 (diff) | |
download | kube-4f006ff552a5ecf4550554d53ece8f4e9c1b9dc0.tar.gz kube-4f006ff552a5ecf4550554d53ece8f4e9c1b9dc0.zip |
Support encrypted mails forwarding
Summary:
Some notes:
- What we do is: if the mail is encrypted, decrypt it and copy its content into a new message (with plaintext, html and attachments, if any), and use this message as attachment for forwarding
- The `isEncrypted` function from KMime doesn't seem to detect every kind of encrypted mails. AFAIK this structure is not detected:
- `multipart/mixed`
- `text/plain`
- `application/pgp-encrypted` (attachement, named "ATT00001")
- `application/octet-stream` (attachment named "encrypted.asc")
Reviewers: cmollekopf
Tags: PHID-PROJ-6npnfcmppynqynn7slmv
Maniphest Tasks: T8112, T7024
Differential Revision: https://phabricator.kde.org/D10966
Diffstat (limited to 'framework/src/domain/mime/tests/mailtemplatetest.cpp')
-rw-r--r-- | framework/src/domain/mime/tests/mailtemplatetest.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/framework/src/domain/mime/tests/mailtemplatetest.cpp b/framework/src/domain/mime/tests/mailtemplatetest.cpp index 8d044608..6338cd58 100644 --- a/framework/src/domain/mime/tests/mailtemplatetest.cpp +++ b/framework/src/domain/mime/tests/mailtemplatetest.cpp | |||
@@ -248,6 +248,55 @@ private slots: | |||
248 | QCOMPARE(origMsg->subject(false)->asUnicodeString(), {"A random subject with alternative contenttype"}); | 248 | QCOMPARE(origMsg->subject(false)->asUnicodeString(), {"A random subject with alternative contenttype"}); |
249 | } | 249 | } |
250 | 250 | ||
251 | void testEncryptedForwardAsAttachment() | ||
252 | { | ||
253 | auto msg = readMail("openpgp-encrypted.mbox"); | ||
254 | KMime::Message::Ptr result; | ||
255 | MailTemplates::forward(msg, [&](const KMime::Message::Ptr &r) { result = r; }); | ||
256 | QTRY_VERIFY(result); | ||
257 | QCOMPARE(result->subject(false)->asUnicodeString(), {"FW: OpenPGP encrypted"}); | ||
258 | QCOMPARE(result->to()->addresses(), {}); | ||
259 | QCOMPARE(result->cc()->addresses(), {}); | ||
260 | |||
261 | auto attachments = result->attachments(); | ||
262 | QCOMPARE(attachments.size(), 1); | ||
263 | auto attachment = attachments[0]; | ||
264 | QCOMPARE(attachment->contentDisposition(false)->disposition(), KMime::Headers::CDinline); | ||
265 | QCOMPARE(attachment->contentDisposition(false)->filename(), {"OpenPGP encrypted.eml"}); | ||
266 | QVERIFY(attachment->bodyIsMessage()); | ||
267 | |||
268 | attachment->parse(); | ||
269 | auto origMsg = attachment->bodyAsMessage(); | ||
270 | QCOMPARE(origMsg->subject(false)->asUnicodeString(), {"OpenPGP encrypted"}); | ||
271 | } | ||
272 | |||
273 | void testEncryptedWithAttachmentsForwardAsAttachment() | ||
274 | { | ||
275 | auto msg = readMail("openpgp-encrypted-two-attachments.mbox"); | ||
276 | KMime::Message::Ptr result; | ||
277 | MailTemplates::forward(msg, [&](const KMime::Message::Ptr &r) { result = r; }); | ||
278 | QTRY_VERIFY(result); | ||
279 | QCOMPARE(result->subject(false)->asUnicodeString(), {"FW: OpenPGP encrypted with 2 text attachments"}); | ||
280 | QCOMPARE(result->to()->addresses(), {}); | ||
281 | QCOMPARE(result->cc()->addresses(), {}); | ||
282 | |||
283 | auto attachments = result->attachments(); | ||
284 | QCOMPARE(attachments.size(), 1); | ||
285 | auto attachment = attachments[0]; | ||
286 | QCOMPARE(attachment->contentDisposition(false)->disposition(), KMime::Headers::CDinline); | ||
287 | QCOMPARE(attachment->contentDisposition(false)->filename(), {"OpenPGP encrypted with 2 text attachments.eml"}); | ||
288 | QVERIFY(attachment->bodyIsMessage()); | ||
289 | |||
290 | attachment->parse(); | ||
291 | auto origMsg = attachment->bodyAsMessage(); | ||
292 | QCOMPARE(origMsg->subject(false)->asUnicodeString(), {"OpenPGP encrypted with 2 text attachments"}); | ||
293 | |||
294 | auto attattachments = origMsg->attachments(); | ||
295 | QCOMPARE(attattachments.size(), 2); | ||
296 | QCOMPARE(attattachments[0]->contentDisposition(false)->filename(), {"attachment1.txt"}); | ||
297 | QCOMPARE(attattachments[1]->contentDisposition(false)->filename(), {"attachment2.txt"}); | ||
298 | } | ||
299 | |||
251 | void testCreatePlainMail() | 300 | void testCreatePlainMail() |
252 | { | 301 | { |
253 | QStringList to = {{"to@example.org"}}; | 302 | QStringList to = {{"to@example.org"}}; |