52 lines
1.8 KiB
EmacsLisp
52 lines
1.8 KiB
EmacsLisp
|
;; Message mode
|
||
|
;; This is common to Gnus, mu4e, notmuch, etc.
|
||
|
|
||
|
(setq mm-default-directory "~/temp" ; Where to save attachments.
|
||
|
message-kill-buffer-on-exit t
|
||
|
;; Sending mail:
|
||
|
mail-specify-envelope-from t
|
||
|
mail-envelope-from 'header
|
||
|
message-send-mail-function 'smtpmail-send-it)
|
||
|
|
||
|
(load "~/personal/mail/smtpmail.el" 'noerror)
|
||
|
|
||
|
;; TODO: Use the following to automatically set the From: field when replying.
|
||
|
;; message-alternative-emails
|
||
|
|
||
|
;; Sign messages by default.
|
||
|
(add-hook 'message-setup-hook 'mml-secure-sign-pgpmime)
|
||
|
|
||
|
(defun message-recipients ()
|
||
|
"Return a list of all recipients in the message, looking at TO, CC and BCC.
|
||
|
|
||
|
Each recipient is in the format of `mail-extract-address-components'."
|
||
|
(mapcan (lambda (header)
|
||
|
(let ((header-value (message-fetch-field header)))
|
||
|
(and
|
||
|
header-value
|
||
|
(mail-extract-address-components header-value t))))
|
||
|
'("To" "Cc" "Bcc")))
|
||
|
|
||
|
(defun message-all-epg-keys-available-p ()
|
||
|
"Return non-nil if the pgp keyring has a public key for each recipient."
|
||
|
(require 'epa)
|
||
|
(let ((context (epg-make-context epa-protocol)))
|
||
|
(catch 'break
|
||
|
(dolist (recipient (message-recipients))
|
||
|
(let ((recipient-email (cadr recipient)))
|
||
|
(when (and recipient-email (not (epg-list-keys context recipient-email)))
|
||
|
(throw 'break nil))))
|
||
|
t)))
|
||
|
|
||
|
(defun message-sign-encrypt-if-all-keys-available ()
|
||
|
"Add MML tag to encrypt message when there is a key for each recipient.
|
||
|
|
||
|
Consider adding this function to `message-send-hook' to
|
||
|
systematically send encrypted emails when possible."
|
||
|
(when (message-all-epg-keys-available-p)
|
||
|
(mml-secure-message-sign-encrypt)))
|
||
|
|
||
|
;; (add-hook 'message-send-hook #'message-sign-encrypt-if-all-keys-available)
|
||
|
|
||
|
(provide 'init-message)
|