fedora-csb-system-manager
1;;; config-mu4e.el -- mu emacs client configuration -*- lexical-binding: t -*-
2;;; Commentary:
3;;; Code:
4
5(use-package mu4e
6 :commands (mu4e)
7 :custom
8 (mu4e-mu-home "/home/vincent/.local/cache/mu")
9 (mu4e-context-policy 'pick-first)
10 (mu4e-change-filenames-when-moving t)
11 (mu4e-attachment-dir "~/desktop/downloads")
12 :config
13 (setq mu4e-get-mail-command (concat (executable-find "mbsync") " --all"))
14 (setq mu4e-update-interval 1800) ; 30m
15
16 (defun vde-mu4e--mark-get-copy-target ()
17 "Ask for a copy target, and propose to create it if it does not exist."
18 (let* ((target (mu4e-ask-maildir "Copy message to: "))
19 (target (if (string= (substring target 0 1) "/")
20 target
21 (concat "/" target)))
22 (fulltarget (mu4e-join-paths (mu4e-root-maildir) target)))
23 (when (mu4e-create-maildir-maybe fulltarget)
24 target)))
25
26 (defun copy-message-to-target(docid msg target)
27 (let (
28 (new_msg_path nil) ;; local variable
29 (msg_flags (mu4e-message-field msg :flags))
30 )
31 ;; 1. target is already determined interactively when executing the mark (:ask-target)
32
33 ;; 2. Determine the path for the new file: we use mu4e~draft-message-filename-construct from
34 ;; mu4e-draft.el to create a new random filename, and append the original's msg_flags
35 (setq new_msg_path (format "%s/%s/cur/%s" mu4e-maildir target (mu4e~draft-message-filename-construct
36 (mu4e-flags-to-string msg_flags))))
37
38 ;; 3. Copy the message using file system call (copy-file) to new_msg_path:
39 ;; (See e.g. mu4e-draft.el > mu4e-draft-open > resend)
40 (copy-file (mu4e-message-field msg :path) new_msg_path)
41
42 ;; 4. Add the information to the database (may need to update current search query with 'g' if duplicating to current box. Try also 'V' to toggle the display of duplicates)
43 (mu4e~proc-add new_msg_path (mu4e~mark-check-target target))
44 )
45 )
46
47 (defun vde-mu4e--refile (msg)
48 "Refile function to smartly move `MSG' to a given folder."
49 (cond
50 ;; Delete GitHub CI activity notifications
51 ((string= (plist-get (car-safe (mu4e-message-field msg :cc)) :email) "ci_activity@noreply.github.com")
52 "/icloud/Deleted Messages")
53 ;; Move Red Hat emails to Trash (will be permanently deleted by Gmail after 30 days)
54 ((string-prefix-p "/redhat" (mu4e-message-field msg :maildir))
55 "/redhat/[Gmail]/Trash")
56 ;; Archive iCloud and other emails by year
57 (t
58 (let ((year (format-time-string "%Y" (mu4e-message-field msg :date))))
59 (format "/icloud/Archives/%s" year)))))
60
61 (setq
62 mu4e-headers-draft-mark '("D" . "💈")
63 mu4e-headers-flagged-mark '("F" . "📍")
64 mu4e-headers-new-mark '("N" . "🔥")
65 mu4e-headers-passed-mark '("P" . "❯")
66 mu4e-headers-replied-mark '("R" . "❮")
67 mu4e-headers-seen-mark '("S" . "☑")
68 mu4e-headers-trashed-mark '("T" . "💀")
69 mu4e-headers-attach-mark '("a" . "📎")
70 mu4e-headers-encrypted-mark '("x" . "🔒")
71 mu4e-headers-signed-mark '("s" . "🔑")
72 mu4e-headers-unread-mark '("u" . "⎕")
73 mu4e-headers-list-mark '("l" . "🔈")
74 mu4e-headers-personal-mark '("p" . "👨")
75 mu4e-headers-calendar-mark '("c" . "📅"))
76
77 (setopt mu4e-completing-read-function completing-read-function)
78 (setq mu4e-refile-folder 'vde-mu4e--refile)
79 (setq mu4e-contexts `( ,(make-mu4e-context
80 :name "icloud"
81 :match-func (lambda (msg) (when msg
82 (string-prefix-p "/icloud" (mu4e-message-field msg :maildir))))
83 :vars '(
84 (user-mail-address . "vincent@demeester.fr")
85 (mu4e-trash-folder . "/icloud/Deleted Messages")
86 (mu4e-sent-folder . "/icloud/Sent Messages")
87 (mu4e-draft-folder . "/icloud/Drafts")
88 ;; (mu4e-get-mail-command . "mbsync icloud")
89 ))
90 ,(make-mu4e-context
91 :name "gmail"
92 :match-func (lambda (msg) (when msg
93 (string-prefix-p "/gmail" (mu4e-message-field msg :maildir))))
94 :vars '(
95 (user-mail-address . "vinc.demeester@gmail.com")
96 (mu4e-drafts-folder . "/gmail/[Gmail]/Drafts")
97 (mu4e-sent-folder . "/gmail/[Gmail]/Sent Mail")
98 ;; (mu4e-refile-folder . "/gmail/[Gmail]/All Mail")
99 (mu4e-trash-folder . "/gmail/[Gmail]/Trash")
100 ;; (mu4e-get-mail-command . "mbsync gmail")
101 ))
102 ,(make-mu4e-context
103 :name "redhat"
104 :match-func (lambda (msg) (when msg
105 (string-prefix-p "/redhat" (mu4e-message-field msg :maildir))))
106 :vars '(
107 (user-mail-address . "vdemeest@redhat.com")
108 (mu4e-drafts-folder . "/redhat/[Gmail]/Drafts")
109 (mu4e-sent-folder . "/redhat/[Gmail]/Sent Mail")
110 ;; (mu4e-refile-folder . "/redhat/[Gmail]/All Mail")
111 (mu4e-trash-folder . "/redhat/[Gmail]/Trash")
112 ;; (mu4e-get-mail-command . "mbsync redhat")
113 ))
114 ))
115 (add-to-list 'mu4e-bookmarks
116 '( :name "All Inboxes"
117 :query "maildir:/icloud/INBOX OR maildir:/gmail/INBOX OR maildir:/redhat/INBOX"
118 :key ?b))
119 (with-eval-after-load "mm-decode"
120 (add-to-list 'mm-discouraged-alternatives "text/html")
121 (add-to-list 'mm-discouraged-alternatives "text/richtext")))
122
123(setq sendmail-program "msmtp"
124 send-mail-function 'smtpmail-send-it
125 message-sendmail-f-is-evil t
126 message-sendmail-extra-arguments '("--read-envelope-from")
127 message-send-mail-function 'message-send-mail-with-sendmail)
128
129(use-package consult-mu
130 :after mu4e
131 :custom
132 ;;maximum number of results shown in minibuffer
133 (consult-mu-maxnum 200)
134 ;;show preview when pressing any keys
135 (consult-mu-preview-key 'any)
136 ;;do not mark email as read when previewed. If you turn this to t, be aware that the auto-loaded preview if the preview-key above is 'any would also get marked as read!
137 (consult-mu-mark-previewed-as-read nil)
138 ;;mark email as read when selected.
139 (consult-mu-mark-viewed-as-read t)
140 ;;use reply to all when composing reply emails
141 (consult-mu-use-wide-reply t)
142 ;; define a template for headers view in minibuffer. The example below adjusts the width based on the width of the screen.
143 (consult-mu-headers-template (lambda () (concat "%f" (number-to-string (floor (* (frame-width) 0.15))) "%s" (number-to-string (floor (* (frame-width) 0.5))) "%d13" "%g" "%x")))
144
145 :config
146 ;;create a list of saved searches for quick access using `histroy-next-element' with `M-n' in minibuffer. Note the "#" character at the beginning of each query! Change these according to
147 (setq consult-mu-saved-searches-dynamics '("#flag:unread"))
148 (setq consult-mu-saved-searches-async '("#flag:unread"))
149 ;; require embark actions for marking, replying, forwarding, etc. directly from minibuffer
150 (require 'consult-mu-embark)
151 ;; require extra module for composing (e.g. for interactive attachment) as well as embark actions
152 (require 'consult-mu-compose)
153 (require 'consult-mu-compose-embark)
154 ;; require extra module for searching contacts and runing embark actions on contacts
155 (require 'consult-mu-contacts)
156 (require 'consult-mu-contacts-embark)
157 ;; change the prefiew key for compose so you don't open a preview of every file when selecting files to attach
158 (setq consult-mu-compose-preview-key "M-o")
159 ;; pick a key to bind to consult-mu-compose-attach in embark-file-map
160 (setq consult-mu-embark-attach-file-key "C-a")
161 (setq consult-mu-contacts-ignore-list '("^.*no.*reply.*"))
162 (setq consult-mu-contacts-ignore-case-fold-search t)
163 (consult-mu-compose-embark-bind-attach-file-key)
164 ;; choose if you want to use dired for attaching files (choice of 'always, 'in-dired, or nil)
165 (setq consult-mu-compose-use-dired-attachment 'in-dired))
166
167(provide 'config-mu4e)
168;;; config-mu4e.el ends here