aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2011-08-16 00:04:27 -0400
committerRichard M. Stallman2011-08-16 00:04:27 -0400
commit04963aa8ff62058b9795c3e3217630515470fcff (patch)
treee0882f08e82c196e8abed0c94c10d7f35a9011f7
parent177549d04c917ea9f3de23041b60d3c22a07279b (diff)
downloademacs-04963aa8ff62058b9795c3e3217630515470fcff.tar.gz
emacs-04963aa8ff62058b9795c3e3217630515470fcff.zip
epa-mail.el handles GnuPG groups.
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/epa-mail.el75
2 files changed, 83 insertions, 0 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index cfa948c6bec..70d34fb7117 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,13 @@
12011-08-16 Richard Stallman <rms@gnu.org> 12011-08-16 Richard Stallman <rms@gnu.org>
2 2
3 * epa-mail.el: Handle GnuPG group definitions.
4 (epa-mail-group-alist, epa-mail-group-modtime)
5 (epa-mail-gnupg-conf-file): New variables.
6 (epa-mail-parse-groups, epa-mail-sync-groups)
7 (epa-mail-expand-recipient-1, epa-mail-expand-recipients-2)
8 (epa-mail-expand-recipients): New functions.
9 (epa-mail-encrypt): Call epa-mail-expand-recipients.
10
3 * mail/rmail.el (rmail-epa-decrypt): New command. 11 * mail/rmail.el (rmail-epa-decrypt): New command.
4 12
5 * epa.el (epa-decrypt-region): New arg MAKE-BUFFER-FUNCTION. 13 * epa.el (epa-decrypt-region): New arg MAKE-BUFFER-FUNCTION.
diff --git a/lisp/epa-mail.el b/lisp/epa-mail.el
index a3f11f78675..e6f6c0ec2b1 100644
--- a/lisp/epa-mail.el
+++ b/lisp/epa-mail.el
@@ -50,6 +50,9 @@
50 "A minor-mode for composing encrypted/clearsigned mails." 50 "A minor-mode for composing encrypted/clearsigned mails."
51 nil " epa-mail" epa-mail-mode-map) 51 nil " epa-mail" epa-mail-mode-map)
52 52
53;;; ??? Could someone please clarify this doc string?
54;;; In particular, what does USAGE look like
55;;; and what does it mean? -- rms
53(defun epa-mail--find-usable-key (keys usage) 56(defun epa-mail--find-usable-key (keys usage)
54 "Find a usable key from KEYS for USAGE." 57 "Find a usable key from KEYS for USAGE."
55 (catch 'found 58 (catch 'found
@@ -63,6 +66,71 @@
63 (setq pointer (cdr pointer)))) 66 (setq pointer (cdr pointer))))
64 (setq keys (cdr keys))))) 67 (setq keys (cdr keys)))))
65 68
69(defvar epa-mail-group-alist nil
70 "Alist of GnuPG mail groups (`group' commands in `.gnupg/gpg.conf').
71Each element has the form (GROUPNAME ADDRESSES...).
72t means the list is not yet read in.")
73
74(defvar epa-mail-group-modtime nil
75 "The modification time of `~/.gnupg/gpg.conf' file when last examined.")
76
77(defvar epa-mail-gnupg-conf-file "~/.gnupg/gpg.conf"
78 "File name of GnuPG configuration file that specifies recipient groups.")
79
80(defun epa-mail-parse-groups ()
81 "Parse `~/.gnupg/gpg.conf' and set `epa-mail-group-alist' from it."
82 (let (aliases)
83 (with-temp-buffer
84 (insert-file-contents-literally epa-mail-gnupg-conf-file)
85
86 (while (re-search-forward "^[ \t]*group[ \t]*" nil t)
87 (if (looking-at "\\([^= \t]+\\)[ \t]*=[ \t]*\\([^ \t\n]+\\)")
88 (push (cons (match-string-no-properties 1)
89 (split-string (match-string-no-properties 2)))
90 aliases))))
91 (setq epa-mail-group-alist aliases)))
92
93(defun epa-mail-sync-groups ()
94 "Update GnuPG groups from file if necessary."
95 (if (file-exists-p epa-mail-gnupg-conf-file)
96 (let ((modtime (nth 5 (file-attributes epa-mail-gnupg-conf-file))))
97 (if (not (equal epa-mail-group-modtime modtime))
98 (progn
99 (setq epa-mail-group-modtime modtime)
100 (epa-mail-parse-groups))))
101 (setq epa-mail-group-alist nil)))
102
103(defun epa-mail-expand-recipient-1 (recipient)
104 "Expand RECIPIENT once thru `epa-mail-group-alist'.
105Returns the list of names it stands for, or nil if it isn't a group."
106 ;; Load the alias list if not loaded before.
107 (let (alist-elt)
108 (setq alist-elt (assoc recipient epa-mail-group-alist))
109 (cdr alist-elt)))
110
111(defun epa-mail-expand-recipients-2 (recipients)
112 "Expand list RECIPIENTS once thru `epa-mail-group-alist'.
113Returns the list of names they stand for."
114 ;; Load the alias list if not loaded before.
115 (let (output)
116 (dolist (r recipients)
117 (let ((expanded (epa-mail-expand-recipient-1 r)))
118 (if expanded
119 (dolist (xr expanded)
120 (unless (member xr output)
121 (push xr output)))
122 (unless (member r output)
123 (push r output)))))
124 (nreverse output)))
125
126(defun epa-mail-expand-recipients (recipients)
127 "Expand RECIPIENTS thru `epa-mail-group-alist' until it stops changing."
128 (epa-mail-sync-groups)
129 (while (not (equal recipients
130 (setq recipients
131 (epa-mail-expand-recipients-2 recipients)))))
132 recipients)
133
66;;;###autoload 134;;;###autoload
67(defun epa-mail-decrypt () 135(defun epa-mail-decrypt ()
68 "Decrypt OpenPGP armors in the current buffer. 136 "Decrypt OpenPGP armors in the current buffer.
@@ -140,6 +208,13 @@ Don't use this command in Lisp programs!"
140 (setq recipients (delete "" 208 (setq recipients (delete ""
141 (split-string recipients 209 (split-string recipients
142 "[ \t\n]*,[ \t\n]*")))) 210 "[ \t\n]*,[ \t\n]*"))))
211
212 ;; Process all the recipients thru the list of GnuPG groups.
213 ;; Expand GnuPG group names to what they stand for.
214 ;; The code below, and elsewhere, that checks that names have keys
215 ;; does not know about these group names.
216 (setq recipients (epa-mail-expand-recipients recipients))
217
143 (goto-char (point-min)) 218 (goto-char (point-min))
144 (if (search-forward mail-header-separator nil t) 219 (if (search-forward mail-header-separator nil t)
145 (forward-line)) 220 (forward-line))