]> git.notmuchmail.org Git - notmuch/blob - emacs/notmuch-crypto.el
emacs: Give mutlipart/{signed, encrypted} their own part handler.
[notmuch] / emacs / notmuch-crypto.el
1 ;; notmuch-crypto.el --- functions for handling display of cryptographic metadata.
2 ;;
3 ;; Copyright © Jameson Rollins
4 ;;
5 ;; This file is part of Notmuch.
6 ;;
7 ;; Notmuch is free software: you can redistribute it and/or modify it
8 ;; under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
11 ;;
12 ;; Notmuch is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 ;; General Public License for more details.
16 ;;
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with Notmuch.  If not, see <http://www.gnu.org/licenses/>.
19 ;;
20 ;; Authors: Jameson Rollins <jrollins@finestructure.net>
21
22 (defcustom notmuch-crypto-process-mime nil
23   "Should cryptographic MIME parts be processed?
24
25 If this variable is non-nil signatures in multipart/signed
26 messages will be verified and multipart/encrypted parts will be
27 decrypted.  The result of the crypto operation will be displayed
28 in a specially colored header button at the top of the processed
29 part.  Signed parts will have variously colored headers depending
30 on the success or failure of the verification process and on the
31 validity of user ID of the signer.
32
33 The effect of setting this variable can be seen temporarily by
34 viewing a signed or encrypted message with M-RET in notmuch
35 search."
36   :group 'notmuch
37   :type 'boolean)
38
39 (define-button-type 'notmuch-crypto-status-button-type
40   'action '(lambda (button) (message (button-get button 'help-echo)))
41   'follow-link t
42   'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts."
43   'face '(:foreground "blue")
44   'mouse-face '(:foreground "blue"))
45
46 (defun notmuch-crypto-insert-sigstatus-button (sigstatus from)
47   (let* ((status (plist-get sigstatus :status))
48          (help-msg nil)
49          (label "Signature not processed")
50          (face '(:background "red" :foreground "black")))
51     (cond
52      ((string= status "good")
53       ; if userid present, userid has full or greater validity
54       (if (plist-member sigstatus :userid)
55           (let ((userid (plist-get sigstatus :userid)))
56             (setq label (concat "Good signature by: " userid))
57             (setq face '(:background "green" :foreground "black")))
58         (let ((fingerprint (concat "0x" (plist-get sigstatus :fingerprint))))
59           (setq label (concat "Good signature by key: " fingerprint))
60           (setq face '(:background "orange" :foreground "black")))))
61      ((string= status "error")
62       (let ((keyid (concat "0x" (plist-get sigstatus :keyid))))
63         (setq label (concat "Unknown key ID " keyid " or unsupported algorithm"))
64         (setq face '(:background "red" :foreground "black"))))
65      ((string= status "bad")
66       (let ((keyid (concat "0x" (plist-get sigstatus :keyid))))
67         (setq label (concat "Bad signature (claimed key ID " keyid ")"))
68         (setq face '(:background "red" :foreground "black"))))
69      (t
70       (setq label "Unknown signature status")
71       (if status (setq label (concat label " \"" status "\"")))))
72     (insert-button
73      (concat "[ " label " ]")
74      :type 'notmuch-crypto-status-button-type
75      'help-echo help-msg
76      'face face
77      'mouse-face face
78      :notmuch-sigstatus sigstatus
79      :notmuch-from from)
80     (insert "\n")))
81
82 (defun notmuch-crypto-insert-encstatus-button (encstatus)
83   (let* ((status (plist-get encstatus :status))
84          (help-msg nil)
85          (label "Decryption not attempted")
86          (face '(:background "purple" :foreground "black")))
87     (cond
88      ((string= status "good")
89       (setq label "Decryption successful"))
90      ((string= status "bad")
91       (setq label "Decryption error"))
92      (t
93       (setq label (concat "Unknown encstatus \"" status "\""))))
94     (insert-button
95      (concat "[ " label " ]")
96      :type 'notmuch-crypto-status-button-type
97      'help-echo help-msg
98      'face face
99      'mouse-face face)
100     (insert "\n")))
101
102 ;;
103
104 (provide 'notmuch-crypto)