;;; mml2015.el --- MIME Security with Pretty Good Privacy (PGP)
;; Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
-;; 2008, 2009, 2010 Free Software Foundation, Inc.
+;; 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
;; Keywords: PGP MIME MML
;;; Code:
-;; For Emacs < 22.2.
(eval-and-compile
+ ;; For Emacs <22.2 and XEmacs.
(unless (fboundp 'declare-function) (defmacro declare-function (&rest r)))
(if (locate-library "password-cache")
'epg)
(error))
(progn
- (ignore-errors
- ;; Avoid the "Recursive load suspected" error
- ;; in Emacs 21.1.
- (let ((recursive-load-depth-limit 100))
- (require 'pgg)))
+ (ignore-errors (require 'pgg))
(and (fboundp 'pgg-sign-region)
'pgg))
(progn (ignore-errors
(autoload 'epg-key-sub-key-list "epg")
(autoload 'epg-sub-key-capability "epg")
(autoload 'epg-sub-key-validity "epg")
+(autoload 'epg-sub-key-fingerprint "epg")
(autoload 'epg-configuration "epg-config")
(autoload 'epg-expand-group "epg-config")
(autoload 'epa-select-keys "epa")
(setq pointer (cdr pointer))))
(setq keys (cdr keys)))))
+;; XXX: since gpg --list-secret-keys does not return validity of each
+;; key, `mml2015-epg-find-usable-key' defined above is not enough for
+;; secret keys. The function `mml2015-epg-find-usable-secret-key'
+;; below looks at appropriate public keys to check usability.
+(defun mml2015-epg-find-usable-secret-key (context name usage)
+ (let ((secret-keys (epg-list-keys context name t))
+ secret-key)
+ (while (and (not secret-key) secret-keys)
+ (if (mml2015-epg-find-usable-key
+ (epg-list-keys context (epg-sub-key-fingerprint
+ (car (epg-key-sub-key-list
+ (car secret-keys)))))
+ usage)
+ (setq secret-key (car secret-keys)
+ secret-keys nil)
+ (setq secret-keys (cdr secret-keys))))
+ secret-key))
+
(defun mml2015-epg-decrypt (handle ctl)
(catch 'error
(let ((inhibit-redisplay t)
(let* ((inhibit-redisplay t)
(context (epg-make-context))
(boundary (mml-compute-boundary cont))
+ (sender (message-options-get 'message-sender))
signer-key
(signers
(or (message-options-get 'mml2015-epg-signers)
(epa-select-keys context "\
Select keys for signing.
If no one is selected, default secret key is used. "
- mml2015-signers t)
- (if mml2015-signers
+ (if sender
+ (cons (concat "<" sender ">")
+ mml2015-signers)
+ mml2015-signers)
+ t)
+ (if (or sender mml2015-signers)
(delq nil
(mapcar
(lambda (signer)
- (setq signer-key (mml2015-epg-find-usable-key
- (epg-list-keys context signer t)
- 'sign))
+ (setq signer-key
+ (mml2015-epg-find-usable-secret-key
+ context signer 'sign))
(unless (or signer-key
(y-or-n-p
(format
signer)))
(error "No secret key for %s" signer))
signer-key)
- mml2015-signers)))))))
+ (if sender
+ (cons (concat "<" sender ">")
+ mml2015-signers)
+ mml2015-signers))))))))
signature micalg)
(epg-context-set-armor context t)
(epg-context-set-textmode context t)
(let ((inhibit-redisplay t)
(context (epg-make-context))
(config (epg-configuration))
+ (sender (message-options-get 'message-sender))
(recipients (message-options-get 'mml2015-epg-recipients))
cipher signers
(boundary (mml-compute-boundary cont))
(read-string "Recipients: ")))
"[ \f\t\n\r\v,]+"))))
(when mml2015-encrypt-to-self
- (unless mml2015-signers
- (error "mml2015-signers not set"))
- (setq recipients (nconc recipients mml2015-signers)))
+ (unless (or sender mml2015-signers)
+ (error "Message sender and mml2015-signers not set"))
+ (setq recipients (nconc recipients (if sender
+ (cons (concat "<" sender ">")
+ mml2015-signers)
+ mml2015-signers))))
(if (eq mm-encrypt-option 'guided)
(setq recipients
(epa-select-keys context "\
(epa-select-keys context "\
Select keys for signing.
If no one is selected, default secret key is used. "
- mml2015-signers t)
- (if mml2015-signers
+ (if sender
+ (cons (concat "<" sender ">")
+ mml2015-signers)
+ mml2015-signers)
+ t)
+ (if (or sender mml2015-signers)
(delq nil
(mapcar
(lambda (signer)
- (setq signer-key (mml2015-epg-find-usable-key
- (epg-list-keys context signer t)
- 'sign))
+ (setq signer-key
+ (mml2015-epg-find-usable-secret-key
+ context signer 'sign))
(unless (or signer-key
(y-or-n-p
(format
signer)))
(error "No secret key for %s" signer))
signer-key)
- mml2015-signers)))))))
+ (if sender
+ (cons (concat "<" sender ">") mml2015-signers)
+ mml2015-signers))))))))
(epg-context-set-signers context signers))
(epg-context-set-armor context t)
(epg-context-set-textmode context t)