summaryrefslogtreecommitdiffstats
path: root/framework/src/domain/composercontroller.cpp
diff options
context:
space:
mode:
authorRémi Nicole <nicole@kolabsystems.com>2018-03-09 13:32:10 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-03-09 13:32:24 +0100
commitd5b5c33a0cb3fbe02d011a14f2028249220b0656 (patch)
treedb0ebb30db599a6889ea6066ec33bf5f862c8444 /framework/src/domain/composercontroller.cpp
parent93e9c10d1894797b5826bbdfcc324f4235c9e193 (diff)
downloadkube-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/composercontroller.cpp')
-rw-r--r--framework/src/domain/composercontroller.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/framework/src/domain/composercontroller.cpp b/framework/src/domain/composercontroller.cpp
index 2286a71b..a71e66f9 100644
--- a/framework/src/domain/composercontroller.cpp
+++ b/framework/src/domain/composercontroller.cpp
@@ -135,7 +135,7 @@ public:
135 SinkLog() << "Searching key for: " << mb.address(); 135 SinkLog() << "Searching key for: " << mb.address();
136 asyncRun<std::vector<GpgME::Key>>(this, 136 asyncRun<std::vector<GpgME::Key>>(this,
137 [mb] { 137 [mb] {
138 return MailCrypto::findKeys(QStringList{} << mb.address(), false, false, MailCrypto::OPENPGP); 138 return MailCrypto::findKeys(QStringList{} << mb.address(), false, false);
139 }, 139 },
140 [this, addressee, id](const std::vector<GpgME::Key> &keys) { 140 [this, addressee, id](const std::vector<GpgME::Key> &keys) {
141 if (!keys.empty()) { 141 if (!keys.empty()) {
@@ -463,18 +463,25 @@ KMime::Message::Ptr ComposerController::assembleMessage()
463 }; 463 };
464 }); 464 });
465 465
466 GpgME::Key attachedKey;
466 std::vector<GpgME::Key> signingKeys; 467 std::vector<GpgME::Key> signingKeys;
467 if (getSign()) { 468 if (getSign()) {
468 signingKeys = getPersonalKeys().value<std::vector<GpgME::Key>>(); 469 signingKeys = getPersonalKeys().value<std::vector<GpgME::Key>>();
470 Q_ASSERT(!signingKeys.empty());
471 attachedKey = signingKeys[0];
469 } 472 }
470 std::vector<GpgME::Key> encryptionKeys; 473 std::vector<GpgME::Key> encryptionKeys;
471 if (getEncrypt()) { 474 if (getEncrypt()) {
472 //Encrypt to self so we can read the sent message 475 //Encrypt to self so we can read the sent message
473 encryptionKeys += getPersonalKeys().value<std::vector<GpgME::Key>>(); 476 auto personalKeys = getPersonalKeys().value<std::vector<GpgME::Key>>();
477
478 attachedKey = personalKeys[0];
479
480 encryptionKeys += personalKeys;
474 encryptionKeys += getRecipientKeys(); 481 encryptionKeys += getRecipientKeys();
475 } 482 }
476 483
477 return MailTemplates::createMessage(mExistingMessage, toAddresses, ccAddresses, bccAddresses, getIdentity(), getSubject(), getBody(), getHtmlBody(), attachments, signingKeys, encryptionKeys); 484 return MailTemplates::createMessage(mExistingMessage, toAddresses, ccAddresses, bccAddresses, getIdentity(), getSubject(), getBody(), getHtmlBody(), attachments, signingKeys, encryptionKeys, attachedKey);
478} 485}
479 486
480void ComposerController::send() 487void ComposerController::send()