From dd018399b23e16ca301dd18c4d32b55b94fd8a78 Mon Sep 17 00:00:00 2001 From: Benson Chu Date: Fri, 1 Nov 2024 11:54:23 -0500 Subject: [PATCH] Set email based on receiver --- lisp/mail/mu4e-configuration.el | 45 ++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/lisp/mail/mu4e-configuration.el b/lisp/mail/mu4e-configuration.el index 69dbcd4..0ed5b03 100644 --- a/lisp/mail/mu4e-configuration.el +++ b/lisp/mail/mu4e-configuration.el @@ -78,17 +78,44 @@ x) mu4e-bookmarks)) + (defvar my/email-accounts + '("bensonchu457@fastmail.com" + "bensonchu457@gmail.com" + "me@mail.pestctrl.io" + "dev@mail.pestctrl.io")) + (defun my/mu-init () (interactive) - (let ((addresses - '("bensonchu457@fastmail.com" - "bensonchu457@gmail.com" - "me@mail.pestctrl.io"))) - (async-shell-command - (format "mu init --maildir=~/.mail/ %s" - (--> addresses - (mapcar #'(lambda (x) (concat "--my-address=" x)) it) - (string-join it " ")))))) + (async-shell-command + (format "mu init --maildir=~/.mail/ %s" + (--> my/email-accounts + (mapcar #'(lambda (x) (concat "--my-address=" x)) it) + (string-join it " "))))) + + (defun my-mu4e-set-account () + (setq user-mail-address + (if (not mu4e-compose-parent-message) + (completing-read "Compose with account: " + my/email-accounts + nil t) + (mu4e-contact-email + (-any + #'(lambda (x) + (mu4e-message-contact-field-matches-me mu4e-compose-parent-message + x)) + '(:to :cc :bcc :from)))))) + + (add-hook 'mu4e-compose-pre-hook 'my-mu4e-set-account) + + (if (not (string= mu4e-mu-version "1.12.5")) + (warn "Remove this advice, bug has been fixed") + (defun my/mu4e-run-pre-hook (compose-type compose-func &optional parent) + (let ((mu4e-compose-parent-message parent) + (mu4e-compose-type compose-type)) + (run-hooks 'mu4e-compose-pre-hook))) + (advice-add #'mu4e--draft + :before + #'my/mu4e-run-pre-hook)) ;; (setcar mu4e-headers-thread-last-child-prefix "╰┬►") ;; (setcar mu4e-headers-thread-first-child-prefix "├┬►")