summaryrefslogtreecommitdiffstats
path: root/framework/src/domain/mime/attachmentmodel.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/mime/attachmentmodel.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/mime/attachmentmodel.cpp')
-rw-r--r--framework/src/domain/mime/attachmentmodel.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/framework/src/domain/mime/attachmentmodel.cpp b/framework/src/domain/mime/attachmentmodel.cpp
index 2eb2cc13..8b12679b 100644
--- a/framework/src/domain/mime/attachmentmodel.cpp
+++ b/framework/src/domain/mime/attachmentmodel.cpp
@@ -32,6 +32,11 @@
32#include <QUrl> 32#include <QUrl>
33#include <QMimeDatabase> 33#include <QMimeDatabase>
34 34
35#include <QGpgME/ImportJob>
36#include <QGpgME/Protocol>
37
38#include <memory>
39
35QString sizeHuman(float size) 40QString sizeHuman(float size)
36{ 41{
37 QStringList list; 42 QStringList list;
@@ -210,6 +215,36 @@ bool AttachmentModel::openAttachment(const QModelIndex &index)
210 return false; 215 return false;
211} 216}
212 217
218bool AttachmentModel::importPublicKey(const QModelIndex &index)
219{
220 Q_ASSERT(index.internalPointer());
221 const auto part = static_cast<MimeTreeParser::MessagePart *>(index.internalPointer());
222 Q_ASSERT(part);
223 auto pkey = part->node()->decodedContent();
224
225 const auto *proto = QGpgME::openpgp();
226 std::unique_ptr<QGpgME::ImportJob> job(proto->importJob());
227 auto result = job->exec(pkey);
228
229 bool success = true;
230
231 QString message;
232 if(result.numConsidered() == 0) {
233 message = tr("No keys were found in this attachment");
234 success = false;
235 } else {
236 message = tr("%n Key(s) imported", "", result.numImported());
237 if(result.numUnchanged() != 0) {
238 message += "\n" + tr("%n Key(s) were already imported", "", result.numUnchanged());
239 }
240 }
241
242 Kube::Fabric::Fabric{}.postMessage("notification",
243 {{"message", message}});
244
245 return success;
246}
247
213QModelIndex AttachmentModel::parent(const QModelIndex &) const 248QModelIndex AttachmentModel::parent(const QModelIndex &) const
214{ 249{
215 return QModelIndex(); 250 return QModelIndex();