Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mu4e: Set account by "to" field #4657

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions layers/+email/mu4e/funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,29 @@
;;
;;; License: GPLv3

(defun mu4e/search-account-by-mail-address (mail-address)
(car (rassoc-if (lambda (x)
(equal (cadr (assoc 'user-mail-address x)) mail-address))
mu4e-account-alist)))

(defun mu4e/set-account ()
"Set the account for composing a message."
(let* ((account
(if mu4e-compose-parent-message
(let ((maildir
(mu4e-message-field mu4e-compose-parent-message :maildir)))
(string-match "/\\(.*?\\)/" maildir)
(match-string 1 maildir))
(let* ((mailtos
(mu4e-message-field mu4e-compose-parent-message :to))
(mailto-account
(car (cl-remove-if-not 'identity
(mapcar (lambda (x)
(mu4e/search-account-by-mail-address (cdr x)))
mailtos))))
(maildir
(mu4e-message-field mu4e-compose-parent-message :maildir))
(maildir-account
(progn
(string-match "/\\(.*?\\)/" maildir)
(match-string 1 maildir))))
(or mailto-account maildir-account))
(helm-comp-read
"Compose with account:"
(mapcar (lambda (var) (car var)) mu4e-account-alist))))
Expand Down