Mu4e: More contextual +mu4e-set-from-address-h
This hook should only be used when users define email aliases, or no contexts are defined (in which case the list of personal addresses should be used). Otherwise, the `:match-func` contexts feature is sufficient.
This commit is contained in:
parent
a75dea6281
commit
2fd89a7eca
2 changed files with 37 additions and 24 deletions
|
@ -169,6 +169,22 @@ Then configure Emacs to use your email address:
|
||||||
t)
|
t)
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
|
If you use multiple email accounts, defining them with ~set-email-account!~ will
|
||||||
|
automatically set the appropriate account context when replying to emails in
|
||||||
|
that account's maildir. ~mu4e-context-policy~ and ~mu4e-compose-context-policy~
|
||||||
|
can be modified to change context behavior when opening mu4e and composing
|
||||||
|
email:
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(setq mu4e-context-policy 'ask-if-none
|
||||||
|
mu4e-compose-context-policy 'always-ask)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
If you send mail from various email aliases for different services,
|
||||||
|
~+mu4e-personal-addresses~ can be set per-context with ~set-email-account!~. If
|
||||||
|
you are not replying to an email to or from one of the specified aliases, you
|
||||||
|
will be prompted for an alias to send from.
|
||||||
|
|
||||||
*** Gmail
|
*** Gmail
|
||||||
With the =+gmail= flag, integrations are applied which account for the different
|
With the =+gmail= flag, integrations are applied which account for the different
|
||||||
behaviour of Gmail.
|
behaviour of Gmail.
|
||||||
|
|
|
@ -30,8 +30,11 @@ default/fallback account."
|
||||||
collect context))
|
collect context))
|
||||||
(let ((context (make-mu4e-context
|
(let ((context (make-mu4e-context
|
||||||
:name label
|
:name label
|
||||||
:enter-func (lambda () (mu4e-message "Switched to %s" label))
|
:enter-func
|
||||||
:leave-func #'mu4e-clear-caches
|
(lambda () (mu4e-message "Switched to %s" label))
|
||||||
|
:leave-func
|
||||||
|
(lambda () (progn (setq +mu4e-personal-addresses nil)
|
||||||
|
(mu4e-clear-caches)))
|
||||||
:match-func
|
:match-func
|
||||||
(lambda (msg)
|
(lambda (msg)
|
||||||
(when msg
|
(when msg
|
||||||
|
@ -328,26 +331,20 @@ When otherwise called, open a dired buffer and enable `dired-mu4e-attach-ctrl-c-
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +mu4e-set-from-address-h ()
|
(defun +mu4e-set-from-address-h ()
|
||||||
"Set the account for composing a message. If a 'To' header is present,
|
"If the user defines multiple `+mu4e-personal-addresses' for email aliases
|
||||||
and correspands to an email address, this address will be selected.
|
within a context, set `user-mail-address' to an alias found in the 'To' or
|
||||||
Otherwise, the user is prompted for the address they wish to use. Possible
|
'From' headers of the parent message if present, or prompt the user for a
|
||||||
selections come from the mu database or a list of email addresses associated
|
preferred alias"
|
||||||
with the current context."
|
(when-let ((addresses (if (or mu4e-contexts+mu4e-personal-addresses)
|
||||||
(unless (and mu4e-compose-parent-message
|
(and (> (length +mu4e-personal-addresses) 1)
|
||||||
|
+mu4e-personal-addresses)
|
||||||
|
(mu4e-personal-addresses))))
|
||||||
|
(setq user-mail-address
|
||||||
|
(if mu4e-compose-parent-message
|
||||||
(let ((to (cdr (car (mu4e-message-field mu4e-compose-parent-message :to))))
|
(let ((to (cdr (car (mu4e-message-field mu4e-compose-parent-message :to))))
|
||||||
(from (cdr (car (mu4e-message-field mu4e-compose-parent-message :from)))))
|
(from (cdr (car (mu4e-message-field mu4e-compose-parent-message :from)))))
|
||||||
(if (member to (mu4e-personal-addresses))
|
(cond
|
||||||
(setq user-mail-address to)
|
((member to addresses) to)
|
||||||
(if (member from (mu4e-personal-addresses))
|
((member from addresses) from)
|
||||||
(setq user-mail-address from)
|
(t (completing-read "From: " addresses))))
|
||||||
nil))))
|
(completing-read "From: " addresses)))))
|
||||||
(setq user-mail-address
|
|
||||||
(if (= (length +mu4e-personal-addresses) 1)
|
|
||||||
(car +mu4e-personal-addresses)
|
|
||||||
(completing-read
|
|
||||||
"From: "
|
|
||||||
(if-let ((context-addresses
|
|
||||||
(when mu4e~context-current
|
|
||||||
(alist-get '+mu4e-personal-addresses (mu4e-context-vars mu4e~context-current)))))
|
|
||||||
context-addresses
|
|
||||||
(mu4e-personal-addresses)))))))
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue