Skip to content

Commit

Permalink
tweak(mu4e): auto save google accounts on registration
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed Jun 9, 2023
1 parent 4db86af commit f099f67
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
20 changes: 19 additions & 1 deletion modules/extras/me-mu4e-extras.el
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,25 @@ Acts like a singular `mu4e-view-save-attachments', without the saving."
(mu4e-message "No attached files found")))
(mu4e-error "Not in `mu4e-view-mode' nor in `gnus-article-mode'.")))

(defun +mu4e-register-account (label maildir letvars &optional default-p)
(defun +mu4e-register-account (label maildir letvars &optional default-p gmail-p)
"Register a mu4e context named LABEL, located in MAILDIR.
LETVARS contains the alist of local variables with their values.
If DEFAULT-P is non-nil, the context is placed first and considered the default
one. If GMAIL-P is non-nil, addresses are saved to `+mu4e-gmail-accounts' to be
used later for Gmail specific actions."
(when gmail-p
(with-eval-after-load 'me-mu4e-gmail
(setq
+mu4e-gmail-accounts
(delete-dups
(append
+mu4e-gmail-accounts
(mapcar (+apply-partially-right
#'cons
(concat (if (string-prefix-p "/" maildir) "" "/") maildir))
(append
(ensure-list (alist-get 'user-mail-address letvars))
(alist-get '+mu4e-account-aliases letvars))))))))
(let ((context
(make-mu4e-context
:name label
Expand Down
3 changes: 2 additions & 1 deletion modules/extras/me-mu4e-gmail.el
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ See `+mu4e-msg-gmail-p' and `mu4e-sent-messages-behavior'."
(let ((root-maildir
(replace-regexp-in-string
"/.*" "" (substring (mu4e-message-field msg :maildir) 1))))
(or (member (concat "/" root-maildir) (mapcar #'cdr +mu4e-gmail-accounts))
(or (member (concat "/" root-maildir)
(seq-uniq (mapcar #'cdr +mu4e-gmail-accounts) #'string=))
(string-match-p "gmail" root-maildir)
(string-match-p "google" root-maildir))))

Expand Down
8 changes: 4 additions & 4 deletions skel/config.el
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@

;; (setq mail-personal-alias-file (concat minemacs-config-dir "private/mail-aliases.mailrc"))

(setq +mu4e-auto-bcc-address "always.bcc@this.email" ;; Add an email address always included as BCC
+mu4e-gmail-accounts '(("account1@gmail.com" . "/gmail")
("account@somesite.org" . "/gmail")))
(setq +mu4e-auto-bcc-address "always.bcc@this.email") ;; Add an email address always included as BCC

;; Register email accounts with mu4e
;; Use MinEmacs' `+mu4e-register-account' helper function to register multiple accounts
Expand All @@ -89,7 +87,9 @@
"Regards," ;; Closing phrase
"Firstname" ;; First name
"Lastname" ;; Last name
"/R&D Engineer at Some company/")))))
"/R&D Engineer at Some company/")))
'default ;; Use it as default in a multi-accounts setting
'gmail)) ;; This is a Gmail account, store it and treat it accordingly (see `me-mu4e-gmail')

;; Module: `me-org' -- Package: `org'
(with-eval-after-load 'org
Expand Down

0 comments on commit f099f67

Please sign in to comment.