From 4f006ff552a5ecf4550554d53ece8f4e9c1b9dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Nicole?= Date: Thu, 8 Mar 2018 12:09:25 +0100 Subject: 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 --- .../src/domain/mime/tests/mailtemplatetest.cpp | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'framework/src/domain/mime/tests') 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: QCOMPARE(origMsg->subject(false)->asUnicodeString(), {"A random subject with alternative contenttype"}); } + void testEncryptedForwardAsAttachment() + { + auto msg = readMail("openpgp-encrypted.mbox"); + KMime::Message::Ptr result; + MailTemplates::forward(msg, [&](const KMime::Message::Ptr &r) { result = r; }); + QTRY_VERIFY(result); + QCOMPARE(result->subject(false)->asUnicodeString(), {"FW: OpenPGP encrypted"}); + QCOMPARE(result->to()->addresses(), {}); + QCOMPARE(result->cc()->addresses(), {}); + + auto attachments = result->attachments(); + QCOMPARE(attachments.size(), 1); + auto attachment = attachments[0]; + QCOMPARE(attachment->contentDisposition(false)->disposition(), KMime::Headers::CDinline); + QCOMPARE(attachment->contentDisposition(false)->filename(), {"OpenPGP encrypted.eml"}); + QVERIFY(attachment->bodyIsMessage()); + + attachment->parse(); + auto origMsg = attachment->bodyAsMessage(); + QCOMPARE(origMsg->subject(false)->asUnicodeString(), {"OpenPGP encrypted"}); + } + + void testEncryptedWithAttachmentsForwardAsAttachment() + { + auto msg = readMail("openpgp-encrypted-two-attachments.mbox"); + KMime::Message::Ptr result; + MailTemplates::forward(msg, [&](const KMime::Message::Ptr &r) { result = r; }); + QTRY_VERIFY(result); + QCOMPARE(result->subject(false)->asUnicodeString(), {"FW: OpenPGP encrypted with 2 text attachments"}); + QCOMPARE(result->to()->addresses(), {}); + QCOMPARE(result->cc()->addresses(), {}); + + auto attachments = result->attachments(); + QCOMPARE(attachments.size(), 1); + auto attachment = attachments[0]; + QCOMPARE(attachment->contentDisposition(false)->disposition(), KMime::Headers::CDinline); + QCOMPARE(attachment->contentDisposition(false)->filename(), {"OpenPGP encrypted with 2 text attachments.eml"}); + QVERIFY(attachment->bodyIsMessage()); + + attachment->parse(); + auto origMsg = attachment->bodyAsMessage(); + QCOMPARE(origMsg->subject(false)->asUnicodeString(), {"OpenPGP encrypted with 2 text attachments"}); + + auto attattachments = origMsg->attachments(); + QCOMPARE(attattachments.size(), 2); + QCOMPARE(attattachments[0]->contentDisposition(false)->filename(), {"attachment1.txt"}); + QCOMPARE(attattachments[1]->contentDisposition(false)->filename(), {"attachment2.txt"}); + } + void testCreatePlainMail() { QStringList to = {{"to@example.org"}}; -- cgit v1.2.3