message: Set sender automatically

master
Pierre Neidhardt 2019-05-18 15:33:12 +02:00
parent 43235d6fad
commit 9b0194af99
1 changed files with 19 additions and 1 deletions

View File

@ -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)