From 9b0194af99ed5b28981a1f705b85eefc67d8af64 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Sat, 18 May 2019 15:33:12 +0200 Subject: [PATCH] message: Set sender automatically --- .emacs.d/lisp/init-message.el | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.emacs.d/lisp/init-message.el b/.emacs.d/lisp/init-message.el index 39a67b5b..2a9b5d6c 100644 --- a/.emacs.d/lisp/init-message.el +++ b/.emacs.d/lisp/init-message.el @@ -121,7 +121,25 @@ A fortune is appended if `ambrevar/message-compose-fortune-p' is non-nil." (setq addresses (cdr addresses)) (ispell-change-dictionary (cdr (assoc (car addresses) address-lang-map))) (setq addresses nil))))) - (add-hook 'message-setup-hook 'ambrevar/message-select-dictionary)) + (add-hook 'message-setup-hook 'ambrevar/message-select-dictionary) + + (defun ambrevar/message-select-sender () + "Set the sender according to the SENDER property of the first +\"To:\" recipient found in the Org contacts file." + (interactive) + (let* ((addresses (mapcar #'cadr (ambrevar/message-recipients))) + (sender (cl-loop for contact in (org-contacts-filter) + for email-list = (org-contacts-split-property + (or (cdr (assoc-string org-contacts-email-property + (nth 2 contact))) "")) + when (cl-loop for email in email-list + thereis (string= (downcase email) + (downcase (car addresses)))) + return (cdr (assoc-string "SENDER" (nth 2 contact)))))) + (when sender + (ambrevar/notmuch-change-sender sender)))) + (add-hook 'message-send-hook 'ambrevar/message-select-sender)) + ;; Because it's to tempting to send an e-mail riddled with typos... (add-hook 'message-setup-hook 'flyspell-mode)