Mu4e: Add nuance to Gmail-specific behaviour
for the non-gmail accounts out there
This commit is contained in:
parent
940177613e
commit
f7a2479064
2 changed files with 49 additions and 10 deletions
|
@ -36,7 +36,8 @@ via IMAP) and ~mu~ (to index my mail into a format ~mu4e~ can understand).
|
||||||
#+end_quote
|
#+end_quote
|
||||||
|
|
||||||
** Module Flags
|
** Module Flags
|
||||||
+ ~+gmail~ Enables gmail-specific configuration.
|
+ ~+gmail~ Enables gmail-specific configuration for mail ~To~ or ~From~ a gmail
|
||||||
|
address, or a maildir with ~gmail~ in the name.
|
||||||
|
|
||||||
** Plugins
|
** Plugins
|
||||||
+ [[https://github.com/jeremy-compostella/org-msg][org-msg]]
|
+ [[https://github.com/jeremy-compostella/org-msg][org-msg]]
|
||||||
|
|
|
@ -325,7 +325,10 @@ Must be set before org-msg is loaded to take effect.")
|
||||||
(when (featurep! +gmail)
|
(when (featurep! +gmail)
|
||||||
(after! mu4e
|
(after! mu4e
|
||||||
;; don't save message to Sent Messages, Gmail/IMAP takes care of this
|
;; don't save message to Sent Messages, Gmail/IMAP takes care of this
|
||||||
(setq mu4e-sent-messages-behavior 'delete
|
(setq mu4e-sent-messages-behavior
|
||||||
|
(lambda ()
|
||||||
|
(if (string-match-p "@gmail.com\\'" (message-sendmail-envelope-from))
|
||||||
|
'delete 'sent))
|
||||||
|
|
||||||
;; don't need to run cleanup after indexing for gmail
|
;; don't need to run cleanup after indexing for gmail
|
||||||
mu4e-index-cleanup nil
|
mu4e-index-cleanup nil
|
||||||
|
@ -334,6 +337,19 @@ Must be set before org-msg is loaded to take effect.")
|
||||||
;; messages don't really "move"
|
;; messages don't really "move"
|
||||||
mu4e-index-lazy-check t)
|
mu4e-index-lazy-check t)
|
||||||
|
|
||||||
|
(defun +mu4e-msg-gmail-p (msg)
|
||||||
|
(or
|
||||||
|
(string-match-p "gmail"
|
||||||
|
(cond
|
||||||
|
((member (mu4e-message-field msg :to)
|
||||||
|
(plist-get mu4e~server-props :personal-addresses))
|
||||||
|
(mu4e-message-field msg :to))
|
||||||
|
((member (mu4e-message-field msg :from)
|
||||||
|
(plist-get mu4e~server-props :personal-addresses))
|
||||||
|
(mu4e-message-field msg :from))
|
||||||
|
(t "")))
|
||||||
|
(string-match-p "gmail" (mu4e-message-field msg :maildir))))
|
||||||
|
|
||||||
;; In my workflow, emails won't be moved at all. Only their flags/labels are
|
;; In my workflow, emails won't be moved at all. Only their flags/labels are
|
||||||
;; changed. Se we redefine the trash and refile marks not to do any moving.
|
;; changed. Se we redefine the trash and refile marks not to do any moving.
|
||||||
;; However, the real magic happens in `+mu4e|gmail-fix-flags'.
|
;; However, the real magic happens in `+mu4e|gmail-fix-flags'.
|
||||||
|
@ -342,18 +358,39 @@ Must be set before org-msg is loaded to take effect.")
|
||||||
(defun +mu4e--mark-seen (docid _msg target)
|
(defun +mu4e--mark-seen (docid _msg target)
|
||||||
(mu4e~proc-move docid (mu4e~mark-check-target target) "+S-u-N"))
|
(mu4e~proc-move docid (mu4e~mark-check-target target) "+S-u-N"))
|
||||||
|
|
||||||
|
(defvar +mu4e--last-invalid-gmail-action 0)
|
||||||
|
|
||||||
(delq! 'delete mu4e-marks #'assq)
|
(delq! 'delete mu4e-marks #'assq)
|
||||||
(setf (alist-get 'trash mu4e-marks)
|
(setf (alist-get 'delete mu4e-marks)
|
||||||
|
(list
|
||||||
|
:char '("D" . "✘")
|
||||||
|
:prompt "Delete"
|
||||||
|
:show-target (lambda (target) "delete")
|
||||||
|
:action (lambda (docid msg target)
|
||||||
|
(if (+mu4e-msg-gmail-p msg)
|
||||||
|
(progn (message "The delete operation is invalid for Gmail accounts.")
|
||||||
|
(when (< 2 (- (float-time) +mu4e--last-invalid-gmail-action))
|
||||||
|
(sit-for 1))
|
||||||
|
(setq +mu4e--last-invalid-gmail-action (float-time)))
|
||||||
|
(mu4e~proc-remove docid))))
|
||||||
|
(alist-get 'trash mu4e-marks)
|
||||||
(list :char '("d" . "▼")
|
(list :char '("d" . "▼")
|
||||||
:prompt "dtrash"
|
:prompt "dtrash"
|
||||||
:dyn-target (lambda (_target msg) (mu4e-get-trash-folder msg))
|
:dyn-target (lambda (_target msg) (mu4e-get-trash-folder msg))
|
||||||
:action #'+mu4e--mark-seen)
|
:action (lambda (docid msg target)
|
||||||
|
(if (+mu4e-msg-gmail-p msg)
|
||||||
|
(+mu4e--mark-seen docid msg target)
|
||||||
|
(mu4e~proc-move docid (mu4e~mark-check-target target) "+T-N"))))
|
||||||
;; Refile will be my "archive" function.
|
;; Refile will be my "archive" function.
|
||||||
(alist-get 'refile mu4e-marks)
|
(alist-get 'refile mu4e-marks)
|
||||||
(list :char '("r" . "▼")
|
(list :char '("r" . "▼")
|
||||||
:prompt "rrefile"
|
:prompt "rrefile"
|
||||||
:dyn-target (lambda (_target msg) (mu4e-get-refile-folder msg))
|
:dyn-target (lambda (_target msg) (mu4e-get-refile-folder msg))
|
||||||
:action #'+mu4e--mark-seen))
|
:action (lambda (docid msg target)
|
||||||
|
(if (+mu4e-msg-gmail-p msg)
|
||||||
|
(+mu4e--mark-seen docid msg target)
|
||||||
|
(mu4e~proc-move docid (mu4e~mark-check-target target) "-N")))
|
||||||
|
#'+mu4e--mark-seen))
|
||||||
|
|
||||||
;; This hook correctly modifies gmail flags on emails when they are marked.
|
;; This hook correctly modifies gmail flags on emails when they are marked.
|
||||||
;; Without it, refiling (archiving), trashing, and flagging (starring) email
|
;; Without it, refiling (archiving), trashing, and flagging (starring) email
|
||||||
|
@ -361,8 +398,9 @@ Must be set before org-msg is loaded to take effect.")
|
||||||
;; are ineffectual otherwise.
|
;; are ineffectual otherwise.
|
||||||
(add-hook! 'mu4e-mark-execute-pre-hook
|
(add-hook! 'mu4e-mark-execute-pre-hook
|
||||||
(defun +mu4e-gmail-fix-flags-h (mark msg)
|
(defun +mu4e-gmail-fix-flags-h (mark msg)
|
||||||
(pcase mark
|
(when (+mu4e-msg-gmail-p msg)
|
||||||
(`trash (mu4e-action-retag-message msg "-\\Inbox,+\\Trash,-\\Draft"))
|
(pcase mark
|
||||||
(`refile (mu4e-action-retag-message msg "-\\Inbox"))
|
(`trash (mu4e-action-retag-message msg "-\\Inbox,+\\Trash,-\\Draft"))
|
||||||
(`flag (mu4e-action-retag-message msg "+\\Starred"))
|
(`refile (mu4e-action-retag-message msg "-\\Inbox"))
|
||||||
(`unflag (mu4e-action-retag-message msg "-\\Starred")))))))
|
(`flag (mu4e-action-retag-message msg "+\\Starred"))
|
||||||
|
(`unflag (mu4e-action-retag-message msg "-\\Starred"))))))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue