From d5b5c33a0cb3fbe02d011a14f2028249220b0656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Nicole?= Date: Fri, 9 Mar 2018 13:32:10 +0100 Subject: Automatic key import / export + Expected monad Summary: There are many things going on here (perhaps a bit much for a single patch): - When an attachment is of mime type "application/pgp-keys", a button is added to import the key to GPG - When sending a mail and crypto is enabled (encryption, signing or both), the public key of the first private key found is sent as an un-encrypted attachment (T6994) - The `mailcrypto.{h,cpp}` was, for the most part, rewritten - Introduction of the expected monad, inspired by what was proposed for C++ [here](https://isocpp.org/files/papers/n4015.pdf), but not at all a strict implementation of this specification. We may want to add some more features of this standard later. The rationale for some of the choices: - I found mailcrypto a bit hard to edit to add new features, and a great part was commented code to prepare for the support the SMIME crypto format, which would (in my current knowledge) not be used for sending emails. - One thing I found that may be missing in the code base was a standardized way of handling errors in C++ code. Since exceptions are disabled I think that the functional way is the way to go. After some research I found the Expected monad / tagged union / sum type, which seemed to suit the problem particularly well. In the long run, I hope we would move the entire code base to use `Expected` to indicate if a function might fail. Of course every choice made here is to be considered as a proposition for doing things / RFC, critics wholeheartedly accepted. Reviewers: cmollekopf Tags: #kube Maniphest Tasks: T6994, T8147, T6995 Differential Revision: https://phabricator.kde.org/D11158 --- .../src/domain/mime/tests/mailtemplatetest.cpp | 34 +++++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) (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 6338cd58..d5642bb6 100644 --- a/framework/src/domain/mime/tests/mailtemplatetest.cpp +++ b/framework/src/domain/mime/tests/mailtemplatetest.cpp @@ -31,16 +31,16 @@ static std::vector< GpgME::Key, std::allocator< GpgME::Key > > getKeys(bool smim if (smime) { const QGpgME::Protocol *const backend = QGpgME::smime(); Q_ASSERT(backend); - job = backend->keyListJob(false); + job = backend->keyListJob(/* remote = */ false); } else { const QGpgME::Protocol *const backend = QGpgME::openpgp(); Q_ASSERT(backend); - job = backend->keyListJob(false); + job = backend->keyListJob(/* remote = */ false); } Q_ASSERT(job); std::vector< GpgME::Key > keys; - GpgME::KeyListResult res = job->exec(QStringList(), true, keys); + GpgME::KeyListResult res = job->exec(QStringList(), /* secretOnly = */ true, keys); if (!smime) { Q_ASSERT(keys.size() == 3); @@ -401,7 +401,7 @@ private slots: std::vector keys = getKeys(); - auto result = MailTemplates::createMessage({}, to, cc, bcc, from, subject, body, false, attachments, keys); + auto result = MailTemplates::createMessage({}, to, cc, bcc, from, subject, body, false, attachments, keys, {}, keys[0]); QVERIFY(result); // qWarning() << "---------------------------------"; @@ -409,9 +409,17 @@ private slots: // qWarning() << "---------------------------------"; QCOMPARE(result->subject()->asUnicodeString(), subject); QVERIFY(result->date(false)->dateTime().isValid()); - QVERIFY(result->contentType()->isMimeType("multipart/signed")); - const auto contents = result->contents(); + QCOMPARE(result->contentType()->mimeType(), "multipart/mixed"); + auto resultAttachments = result->attachments(); + QCOMPARE(resultAttachments.size(), 1); + QCOMPARE(resultAttachments[0]->contentDisposition()->filename(), "0x8F246DE6.asc"); + + auto signedMessage = result->contents()[0]; + + QVERIFY(signedMessage->contentType()->isMimeType("multipart/signed")); + + const auto contents = signedMessage->contents(); QCOMPARE(contents.size(), 2); { auto c = contents.at(0); @@ -441,9 +449,19 @@ private slots: QVERIFY(result); QCOMPARE(result->subject()->asUnicodeString(), subject); QVERIFY(result->date(false)->dateTime().isValid()); - QVERIFY(result->contentType()->isMimeType("multipart/signed")); - const auto contents = result->contents(); + QCOMPARE(result->contentType()->mimeType(), "multipart/mixed"); + auto resultAttachments = result->attachments(); + QCOMPARE(resultAttachments.size(), 3); + // It seems KMime searches for the attachments using depth-first + // search, so the public key is last + QCOMPARE(resultAttachments[2]->contentDisposition()->filename(), "0x8F246DE6.asc"); + + auto signedMessage = result->contents()[0]; + + QVERIFY(signedMessage->contentType()->isMimeType("multipart/signed")); + + const auto contents = signedMessage->contents(); QCOMPARE(contents.size(), 2); { auto c = contents.at(0); -- cgit v1.2.3