nftable-migration
  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     ;; FIXME
 51     ((string= (plist-get (car-safe (mu4e-message-field msg :cc)) :email) "ci_activity@noreply.github.com")
 52      "/icloud/Deleted Messages")
 53     (t
 54      (let ((year (format-time-string "%Y" (mu4e-message-field msg :date))))
 55	(format "/icloud/Archives/%s" year)))))
 56
 57  (setq
 58   mu4e-headers-draft-mark     '("D" . "💈")
 59   mu4e-headers-flagged-mark   '("F" . "📍")
 60   mu4e-headers-new-mark       '("N" . "🔥")
 61   mu4e-headers-passed-mark    '("P" . "")
 62   mu4e-headers-replied-mark   '("R" . "")
 63   mu4e-headers-seen-mark      '("S" . "")
 64   mu4e-headers-trashed-mark   '("T" . "💀")
 65   mu4e-headers-attach-mark    '("a" . "📎")
 66   mu4e-headers-encrypted-mark '("x" . "🔒")
 67   mu4e-headers-signed-mark    '("s" . "🔑")
 68   mu4e-headers-unread-mark    '("u" . "")
 69   mu4e-headers-list-mark      '("l" . "🔈")
 70   mu4e-headers-personal-mark  '("p" . "👨")
 71   mu4e-headers-calendar-mark  '("c" . "📅"))
 72
 73  (setopt mu4e-completing-read-function completing-read-function)
 74  (setq mu4e-refile-folder 'vde-mu4e--refile)
 75  (setq mu4e-contexts `( ,(make-mu4e-context
 76			   :name "icloud"
 77			   :match-func (lambda (msg) (when msg
 78						       (string-prefix-p "/icloud" (mu4e-message-field msg :maildir))))
 79			   :vars '(
 80				   (user-mail-address . "vincent@demeester.fr")
 81				   (mu4e-trash-folder . "/icloud/Deleted Messages")
 82				   (mu4e-sent-folder . "/icloud/Sent Messages")
 83				   (mu4e-draft-folder . "/icloud/Drafts")
 84				   ;; (mu4e-get-mail-command . "mbsync icloud")
 85				   ))
 86			 ,(make-mu4e-context
 87			   :name "gmail"
 88			   :match-func (lambda (msg) (when msg
 89						       (string-prefix-p "/gmail" (mu4e-message-field msg :maildir))))
 90			   :vars '(
 91				   (user-mail-address . "vinc.demeester@gmail.com")
 92				   (mu4e-drafts-folder  . "/gmail/[Gmail]/Drafts")
 93				   (mu4e-sent-folder  . "/gmail/[Gmail]/Sent Mail")
 94				   ;; (mu4e-refile-folder  . "/gmail/[Gmail]/All Mail")
 95				   (mu4e-trash-folder  . "/gmail/[Gmail]/Trash")
 96				   ;; (mu4e-get-mail-command . "mbsync gmail")
 97				   ))
 98			 ,(make-mu4e-context
 99			   :name "redhat"
100			   :match-func (lambda (msg) (when msg
101						       (string-prefix-p "/redhat" (mu4e-message-field msg :maildir))))
102			   :vars '(
103				   (user-mail-address . "vdemeest@redhat.com")
104				   (mu4e-drafts-folder  . "/redhat/[Gmail]/Drafts")
105				   (mu4e-sent-folder  . "/redhat/[Gmail]/Sent Mail")
106				   ;; (mu4e-refile-folder  . "/redhat/[Gmail]/All Mail")
107				   (mu4e-trash-folder  . "/redhat/[Gmail]/Trash")
108				   ;; (mu4e-get-mail-command . "mbsync redhat")
109				   ))
110			 ))
111  (add-to-list 'mu4e-bookmarks
112	       '( :name  "All Inboxes"
113		  :query "maildir:/icloud/INBOX OR maildir:/gmail/INBOX OR maildir:/redhat/INBOX"
114		  :key   ?b))
115  (with-eval-after-load "mm-decode"
116    (add-to-list 'mm-discouraged-alternatives "text/html")
117    (add-to-list 'mm-discouraged-alternatives "text/richtext")))
118
119(setq sendmail-program "msmtp"
120      send-mail-function 'smtpmail-send-it
121      message-sendmail-f-is-evil t
122      message-sendmail-extra-arguments '("--read-envelope-from")
123      message-send-mail-function 'message-send-mail-with-sendmail)
124
125(use-package consult-mu
126  :after mu4e
127  :custom
128  ;;maximum number of results shown in minibuffer
129  (consult-mu-maxnum 200)
130  ;;show preview when pressing any keys
131  (consult-mu-preview-key 'any)
132  ;;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!
133  (consult-mu-mark-previewed-as-read nil)
134  ;;mark email as read when selected.
135  (consult-mu-mark-viewed-as-read t)
136  ;;use reply to all when composing reply emails
137  (consult-mu-use-wide-reply t)
138  ;; define a template for headers view in minibuffer. The example below adjusts the width based on the width of the screen.
139  (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")))
140
141  :config
142  ;;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
143  (setq consult-mu-saved-searches-dynamics '("#flag:unread"))
144  (setq consult-mu-saved-searches-async '("#flag:unread"))
145  ;; require embark actions for marking, replying, forwarding, etc. directly from minibuffer
146  (require 'consult-mu-embark)
147  ;; require extra module for composing (e.g. for interactive attachment) as well as embark actions
148  (require 'consult-mu-compose)
149  (require 'consult-mu-compose-embark)
150  ;; require extra module for searching contacts and runing embark actions on contacts
151  (require 'consult-mu-contacts)
152  (require 'consult-mu-contacts-embark)
153  ;; change the prefiew key for compose so you don't open a preview of every file when selecting files to attach
154  (setq consult-mu-compose-preview-key "M-o")
155  ;; pick a key to bind to consult-mu-compose-attach in embark-file-map
156  (setq consult-mu-embark-attach-file-key "C-a")
157  (setq consult-mu-contacts-ignore-list '("^.*no.*reply.*"))
158  (setq consult-mu-contacts-ignore-case-fold-search t)
159  (consult-mu-compose-embark-bind-attach-file-key)
160  ;; choose if you want to use dired for attaching files (choice of 'always, 'in-dired, or nil)
161  (setq consult-mu-compose-use-dired-attachment 'in-dired))
162
163(provide 'config-mu4e)
164;;; config-mu4e.el ends here