- (let ((inhibit-redisplay t)
- (context (epg-make-context))
- (config (epg-configuration))
- (recipients (message-options-get 'mml2015-epg-recipients))
- cipher signers
- (boundary (mml-compute-boundary cont))
- recipient-key signer-key)
- (unless recipients
- (setq recipients
- (apply #'nconc
- (mapcar
- (lambda (recipient)
- (or (epg-expand-group config recipient)
- (list (concat "<" recipient ">"))))
- (split-string
- (or (message-options-get 'message-recipients)
- (message-options-set 'message-recipients
- (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)))
- (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 (recipient)
- (setq recipient-key (mml2015-epg-find-usable-key
- (epg-list-keys context 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)))
- (unless recipients
- (error "No recipient specified")))
- (message-options-set 'mml2015-epg-recipients recipients))
- (when sign
- (setq signers
- (or (message-options-get 'mml2015-epg-signers)
- (message-options-set
- 'mml2015-epg-signers
- (if (eq mm-sign-option 'guided)
- (epa-select-keys context "\
-Select keys for signing.
-If no one is selected, default secret key is used. "
- mml2015-signers t)
- (if mml2015-signers
- (delq nil
- (mapcar
- (lambda (signer)
- (setq signer-key (mml2015-epg-find-usable-key
- (epg-list-keys context signer t)
- 'sign))
- (unless (or signer-key
- (y-or-n-p
- (format
- "No secret key for %s; skip it? "
- signer)))
- (error "No secret key for %s" signer))
- signer-key)
- mml2015-signers)))))))
- (epg-context-set-signers context signers))
- (epg-context-set-armor context t)
- (epg-context-set-textmode context t)
- (if mml2015-cache-passphrase
- (epg-context-set-passphrase-callback
- context
- #'mml2015-epg-passphrase-callback))
- (condition-case error
- (setq cipher
- (epg-encrypt-string context (buffer-string) recipients sign
- mml2015-always-trust)
- mml2015-epg-secret-key-id-list nil)
- (error
- (while mml2015-epg-secret-key-id-list
- (password-cache-remove (car mml2015-epg-secret-key-id-list))
- (setq mml2015-epg-secret-key-id-list
- (cdr mml2015-epg-secret-key-id-list)))
- (signal (car error) (cdr error))))