1 ;; notmuch-crypto.el --- functions for handling display of cryptographic metadata.
3 ;; Copyright © Jameson Rollins
5 ;; This file is part of Notmuch.
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.
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.
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/>.
20 ;; Authors: Jameson Rollins <jrollins@finestructure.net>
22 (defcustom notmuch-crypto-process-mime nil
23 "Should cryptographic MIME parts be processed?
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.
33 The effect of setting this variable can be seen temporarily by
34 viewing a signed or encrypted message with M-RET in notmuch
39 (define-button-type 'notmuch-crypto-status-button-type
40 'action '(lambda (button) (message (button-get button 'help-echo)))
42 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts."
43 'face '(:foreground "blue")
44 'mouse-face '(:foreground "blue"))
46 (defun notmuch-crypto-insert-sigstatus-button (sigstatus from)
47 (let* ((status (plist-get sigstatus :status))
49 (label "Signature not processed")
50 (face '(:background "red" :foreground "black")))
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"))))
70 (setq label "Unknown signature status")
71 (if status (setq label (concat label " \"" status "\"")))))
73 (concat "[ " label " ]")
74 :type 'notmuch-crypto-status-button-type
78 :notmuch-sigstatus sigstatus
82 (defun notmuch-crypto-insert-encstatus-button (encstatus)
83 (let* ((status (plist-get encstatus :status))
85 (label "Decryption not attempted")
86 (face '(:background "purple" :foreground "black")))
88 ((string= status "good")
89 (setq label "Decryption successful"))
90 ((string= status "bad")
91 (setq label "Decryption error"))
93 (setq label (concat "Unknown encstatus \"" status "\""))))
95 (concat "[ " label " ]")
96 :type 'notmuch-crypto-status-button-type
104 (provide 'notmuch-crypto)