- (let ((context (epg-make-context))
- (recipients
- (if (message-options-get 'message-recipients)
- (split-string
- (message-options-get 'message-recipients)
- "[ \f\t\n\r\v,]+")))
- recipient-key signer-key cipher signers config)
- (when mml1991-encrypt-to-self
- (unless mml1991-signers
- (error "mml1991-signers is not set"))
- (setq recipients (nconc recipients mml1991-signers)))
- ;; We should remove this check if epg-0.0.6 is released.
- (if (and (condition-case nil
- (require 'epg-config)
- (error))
- (functionp #'epg-expand-group))
- (setq config (epg-configuration)
- recipients
- (apply #'nconc
- (mapcar (lambda (recipient)
- (or (epg-expand-group config recipient)
- (list recipient)))
- recipients))))
- (if (eq mm-encrypt-option 'guided)
- (setq recipients
- (epa-select-keys context "Select recipients for encryption.
-If no one is selected, symmetric encryption will be performed. "
- recipients))
- (setq recipients
- (delq nil (mapcar
- (lambda (name)
- (setq recipient-key (mml1991-epg-find-usable-key
- (epg-list-keys context name)
- 'encrypt))
- (unless (or recipient-key
- (y-or-n-p
- (format "No public key for %s; skip it? "
- name)))
- (error "No public key for %s" name))
- recipient-key)
- recipients)))
- (unless recipients
- (error "No recipient specified")))
- (when sign
- (if (eq mm-sign-option 'guided)
- (setq signers (epa-select-keys context "Select keys for signing.
-If no one is selected, default secret key is used. "
- mml1991-signers t))
- (if mml1991-signers
- (setq signers (delq nil
- (mapcar
- (lambda (name)
- (mml1991-epg-find-usable-secret-key
- context name 'sign))
- mml1991-signers)))))
- (epg-context-set-signers context signers))
- (epg-context-set-armor context t)
- (epg-context-set-textmode context t)
- (if mml1991-cache-passphrase
- (epg-context-set-passphrase-callback
- context
- #'mml1991-epg-passphrase-callback))
- (condition-case error
- (setq cipher
- (epg-encrypt-string context (buffer-string) recipients sign)
- mml1991-epg-secret-key-id-list nil)
- (error
- (while mml1991-epg-secret-key-id-list
- (password-cache-remove (car mml1991-epg-secret-key-id-list))
- (setq mml1991-epg-secret-key-id-list
- (cdr mml1991-epg-secret-key-id-list)))
- (signal (car error) (cdr error))))