Mercurial > emacs
annotate lisp/epa-mail.el @ 109807:88276a8b38b9
* net/tramp.el (tramp-handle-make-symbolic-link): Flush file
properties.
(tramp-handle-process-file): Call the program in a subshell, in
order to preserve working directory.
(tramp-action-password): Hide password prompt before next run.
(tramp-process-actions): Widen connection buffer for the trace.
author | Michael Albinus <albinus@detlef> |
---|---|
date | Tue, 17 Aug 2010 06:52:16 +0200 |
parents | 018487fd2873 |
children | 280c8ae2476d |
rev | line source |
---|---|
91647 | 1 ;;; epa-mail.el --- the EasyPG Assistant, minor-mode for mail composer |
106815 | 2 ;; Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
91647 | 3 |
4 ;; Author: Daiki Ueno <ueno@unixuser.org> | |
5 ;; Keywords: PGP, GnuPG, mail, message | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
91733
diff
changeset
|
9 ;; GNU Emacs is free software: you can redistribute it and/or modify |
91647 | 10 ;; it under the terms of the GNU General Public License as published by |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
91733
diff
changeset
|
11 ;; the Free Software Foundation, either version 3 of the License, or |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
91733
diff
changeset
|
12 ;; (at your option) any later version. |
91647 | 13 |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
91733
diff
changeset
|
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
91647 | 21 |
22 ;;; Code: | |
23 | |
24 (require 'epa) | |
25 (require 'mail-utils) | |
26 | |
27 (defvar epa-mail-mode-map | |
28 (let ((keymap (make-sparse-keymap))) | |
29 (define-key keymap "\C-c\C-ed" 'epa-mail-decrypt) | |
30 (define-key keymap "\C-c\C-ev" 'epa-mail-verify) | |
31 (define-key keymap "\C-c\C-es" 'epa-mail-sign) | |
32 (define-key keymap "\C-c\C-ee" 'epa-mail-encrypt) | |
33 (define-key keymap "\C-c\C-ei" 'epa-mail-import-keys) | |
34 (define-key keymap "\C-c\C-eo" 'epa-insert-keys) | |
109546
018487fd2873
Add alternative key bindings to epa-mail.el.
Daiki Ueno <ueno@unixuser.org>
parents:
106815
diff
changeset
|
35 (define-key keymap "\C-c\C-e\C-d" 'epa-mail-decrypt) |
018487fd2873
Add alternative key bindings to epa-mail.el.
Daiki Ueno <ueno@unixuser.org>
parents:
106815
diff
changeset
|
36 (define-key keymap "\C-c\C-e\C-v" 'epa-mail-verify) |
018487fd2873
Add alternative key bindings to epa-mail.el.
Daiki Ueno <ueno@unixuser.org>
parents:
106815
diff
changeset
|
37 (define-key keymap "\C-c\C-e\C-s" 'epa-mail-sign) |
018487fd2873
Add alternative key bindings to epa-mail.el.
Daiki Ueno <ueno@unixuser.org>
parents:
106815
diff
changeset
|
38 (define-key keymap "\C-c\C-e\C-e" 'epa-mail-encrypt) |
018487fd2873
Add alternative key bindings to epa-mail.el.
Daiki Ueno <ueno@unixuser.org>
parents:
106815
diff
changeset
|
39 (define-key keymap "\C-c\C-e\C-i" 'epa-mail-import-keys) |
018487fd2873
Add alternative key bindings to epa-mail.el.
Daiki Ueno <ueno@unixuser.org>
parents:
106815
diff
changeset
|
40 (define-key keymap "\C-c\C-e\C-o" 'epa-insert-keys) |
91647 | 41 keymap)) |
42 | |
43 (defvar epa-mail-mode-hook nil) | |
44 (defvar epa-mail-mode-on-hook nil) | |
45 (defvar epa-mail-mode-off-hook nil) | |
46 | |
91731
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91687
diff
changeset
|
47 ;;;###autoload |
91647 | 48 (define-minor-mode epa-mail-mode |
49 "A minor-mode for composing encrypted/clearsigned mails." | |
50 nil " epa-mail" epa-mail-mode-map) | |
51 | |
52 (defun epa-mail--find-usable-key (keys usage) | |
53 "Find a usable key from KEYS for USAGE." | |
54 (catch 'found | |
55 (while keys | |
56 (let ((pointer (epg-key-sub-key-list (car keys)))) | |
57 (while pointer | |
58 (if (and (memq usage (epg-sub-key-capability (car pointer))) | |
59 (not (memq (epg-sub-key-validity (car pointer)) | |
60 '(revoked expired)))) | |
61 (throw 'found (car keys))) | |
62 (setq pointer (cdr pointer)))) | |
63 (setq keys (cdr keys))))) | |
64 | |
65 ;;;###autoload | |
66 (defun epa-mail-decrypt () | |
67 "Decrypt OpenPGP armors in the current buffer. | |
68 The buffer is expected to contain a mail message. | |
69 | |
70 Don't use this command in Lisp programs!" | |
71 (interactive) | |
72 (epa-decrypt-armor-in-region (point-min) (point-max))) | |
73 | |
74 ;;;###autoload | |
75 (defun epa-mail-verify () | |
76 "Verify OpenPGP cleartext signed messages in the current buffer. | |
77 The buffer is expected to contain a mail message. | |
78 | |
79 Don't use this command in Lisp programs!" | |
80 (interactive) | |
81 (epa-verify-cleartext-in-region (point-min) (point-max))) | |
82 | |
83 ;;;###autoload | |
84 (defun epa-mail-sign (start end signers mode) | |
85 "Sign the current buffer. | |
86 The buffer is expected to contain a mail message. | |
87 | |
88 Don't use this command in Lisp programs!" | |
89 (interactive | |
90 (save-excursion | |
91 (goto-char (point-min)) | |
92 (if (search-forward mail-header-separator nil t) | |
93 (forward-line)) | |
94 (setq epa-last-coding-system-specified | |
95 (or coding-system-for-write | |
96 (epa--select-safe-coding-system (point) (point-max)))) | |
97 (let ((verbose current-prefix-arg)) | |
98 (list (point) (point-max) | |
99 (if verbose | |
100 (epa-select-keys (epg-make-context epa-protocol) | |
101 "Select keys for signing. | |
102 If no one is selected, default secret key is used. " | |
103 nil t)) | |
104 (if verbose | |
105 (epa--read-signature-type) | |
106 'clear))))) | |
107 (epa-sign-region start end signers mode)) | |
108 | |
109 ;;;###autoload | |
110 (defun epa-mail-encrypt (start end recipients sign signers) | |
111 "Encrypt the current buffer. | |
112 The buffer is expected to contain a mail message. | |
113 | |
114 Don't use this command in Lisp programs!" | |
115 (interactive | |
116 (save-excursion | |
117 (let ((verbose current-prefix-arg) | |
118 (context (epg-make-context epa-protocol)) | |
119 recipients recipient-key) | |
120 (goto-char (point-min)) | |
121 (save-restriction | |
122 (narrow-to-region (point) | |
123 (if (search-forward mail-header-separator nil 0) | |
124 (match-beginning 0) | |
125 (point))) | |
126 (setq recipients | |
127 (mail-strip-quoted-names | |
128 (mapconcat #'identity | |
129 (nconc (mail-fetch-field "to" nil nil t) | |
130 (mail-fetch-field "cc" nil nil t) | |
131 (mail-fetch-field "bcc" nil nil t)) | |
132 ",")))) | |
133 (if recipients | |
134 (setq recipients (delete "" | |
135 (split-string recipients "[ \t\n]+")))) | |
136 (goto-char (point-min)) | |
137 (if (search-forward mail-header-separator nil t) | |
138 (forward-line)) | |
139 (setq epa-last-coding-system-specified | |
140 (or coding-system-for-write | |
141 (epa--select-safe-coding-system (point) (point-max)))) | |
142 (list (point) (point-max) | |
143 (if verbose | |
144 (epa-select-keys | |
145 context | |
146 "Select recipients for encryption. | |
147 If no one is selected, symmetric encryption will be performed. " | |
148 recipients) | |
149 (if recipients | |
150 (mapcar | |
151 (lambda (recipient) | |
152 (setq recipient-key | |
153 (epa-mail--find-usable-key | |
154 (epg-list-keys | |
155 (epg-make-context epa-protocol) | |
156 (concat "<" recipient ">")) | |
157 'encrypt)) | |
158 (unless (or recipient-key | |
159 (y-or-n-p | |
160 (format | |
161 "No public key for %s; skip it? " | |
162 recipient))) | |
163 (error "No public key for %s" recipient)) | |
164 recipient-key) | |
165 recipients))) | |
166 (setq sign (if verbose (y-or-n-p "Sign? "))) | |
167 (if sign | |
168 (epa-select-keys context | |
169 "Select keys for signing. ")))))) | |
170 (epa-encrypt-region start end recipients sign signers)) | |
171 | |
172 ;;;###autoload | |
173 (defun epa-mail-import-keys () | |
174 "Import keys in the OpenPGP armor format in the current buffer. | |
175 The buffer is expected to contain a mail message. | |
176 | |
177 Don't use this command in Lisp programs!" | |
178 (interactive) | |
179 (epa-import-armor-in-region (point-min) (point-max))) | |
180 | |
91731
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91687
diff
changeset
|
181 ;;;###autoload |
91733
e9326c8f35b0
EasyPG: Rename epa-mail-minor-mode to epa-global-mail-mode.
Michael Olson <mwolson@gnu.org>
parents:
91731
diff
changeset
|
182 (define-minor-mode epa-global-mail-mode |
91731
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91687
diff
changeset
|
183 "Minor mode to hook EasyPG into Mail mode." |
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91687
diff
changeset
|
184 :global t :init-value nil :group 'epa-mail :version "23.1" |
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91687
diff
changeset
|
185 (remove-hook 'mail-mode-hook 'epa-mail-mode) |
91733
e9326c8f35b0
EasyPG: Rename epa-mail-minor-mode to epa-global-mail-mode.
Michael Olson <mwolson@gnu.org>
parents:
91731
diff
changeset
|
186 (if epa-global-mail-mode |
91731
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91687
diff
changeset
|
187 (add-hook 'mail-mode-hook 'epa-mail-mode))) |
7efbdc83b944
EasyPG: Implement some suggestions from emacs-devel.
Michael Olson <mwolson@gnu.org>
parents:
91687
diff
changeset
|
188 |
91647 | 189 (provide 'epa-mail) |
190 | |
91687 | 191 ;; arch-tag: a6f82b3f-d177-4a11-af95-040da55927d2 |
91647 | 192 ;;; epa-mail.el ends here |