- (config (epg-configuration))
- (recipients (message-options-get 'mml2015-epg-recipients))
- cipher
- (sender (message-options-get 'message-sender))
- (signer-names (or mml2015-signers
- (if (and mml2015-sign-with-sender sender)
- (list (concat "<" sender ">")))))
- signers
- 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 signer-names
- (error "Neither message sender nor mml2015-signers are set"))
- (setq recipients (nconc recipients signer-names)))
- (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. "
- signer-names
- t)
- (if (or sender mml2015-signers)
- (delq nil
- (mapcar
- (lambda (signer)
- (setq signer-key
- (mml2015-epg-find-usable-secret-key
- context signer '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)
- signer-names)))))))
- (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))))