Set context-aware "from" address (mu4e)
The user can configure a list of addresses that are associated with a context by passing a list to set-email-account!, e.g. (set-email-account! "foo" ... (+mu4e-personal-addresses ("foo@bar.org" "bar@baz.org"))) This list, if it exists, is used to prompt the user for the "from" address after trying to set the "from" address automatically.
This commit is contained in:
parent
522c1ca33b
commit
a8d7d61e44
2 changed files with 16 additions and 7 deletions
|
@ -15,6 +15,7 @@ OPTIONAL:
|
||||||
+ `mu4e-trash-folder'
|
+ `mu4e-trash-folder'
|
||||||
+ `mu4e-refile-folder'
|
+ `mu4e-refile-folder'
|
||||||
+ `mu4e-compose-signature'
|
+ `mu4e-compose-signature'
|
||||||
|
+ `+mu4e-personal-adresses'
|
||||||
|
|
||||||
DEFAULT-P is a boolean. If non-nil, it marks that email account as the
|
DEFAULT-P is a boolean. If non-nil, it marks that email account as the
|
||||||
default/fallback account."
|
default/fallback account."
|
||||||
|
@ -194,19 +195,24 @@ is tomorrow. With two prefixes, select the deadline."
|
||||||
(t "later"))))))
|
(t "later"))))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +mu4e-set-account ()
|
(defun +mu4e-set-from-address ()
|
||||||
"Set the account for composing a message. If a 'To' header is present,
|
"Set the account for composing a message. If a 'To' header is present,
|
||||||
and correspands to an email account, this account will be selected.
|
and correspands to an email address, this address will be selected.
|
||||||
Otherwise, the user is prompted for the account they wish to use."
|
Otherwise, the user is prompted for the address they wish to use. Possible
|
||||||
|
selections come from the mu database or a list of email addresses associated
|
||||||
|
with the current context."
|
||||||
(unless (and mu4e-compose-parent-message
|
(unless (and 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 (plist-get mu4e~server-props :personal-addresses))
|
(if (member to (mu4e-personal-addresses))
|
||||||
(setq user-mail-address to)
|
(setq user-mail-address to)
|
||||||
(if (member from (plist-get mu4e~server-props :personal-addresses))
|
(if (member from (mu4e-personal-addresses))
|
||||||
(setq user-mail-address from)
|
(setq user-mail-address from)
|
||||||
nil))))
|
nil))))
|
||||||
(ivy-read "Account: " (plist-get mu4e~server-props :personal-addresses) :action (lambda (candidate) (setq user-mail-address candidate)))))
|
(ivy-read "From: " (if-let ((context-addresses (alist-get '+mu4e-personal-addresses (mu4e-context-vars mu4e~context-current))))
|
||||||
|
context-addresses
|
||||||
|
(mu4e-personal-addresses))
|
||||||
|
:action (lambda (candidate) (setq user-mail-address candidate)))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +mu4e~main-action-str-prettier (str &optional func-or-shortcut)
|
(defun +mu4e~main-action-str-prettier (str &optional func-or-shortcut)
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
(defvar +mu4e-backend 'mbsync
|
(defvar +mu4e-backend 'mbsync
|
||||||
"Which backend to use. Can either be offlineimap, mbsync or nil (manual).")
|
"Which backend to use. Can either be offlineimap, mbsync or nil (manual).")
|
||||||
|
|
||||||
|
(defvar +mu4e-personal-adresses 'nil
|
||||||
|
"Alternative to mu4e-personal-adresses that can be set for each account (mu4e context).")
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;;; Packages
|
;;; Packages
|
||||||
|
@ -188,7 +191,7 @@
|
||||||
:v "u" #'mu4e-headers-mark-for-unmark
|
:v "u" #'mu4e-headers-mark-for-unmark
|
||||||
:vn "l" #'+mu4e-msg-to-agenda))
|
:vn "l" #'+mu4e-msg-to-agenda))
|
||||||
|
|
||||||
(add-hook 'mu4e-compose-pre-hook '+mu4e-set-account)
|
(add-hook 'mu4e-compose-pre-hook '+mu4e-set-from-address)
|
||||||
|
|
||||||
(advice-add #'mu4e~main-action-str :override #'+mu4e~main-action-str-prettier)
|
(advice-add #'mu4e~main-action-str :override #'+mu4e~main-action-str-prettier)
|
||||||
(when (featurep! :editor evil)
|
(when (featurep! :editor evil)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue