message: Fix message-recipients and file structure

master
Pierre Neidhardt 2019-03-18 13:12:13 +01:00
parent 3645d66093
commit 01fcdc89b2
1 changed files with 25 additions and 17 deletions

View File

@ -15,14 +15,8 @@
;; Might not be necessary.
;; message-alternative-emails
;; Sign messages by default. TODO: Which method?
(add-hook 'message-setup-hook 'mml-secure-sign-pgpmime)
;; (add-hook 'message-setup-hook 'mml-secure-message-sign-pgpmime)
;; Also crypt to self so that we can read sent e-mails.
(setq mml-secure-openpgp-encrypt-to-self t)
(defun message-recipients ()
(defun message-recipients (&optional include-from)
"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'."
@ -31,7 +25,15 @@ Each recipient is in the format of `mail-extract-address-components'."
(and
header-value
(mail-extract-address-components header-value t))))
'("To" "Cc" "Bcc")))
`(,@(when include-from '("From")) "To" "Cc" "Bcc")))
;; Sign messages by default. TODO: Which method?
(add-hook 'message-setup-hook 'mml-secure-sign-pgpmime)
;; (add-hook 'message-setup-hook 'mml-secure-message-sign-pgpmime)
;; Also crypt to self so that we can read sent e-mails.
(setq mml-secure-openpgp-encrypt-to-self t)
(defvar ambrevar/trust-threshold '(marignal full ultimate))
(defun ambrevar/trusted-addresses ()
@ -51,13 +53,15 @@ Consider adding this function to `message-send-hook' to
systematically send encrypted emails when possible."
(let* ((recipients (message-recipients))
(untrusted-recipients (seq-difference recipients (ambrevar/trusted-addresses))))
(if untrusted-recipients
(warn "Not encrypting because of untrusted %s" untrusted-recipients)
(mml-secure-message-sign-encrypt))))
(unless untrusted-recipients
(mml-secure-message-sign-encrypt)
;; (warn "Not encrypting because of untrusted %s" untrusted-recipients)
)))
;; TODO: Test and report upstream (Emacs + Notmuch).
(add-hook 'message-send-hook #'message-sign-encrypt-if-all-keys-trusted)
;; Fix replying to GitHub. TODO: Test!
(defun ambrevar/message-alter-bogus-github-recipients (addrcell)
"Discard @reply.github.com mail addresses.
@ -68,22 +72,26 @@ cdr is the complete address (full name and mail address)."
addrcell))
(setq message-alter-recipients-function 'ambrevar/message-alter-bogus-github-recipients)
(defvar ambrevar/mu4e-compose-fortune-p nil
(defvar ambrevar/message-compose-fortune-p nil
"Whether or not to include a fortune in the signature.")
(defun ambrevar/mu4e-add-signature-and-maybe-fortune ()
(defun ambrevar/message-add-signature-and-maybe-fortune ()
"Insert signature using `user-full-name'.
A fortune is appended if `ambrevar/mu4e-compose-fortune-p' is non-nil."
A fortune is appended if `ambrevar/message-compose-fortune-p' is non-nil."
(require 'functions) ; For `call-process-to-string'.
;; Return the signature and set it for mu4e.
(setq mu4e-compose-signature
(concat
user-full-name "\n"
"https://ambrevar.xyz/"
(when (and ambrevar/mu4e-compose-fortune-p
(when (and ambrevar/message-compose-fortune-p
(executable-find "fortune"))
(concat "\n\n"
(ambrevar/call-process-to-string "fortune" "-s"))))))
(add-hook 'message-setup-hook 'ambrevar/mu4e-add-signature-and-maybe-fortune)
;; (add-hook 'message-setup-hook 'ambrevar/message-add-signature-and-maybe-fortune)
(setq message-signature 'ambrevar/message-add-signature-and-maybe-fortune)
(defun ambrevar/mu4e-select-dictionary ()
"Set dictionary according to the LANGUAGE property of the first
\"To:\" recipient found in the Org contacts file."