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/mailtemplates.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/mailtemplates.cpp')
-rw-r--r-- | framework/src/domain/mime/mailtemplates.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/framework/src/domain/mime/mailtemplates.cpp b/framework/src/domain/mime/mailtemplates.cpp index 30f9a48d..997eb3ae 100644 --- a/framework/src/domain/mime/mailtemplates.cpp +++ b/framework/src/domain/mime/mailtemplates.cpp | |||
@@ -1025,7 +1025,11 @@ static KMime::Types::Mailbox::List stringListToMailboxes(const QStringList &list | |||
1025 | return mailboxes; | 1025 | return mailboxes; |
1026 | } | 1026 | } |
1027 | 1027 | ||
1028 | KMime::Message::Ptr MailTemplates::createMessage(KMime::Message::Ptr existingMessage, const QStringList &to, const QStringList &cc, const QStringList &bcc, const KMime::Types::Mailbox &from, const QString &subject, const QString &body, bool htmlBody, const QList<Attachment> &attachments, const std::vector<GpgME::Key> &signingKeys, const std::vector<GpgME::Key> &encryptionKeys) | 1028 | KMime::Message::Ptr MailTemplates::createMessage(KMime::Message::Ptr existingMessage, |
1029 | const QStringList &to, const QStringList &cc, const QStringList &bcc, | ||
1030 | const KMime::Types::Mailbox &from, const QString &subject, const QString &body, bool htmlBody, | ||
1031 | const QList<Attachment> &attachments, const std::vector<GpgME::Key> &signingKeys, | ||
1032 | const std::vector<GpgME::Key> &encryptionKeys, const GpgME::Key &attachedKey) | ||
1029 | { | 1033 | { |
1030 | auto mail = existingMessage; | 1034 | auto mail = existingMessage; |
1031 | if (!mail) { | 1035 | if (!mail) { |
@@ -1089,12 +1093,12 @@ KMime::Message::Ptr MailTemplates::createMessage(KMime::Message::Ptr existingMes | |||
1089 | 1093 | ||
1090 | QByteArray bodyData; | 1094 | QByteArray bodyData; |
1091 | if (!signingKeys.empty() || !encryptionKeys.empty()) { | 1095 | if (!signingKeys.empty() || !encryptionKeys.empty()) { |
1092 | auto result = MailCrypto::processCrypto(bodyPart.get(), signingKeys, encryptionKeys, MailCrypto::OPENPGP); | 1096 | auto result = MailCrypto::processCrypto(std::move(bodyPart), signingKeys, encryptionKeys, attachedKey); |
1093 | if (!result) { | 1097 | if (!result) { |
1094 | qWarning() << "Signing failed"; | 1098 | qWarning() << "Crypto failed"; |
1095 | return {}; | 1099 | return {}; |
1096 | } | 1100 | } |
1097 | bodyData = result->encodedContent(); | 1101 | bodyData = result.value()->encodedContent(); |
1098 | } else { | 1102 | } else { |
1099 | if (!bodyPart->contentType(false)) { | 1103 | if (!bodyPart->contentType(false)) { |
1100 | bodyPart->contentType(true)->setMimeType("text/plain"); | 1104 | bodyPart->contentType(true)->setMimeType("text/plain"); |