From 01fcdc89b2831ea942780f1278085212144481a6 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Mon, 18 Mar 2019 13:12:13 +0100 Subject: [PATCH] message: Fix message-recipients and file structure --- .emacs.d/lisp/init-message.el | 42 +++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/.emacs.d/lisp/init-message.el b/.emacs.d/lisp/init-message.el index 2d997fc1..5f38cf0c 100644 --- a/.emacs.d/lisp/init-message.el +++ b/.emacs.d/lisp/init-message.el @@ -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."