X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=epa-mail.el;h=97b32045e27ff8baf97bff7a512be5c188c6247f;hb=7f32132982be06fe7ef290e06a7299612c9a5118;hp=0b0e099b83cb9823f85aee374122af589eb38564;hpb=328f497b8f2dcdcc2634f58f4317fd537f685e05;p=elisp%2Fepg.git diff --git a/epa-mail.el b/epa-mail.el index 0b0e099..97b3204 100644 --- a/epa-mail.el +++ b/epa-mail.el @@ -36,10 +36,27 @@ (define-key keymap "\C-c\C-eo" 'epa-insert-keys) keymap)) +(defvar epa-mail-mode-hook nil) +(defvar epa-mail-mode-on-hook nil) +(defvar epa-mail-mode-off-hook nil) + (define-minor-mode epa-mail-mode "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. @@ -94,7 +111,7 @@ Don't use this command in Lisp programs!" (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) @@ -125,21 +142,22 @@ Don't use this command in Lisp programs!" 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