Mu4e: Try to reply with To: addr, else prompt

This commit is contained in:
TEC 2020-05-23 18:58:31 +08:00
parent 2483d47021
commit 7208b3de64
1 changed files with 17 additions and 0 deletions

View File

@ -1633,6 +1633,23 @@ Let's send emails too.
message-send-mail-function 'message-send-mail-with-sendmail))
#+END_SRC
It's also nice to avoid accidently sending emails with the wrong account.
If we can send from the address in the ~To~ field, let's do that. Opening an ~ivy~
prompt otherwise also seems sensible.
#+BEGIN_SRC emacs-lisp
(after! mu4e
(defun my-mu4e-set-account ()
"Set the account for composing a message."
(when (and mu4e-compose-parent-message
(let ((mail (cdr (car (mu4e-message-field mu4e-compose-parent-message :to)))))
(if (member mail (plist-get mu4e~server-props :personal-addresses))
(setq user-mail-address mail)
nil))
(ivy-read "Account: " (plist-get mu4e~server-props :personal-addresses) :action (lambda (candidate) (setq user-mail-address candidate))))))
(add-hook 'mu4e-compose-pre-hook 'my-mu4e-set-account))
#+END_SRC
We can register Emacs as a potential email client with the following desktop
file, thanks to Etienne Deparis's [[https://etienne.depar.is/emacs.d/mu4e.html][Mu4e customization]].
#+BEGIN_SRC conf :tangle ~/.local/share/applications/emacsmail.desktop