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 (require 'notmuch-lib)
24 (defcustom notmuch-crypto-process-mime nil
25 "Should cryptographic MIME parts be processed?
27 If this variable is non-nil signatures in multipart/signed
28 messages will be verified and multipart/encrypted parts will be
29 decrypted. The result of the crypto operation will be displayed
30 in a specially colored header button at the top of the processed
31 part. Signed parts will have variously colored headers depending
32 on the success or failure of the verification process and on the
33 validity of user ID of the signer.
35 The effect of setting this variable can be seen temporarily by
36 providing a prefix when viewing a signed or encrypted message, or
37 by providing a prefix when reloading the message in notmuch-show
40 :group 'notmuch-crypto)
42 (defface notmuch-crypto-part-header
43 '((t (:foreground "blue")))
44 "Face used for crypto parts headers."
45 :group 'notmuch-crypto
46 :group 'notmuch-faces)
48 (defface notmuch-crypto-signature-good
49 '((t (:background "green" :foreground "black")))
50 "Face used for good signatures."
51 :group 'notmuch-crypto
52 :group 'notmuch-faces)
54 (defface notmuch-crypto-signature-good-key
55 '((t (:background "orange" :foreground "black")))
56 "Face used for good signatures."
57 :group 'notmuch-crypto
58 :group 'notmuch-faces)
60 (defface notmuch-crypto-signature-bad
61 '((t (:background "red" :foreground "black")))
62 "Face used for bad signatures."
63 :group 'notmuch-crypto
64 :group 'notmuch-faces)
66 (defface notmuch-crypto-signature-unknown
67 '((t (:background "red" :foreground "black")))
68 "Face used for signatures of unknown status."
69 :group 'notmuch-crypto
70 :group 'notmuch-faces)
72 (defface notmuch-crypto-decryption
73 '((t (:background "purple" :foreground "black")))
74 "Face used for encryption/decryption status messages."
75 :group 'notmuch-crypto
76 :group 'notmuch-faces)
78 (define-button-type 'notmuch-crypto-status-button-type
79 'action (lambda (button) (message (button-get button 'help-echo)))
81 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts."
82 :supertype 'notmuch-button-type)
84 (defun notmuch-crypto-insert-sigstatus-button (sigstatus from)
85 (let* ((status (plist-get sigstatus :status))
87 (label "Signature not processed")
88 (face 'notmuch-crypto-signature-unknown)
89 (button-action (lambda (button) (message (button-get button 'help-echo)))))
91 ((string= status "good")
92 (let ((fingerprint (concat "0x" (plist-get sigstatus :fingerprint))))
93 ;; if userid present, userid has full or greater validity
94 (if (plist-member sigstatus :userid)
95 (let ((userid (plist-get sigstatus :userid)))
96 (setq label (concat "Good signature by: " userid))
97 (setq face 'notmuch-crypto-signature-good))
99 (setq label (concat "Good signature by key: " fingerprint))
100 (setq face 'notmuch-crypto-signature-good-key)))
101 (setq button-action 'notmuch-crypto-sigstatus-good-callback)
102 (setq help-msg (concat "Click to list key ID 0x" fingerprint "."))))
103 ((string= status "error")
104 (let ((keyid (concat "0x" (plist-get sigstatus :keyid))))
105 (setq label (concat "Unknown key ID " keyid " or unsupported algorithm"))
106 (setq button-action 'notmuch-crypto-sigstatus-error-callback)
107 (setq help-msg (concat "Click to retrieve key ID " keyid " from keyserver and redisplay."))))
108 ((string= status "bad")
109 (let ((keyid (concat "0x" (plist-get sigstatus :keyid))))
110 (setq label (concat "Bad signature (claimed key ID " keyid ")"))
111 (setq face 'notmuch-crypto-signature-bad)))
113 (setq label "Unknown signature status")
114 (if status (setq label (concat label " \"" status "\"")))))
116 (concat "[ " label " ]")
117 :type 'notmuch-crypto-status-button-type
121 'action button-action
122 :notmuch-sigstatus sigstatus
126 (declare-function notmuch-show-refresh-view "notmuch-show" (&optional reset-state))
128 (defun notmuch-crypto-sigstatus-good-callback (button)
129 (let* ((sigstatus (button-get button :notmuch-sigstatus))
130 (fingerprint (concat "0x" (plist-get sigstatus :fingerprint)))
131 (buffer (get-buffer-create "*notmuch-crypto-gpg-out*"))
132 (window (display-buffer buffer t nil)))
133 (with-selected-window window
134 (with-current-buffer buffer
135 (goto-char (point-max))
136 (call-process "gpg" nil t t "--list-keys" fingerprint))
139 (defun notmuch-crypto-sigstatus-error-callback (button)
140 (let* ((sigstatus (button-get button :notmuch-sigstatus))
141 (keyid (concat "0x" (plist-get sigstatus :keyid)))
142 (buffer (get-buffer-create "*notmuch-crypto-gpg-out*"))
143 (window (display-buffer buffer t nil)))
144 (with-selected-window window
145 (with-current-buffer buffer
146 (goto-char (point-max))
147 (call-process "gpg" nil t t "--recv-keys" keyid)
149 (call-process "gpg" nil t t "--list-keys" keyid))
151 (notmuch-show-refresh-view)))
153 (defun notmuch-crypto-insert-encstatus-button (encstatus)
154 (let* ((status (plist-get encstatus :status))
156 (label "Decryption not attempted")
157 (face 'notmuch-crypto-decryption))
159 ((string= status "good")
160 (setq label "Decryption successful"))
161 ((string= status "bad")
162 (setq label "Decryption error"))
164 (setq label (concat "Unknown encstatus \"" status "\""))))
166 (concat "[ " label " ]")
167 :type 'notmuch-crypto-status-button-type
175 (provide 'notmuch-crypto)