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 --- framework/qml/AttachmentDelegate.qml | 10 ++++++++++ framework/qml/Icons.qml | 1 + framework/qml/MailViewer.qml | 2 ++ 3 files changed, 13 insertions(+) (limited to 'framework/qml') diff --git a/framework/qml/AttachmentDelegate.qml b/framework/qml/AttachmentDelegate.qml index 3c308e65..4469cbdd 100644 --- a/framework/qml/AttachmentDelegate.qml +++ b/framework/qml/AttachmentDelegate.qml @@ -23,10 +23,12 @@ Item { id: root property string name + property string type property string icon property alias actionIcon: actionButton.iconName signal clicked; signal execute; + signal publicKeyImport; width: content.width + Kube.Units.smallSpacing * 1.5 height: content.height + Kube.Units.smallSpacing @@ -69,6 +71,14 @@ Item { text: root.name color: Kube.Colors.backgroundColor } + Kube.IconButton { + visible: root.type == "application/pgp-keys" + iconName: Kube.Icons.key_import_inverted + height: Kube.Units.gridUnit + width: height + onClicked: root.publicKeyImport() + padding: 0 + } Kube.IconButton { id: actionButton height: Kube.Units.gridUnit diff --git a/framework/qml/Icons.qml b/framework/qml/Icons.qml index 2afe840e..4dfae3d7 100644 --- a/framework/qml/Icons.qml +++ b/framework/qml/Icons.qml @@ -63,6 +63,7 @@ Item { property string secure: "document-encrypt" property string insecure: "document-decrypt" property string signed: "document-sign" + property string key_import_inverted: "view-certificate-import-inverted" property string addNew: "list-add" property string remove: "kube-list-remove-inverted" diff --git a/framework/qml/MailViewer.qml b/framework/qml/MailViewer.qml index 565adedd..e9ffd108 100644 --- a/framework/qml/MailViewer.qml +++ b/framework/qml/MailViewer.qml @@ -283,6 +283,7 @@ Rectangle { delegate: AttachmentDelegate { name: model.name + type: model.type icon: model.iconName clip: true @@ -290,6 +291,7 @@ Rectangle { actionIcon: Kube.Icons.save_inverted onExecute: messageParser.attachments.saveAttachmentToDisk(messageParser.attachments.index(index, 0)) onClicked: messageParser.attachments.openAttachment(messageParser.attachments.index(index, 0)) + onPublicKeyImport: messageParser.attachments.importPublicKey(messageParser.attachments.index(index, 0)) } } } -- cgit v1.2.3