diff options
author | Rémi Nicole <nicole@kolabsystems.com> | 2018-03-09 13:32:10 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-03-09 13:32:24 +0100 |
commit | d5b5c33a0cb3fbe02d011a14f2028249220b0656 (patch) | |
tree | db0ebb30db599a6889ea6066ec33bf5f862c8444 /framework/src/domain/mime/tests/mailtemplatetest.cpp | |
parent | 93e9c10d1894797b5826bbdfcc324f4235c9e193 (diff) | |
download | kube-d5b5c33a0cb3fbe02d011a14f2028249220b0656.tar.gz kube-d5b5c33a0cb3fbe02d011a14f2028249220b0656.zip |
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
Diffstat (limited to 'framework/src/domain/mime/tests/mailtemplatetest.cpp')
-rw-r--r-- | framework/src/domain/mime/tests/mailtemplatetest.cpp | 34 |
1 files changed, 26 insertions, 8 deletions
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 | |||
31 | if (smime) { | 31 | if (smime) { |
32 | const QGpgME::Protocol *const backend = QGpgME::smime(); | 32 | const QGpgME::Protocol *const backend = QGpgME::smime(); |
33 | Q_ASSERT(backend); | 33 | Q_ASSERT(backend); |
34 | job = backend->keyListJob(false); | 34 | job = backend->keyListJob(/* remote = */ false); |
35 | } else { | 35 | } else { |
36 | const QGpgME::Protocol *const backend = QGpgME::openpgp(); | 36 | const QGpgME::Protocol *const backend = QGpgME::openpgp(); |
37 | Q_ASSERT(backend); | 37 | Q_ASSERT(backend); |
38 | job = backend->keyListJob(false); | 38 | job = backend->keyListJob(/* remote = */ false); |
39 | } | 39 | } |
40 | Q_ASSERT(job); | 40 | Q_ASSERT(job); |
41 | 41 | ||
42 | std::vector< GpgME::Key > keys; | 42 | std::vector< GpgME::Key > keys; |
43 | GpgME::KeyListResult res = job->exec(QStringList(), true, keys); | 43 | GpgME::KeyListResult res = job->exec(QStringList(), /* secretOnly = */ true, keys); |
44 | 44 | ||
45 | if (!smime) { | 45 | if (!smime) { |
46 | Q_ASSERT(keys.size() == 3); | 46 | Q_ASSERT(keys.size() == 3); |
@@ -401,7 +401,7 @@ private slots: | |||
401 | 401 | ||
402 | std::vector<GpgME::Key> keys = getKeys(); | 402 | std::vector<GpgME::Key> keys = getKeys(); |
403 | 403 | ||
404 | auto result = MailTemplates::createMessage({}, to, cc, bcc, from, subject, body, false, attachments, keys); | 404 | auto result = MailTemplates::createMessage({}, to, cc, bcc, from, subject, body, false, attachments, keys, {}, keys[0]); |
405 | 405 | ||
406 | QVERIFY(result); | 406 | QVERIFY(result); |
407 | // qWarning() << "---------------------------------"; | 407 | // qWarning() << "---------------------------------"; |
@@ -409,9 +409,17 @@ private slots: | |||
409 | // qWarning() << "---------------------------------"; | 409 | // qWarning() << "---------------------------------"; |
410 | QCOMPARE(result->subject()->asUnicodeString(), subject); | 410 | QCOMPARE(result->subject()->asUnicodeString(), subject); |
411 | QVERIFY(result->date(false)->dateTime().isValid()); | 411 | QVERIFY(result->date(false)->dateTime().isValid()); |
412 | QVERIFY(result->contentType()->isMimeType("multipart/signed")); | ||
413 | 412 | ||
414 | const auto contents = result->contents(); | 413 | QCOMPARE(result->contentType()->mimeType(), "multipart/mixed"); |
414 | auto resultAttachments = result->attachments(); | ||
415 | QCOMPARE(resultAttachments.size(), 1); | ||
416 | QCOMPARE(resultAttachments[0]->contentDisposition()->filename(), "0x8F246DE6.asc"); | ||
417 | |||
418 | auto signedMessage = result->contents()[0]; | ||
419 | |||
420 | QVERIFY(signedMessage->contentType()->isMimeType("multipart/signed")); | ||
421 | |||
422 | const auto contents = signedMessage->contents(); | ||
415 | QCOMPARE(contents.size(), 2); | 423 | QCOMPARE(contents.size(), 2); |
416 | { | 424 | { |
417 | auto c = contents.at(0); | 425 | auto c = contents.at(0); |
@@ -441,9 +449,19 @@ private slots: | |||
441 | QVERIFY(result); | 449 | QVERIFY(result); |
442 | QCOMPARE(result->subject()->asUnicodeString(), subject); | 450 | QCOMPARE(result->subject()->asUnicodeString(), subject); |
443 | QVERIFY(result->date(false)->dateTime().isValid()); | 451 | QVERIFY(result->date(false)->dateTime().isValid()); |
444 | QVERIFY(result->contentType()->isMimeType("multipart/signed")); | ||
445 | 452 | ||
446 | const auto contents = result->contents(); | 453 | QCOMPARE(result->contentType()->mimeType(), "multipart/mixed"); |
454 | auto resultAttachments = result->attachments(); | ||
455 | QCOMPARE(resultAttachments.size(), 3); | ||
456 | // It seems KMime searches for the attachments using depth-first | ||
457 | // search, so the public key is last | ||
458 | QCOMPARE(resultAttachments[2]->contentDisposition()->filename(), "0x8F246DE6.asc"); | ||
459 | |||
460 | auto signedMessage = result->contents()[0]; | ||
461 | |||
462 | QVERIFY(signedMessage->contentType()->isMimeType("multipart/signed")); | ||
463 | |||
464 | const auto contents = signedMessage->contents(); | ||
447 | QCOMPARE(contents.size(), 2); | 465 | QCOMPARE(contents.size(), 2); |
448 | { | 466 | { |
449 | auto c = contents.at(0); | 467 | auto c = contents.at(0); |