+2008-01-22 Daiki Ueno <ueno@unixuser.org>
+
+ * epa-mail.el (epa-mail--find-usable-key): New function.
+ (epa-mail-encrypt): Use it.
+ Reported by intrigeri <intrigeri@boum.org>.
+
2007-11-26 Daiki Ueno <ueno@unixuser.org>
* epg-package-info.el.in (epg-bug-report-address): New constant.
"A minor-mode for composing encrypted/clearsigned mails."
nil " epa-mail" epa-mail-mode-map)
+(defun epa-mail--find-usable-key (keys usage)
+ "Find a usable key from KEYS for USAGE."
+ (catch 'found
+ (while keys
+ (let ((pointer (epg-key-sub-key-list (car keys))))
+ (while pointer
+ (if (and (memq usage (epg-sub-key-capability (car pointer)))
+ (not (memq (epg-sub-key-validity (car pointer))
+ '(revoked expired))))
+ (throw 'found (car keys)))
+ (setq pointer (cdr pointer))))
+ (setq keys (cdr keys)))))
+
;;;###autoload
(defun epa-mail-decrypt ()
"Decrypt OpenPGP armors in the current buffer.
(save-excursion
(let ((verbose current-prefix-arg)
(context (epg-make-context epa-protocol))
- recipients recipient-keys)
+ recipients recipient-key)
(goto-char (point-min))
(save-restriction
(narrow-to-region (point)
If no one is selected, symmetric encryption will be performed. "
recipients)
(if recipients
- (apply #'nconc
- (mapcar
- (lambda (recipient)
- (setq recipient-keys
- (epg-list-keys
- (epg-make-context epa-protocol)
- (concat "<" recipient ">")))
- (unless (or recipient-keys
- (y-or-n-p
- (format
- "No public key for %s; skip it? "
- recipient)))
- (error "No public key for %s" recipient))
- recipient-keys)
- recipients))))
+ (mapcar
+ (lambda (recipient)
+ (setq recipient-key
+ (epa-mail--find-usable-key
+ (epg-list-keys
+ (epg-make-context epa-protocol)
+ (concat "<" recipient ">"))
+ 'encrypt))
+ (unless (or recipient-key
+ (y-or-n-p
+ (format
+ "No public key for %s; skip it? "
+ recipient)))
+ (error "No public key for %s" recipient))
+ recipient-key)
+ recipients)))
(setq sign (if verbose (y-or-n-p "Sign? ")))
(if sign
(epa-select-keys context