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 providing a prefix when viewing a signed or encrypted message, or
35 by providing a prefix when reloading the message in notmuch-show
40 (defface notmuch-crypto-signature-good
41 '((t (:background "green" :foreground "black")))
42 "Face used for good signatures."
45 (defface notmuch-crypto-signature-good-key
46 '((t (:background "orange" :foreground "black")))
47 "Face used for good signatures."
50 (defface notmuch-crypto-signature-bad
51 '((t (:background "red" :foreground "black")))
52 "Face used for bad signatures."
55 (defface notmuch-crypto-signature-unknown
56 '((t (:background "red" :foreground "black")))
57 "Face used for signatures of unknown status."
60 (defface notmuch-crypto-decryption
61 '((t (:background "purple" :foreground "black")))
62 "Face used for encryption/decryption status messages."
65 (define-button-type 'notmuch-crypto-status-button-type
66 'action '(lambda (button) (message (button-get button 'help-echo)))
68 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts.")
70 (defun notmuch-crypto-insert-sigstatus-button (sigstatus from)
71 (let* ((status (plist-get sigstatus :status))
73 (label "Signature not processed")
74 (face 'notmuch-crypto-signature-unknown)
75 (button-action '(lambda (button) (message (button-get button 'help-echo)))))
77 ((string= status "good")
78 (let ((fingerprint (concat "0x" (plist-get sigstatus :fingerprint))))
79 ;; if userid present, userid has full or greater validity
80 (if (plist-member sigstatus :userid)
81 (let ((userid (plist-get sigstatus :userid)))
82 (setq label (concat "Good signature by: " userid))
83 (setq face 'notmuch-crypto-signature-good))
85 (setq label (concat "Good signature by key: " fingerprint))
86 (setq face 'notmuch-crypto-signature-good-key)))
87 (setq button-action 'notmuch-crypto-sigstatus-good-callback)
88 (setq help-msg (concat "Click to list key ID 0x" fingerprint "."))))
89 ((string= status "error")
90 (let ((keyid (concat "0x" (plist-get sigstatus :keyid))))
91 (setq label (concat "Unknown key ID " keyid " or unsupported algorithm"))
92 (setq button-action 'notmuch-crypto-sigstatus-error-callback)
93 (setq help-msg (concat "Click to retreive key ID " keyid " from keyserver and redisplay."))))
94 ((string= status "bad")
95 (let ((keyid (concat "0x" (plist-get sigstatus :keyid))))
96 (setq label (concat "Bad signature (claimed key ID " keyid ")"))
97 (setq face 'notmuch-crypto-signature-bad)))
99 (setq label "Unknown signature status")
100 (if status (setq label (concat label " \"" status "\"")))))
102 (concat "[ " label " ]")
103 :type 'notmuch-crypto-status-button-type
107 'action button-action
108 :notmuch-sigstatus sigstatus
112 (declare-function notmuch-show-refresh-view "notmuch-show" (&optional crypto-switch))
114 (defun notmuch-crypto-sigstatus-good-callback (button)
115 (let* ((sigstatus (button-get button :notmuch-sigstatus))
116 (fingerprint (concat "0x" (plist-get sigstatus :fingerprint)))
117 (buffer (get-buffer-create "*notmuch-crypto-gpg-out*"))
118 (window (display-buffer buffer t nil)))
119 (with-selected-window window
120 (with-current-buffer buffer
121 (call-process "gpg" nil t t "--list-keys" fingerprint))
124 (defun notmuch-crypto-sigstatus-error-callback (button)
125 (let* ((sigstatus (button-get button :notmuch-sigstatus))
126 (keyid (concat "0x" (plist-get sigstatus :keyid)))
127 (buffer (get-buffer-create "*notmuch-crypto-gpg-out*"))
128 (window (display-buffer buffer t nil)))
129 (with-selected-window window
130 (with-current-buffer buffer
131 (call-process "gpg" nil t t "--recv-keys" keyid)
133 (call-process "gpg" nil t t "--list-keys" keyid))
135 (notmuch-show-refresh-view)))
137 (defun notmuch-crypto-insert-encstatus-button (encstatus)
138 (let* ((status (plist-get encstatus :status))
140 (label "Decryption not attempted")
141 (face 'notmuch-crypto-decryption))
143 ((string= status "good")
144 (setq label "Decryption successful"))
145 ((string= status "bad")
146 (setq label "Decryption error"))
148 (setq label (concat "Unknown encstatus \"" status "\""))))
150 (concat "[ " label " ]")
151 :type 'notmuch-crypto-status-button-type
159 (provide 'notmuch-crypto)