email: start mu4e in background

Instead of autoloading one function...
This commit is contained in:
Max Schlueter 2024-04-12 10:44:53 +02:00
parent 655b40956b
commit 1de6abe136

230
email.el
View File

@ -1,127 +1,130 @@
;;; email.el -*- lexical-binding: t; -*- ;;; email.el -*- lexical-binding: t; -*-
(after! mu4e ;; Start mu4e in the background
;; Recommended msmtp config from doom module documentation ;; https://github.com/djcb/mu/issues/2282
(setq sendmail-program (executable-find "msmtp") (require 'mu4e)
send-mail-function #'smtpmail-send-it (mu4e 'background)
message-sendmail-f-is-evil t
message-sendmail-extra-arguments '("--read-envelope-from")
message-send-mail-function #'message-send-mail-with-sendmail)
;; `set-email-account!' doesn't accept a custom match-func ;; Recommended msmtp config from doom module documentation
(setq mu4e-contexts (setq sendmail-program (executable-find "msmtp")
(list send-mail-function #'smtpmail-send-it
;; (make-mu4e-context message-sendmail-f-is-evil t
;; :name "upcycling" message-sendmail-extra-arguments '("--read-envelope-from")
;; :enter-func message-send-mail-function #'message-send-mail-with-sendmail)
;; (lambda () (mu4e-message "Switched to upcycling"))
;; :leave-func
;; (lambda () (progn (setq +mu4e-personal-addresses nil)
;; (mu4e-clear-caches)))
;; :match-func
;; (lambda (msg)
;; (when msg
;; (mu4e-message-contact-field-matches msg
;; :to "upcycling@fsfe.org")))
;; :vars '((user-mail-address . "upcycling@fsfe.org")
;; (user-full-name . "FSFE Team Upcycling Android")))
(make-mu4e-context
:name "mailbox"
:enter-func
(lambda () (mu4e-message "Switched to mailbox"))
:leave-func
(lambda () (progn (setq +mu4e-personal-addresses nil)
(mu4e-clear-caches)))
:match-func
(lambda (msg)
(when msg
(string-prefix-p "/mailbox"
(mu4e-message-field msg :maildir) t)))
:vars '((user-mail-address . "me@maxschlueter.com")
(user-full-name . "Max Schlueter")
(+mu4e-personal-addresses ("me@maxschlueter.com")
("maxsc@fsfe.org"))
))))
(setq mu4e-attachment-dir "~/Downloads" ;; `set-email-account!' doesn't accept a custom match-func
mu4e-sent-folder "/mailbox/Sent" (setq mu4e-contexts
mu4e-drafts-folder "/mailbox/Drafts" (list
mu4e-trash-folder "/mailbox/Trash" ;; (make-mu4e-context
mu4e-refile-folder "/mailbox/Archive" ;; :name "upcycling"
;; TODO create context-aware variable ;; :enter-func
mu4e-spam-folder "/mailbox/Junk" ;; (lambda () (mu4e-message "Switched to upcycling"))
mu4e-compose-signature nil ;; :leave-func
mu4e-maildir-shortcuts (list (list :maildir "/mailbox/Inbox" ;; (lambda () (progn (setq +mu4e-personal-addresses nil)
:key ?i) ;; (mu4e-clear-caches)))
(list :maildir "/mailbox/Sent" ;; :match-func
:key ?s) ;; (lambda (msg)
(list :maildir "/mailbox/Drafts" ;; (when msg
:key ?d) ;; (mu4e-message-contact-field-matches msg
(list :maildir "/mailbox/Trash" ;; :to "upcycling@fsfe.org")))
:key ?t) ;; :vars '((user-mail-address . "upcycling@fsfe.org")
(list :maildir "/mailbox/Archive" ;; (user-full-name . "FSFE Team Upcycling Android")))
:key ?a)) (make-mu4e-context
mu4e-bookmarks (list (list :name "All Inboxes" :name "mailbox"
:query "maildir:/mailbox/Inbox" :enter-func
:key ?i) (lambda () (mu4e-message "Switched to mailbox"))
(list :name "Unread messages" :leave-func
:query "flag:unread AND NOT flag:trashed" (lambda () (progn (setq +mu4e-personal-addresses nil)
:key ?u) (mu4e-clear-caches)))
(list :name "Today's messages" :match-func
:query "date:today..now" (lambda (msg)
:key ?t) (when msg
(list :name "Last 7 days" (string-prefix-p "/mailbox"
:query "date:7d..now" (mu4e-message-field msg :maildir) t)))
:hide-unread t :vars '((user-mail-address . "me@maxschlueter.com")
:key ?t))) (user-full-name . "Max Schlueter")
(+mu4e-personal-addresses ("me@maxschlueter.com")
("maxsc@fsfe.org"))
))))
;; Render buttons to verify&decrypt messages (setq mu4e-attachment-dir "~/Downloads"
(setq mm-decrypt-option 'always mu4e-sent-folder "/mailbox/Sent"
mm-verify-option 'always mu4e-drafts-folder "/mailbox/Drafts"
gnus-buttonized-mime-types '("multipart/encrypted" "multipart/signed") mu4e-trash-folder "/mailbox/Trash"
mml-secure-openpgp-encrypt-to-self t) mu4e-refile-folder "/mailbox/Archive"
;; TODO create context-aware variable
mu4e-spam-folder "/mailbox/Junk"
mu4e-compose-signature nil
mu4e-maildir-shortcuts (list (list :maildir "/mailbox/Inbox"
:key ?i)
(list :maildir "/mailbox/Sent"
:key ?s)
(list :maildir "/mailbox/Drafts"
:key ?d)
(list :maildir "/mailbox/Trash"
:key ?t)
(list :maildir "/mailbox/Archive"
:key ?a))
mu4e-bookmarks (list (list :name "All Inboxes"
:query "maildir:/mailbox/Inbox"
:key ?i)
(list :name "Unread messages"
:query "flag:unread AND NOT flag:trashed"
:key ?u)
(list :name "Today's messages"
:query "date:today..now"
:key ?t)
(list :name "Last 7 days"
:query "date:7d..now"
:hide-unread t
:key ?t)))
;; Move message to the trash folder but do not set the trash flag ;; Render buttons to verify&decrypt messages
;; https://github.com/djcb/mu/issues/1136#issuecomment-1066303788 (setq mm-decrypt-option 'always
(setf (alist-get 'trash mu4e-marks) mm-verify-option 'always
(list :char '("d" . "") gnus-buttonized-mime-types '("multipart/encrypted" "multipart/signed")
:prompt "dtrash" mml-secure-openpgp-encrypt-to-self t)
:dyn-target (lambda (target msg)
(mu4e-get-trash-folder msg))
:action (lambda (docid msg target)
;; Here's the main difference to the regular trash mark,
;; no +T before -N so the message is not marked as
;; IMAP-deleted:
(mu4e--server-move docid (mu4e--mark-check-target target) "+S-u-N"))))
(add-to-list 'mu4e-marks ;; Move message to the trash folder but do not set the trash flag
'(spam ;; https://github.com/djcb/mu/issues/1136#issuecomment-1066303788
:char "S" (setf (alist-get 'trash mu4e-marks)
:prompt "Spam" (list :char '("d" . "")
:shot-target (lambda (target) mu4e-spam-folder) :prompt "dtrash"
:action (lambda (docid msg target) :dyn-target (lambda (target msg)
(mu4e--server-move docid mu4e-spam-folder "+S-u-N")))) (mu4e-get-trash-folder msg))
:action (lambda (docid msg target)
;; Here's the main difference to the regular trash mark,
;; no +T before -N so the message is not marked as
;; IMAP-deleted:
(mu4e--server-move docid (mu4e--mark-check-target target) "+S-u-N"))))
(defun my:mu4e-mark-for-spam() (add-to-list 'mu4e-marks
"Mark as read and move to spam." '(spam
(interactive) :char "S"
(mu4e-headers-mark-and-next 'spam)) :prompt "Spam"
:shot-target (lambda (target) mu4e-spam-folder)
:action (lambda (docid msg target)
(mu4e--server-move docid mu4e-spam-folder "+S-u-N"))))
(map! :map mu4e-headers-mode-map :n "S" #'my:mu4e-mark-for-spam) (defun my:mu4e-mark-for-spam()
"Mark as read and move to spam."
(interactive)
(mu4e-headers-mark-and-next 'spam))
(add-to-list 'mu4e-view-mime-part-actions (map! :map mu4e-headers-mode-map :n "S" #'my:mu4e-mark-for-spam)
'(:name "calendar"
:handler (lambda (file)
(shell-command
(format "khal import --batch %s" file))
(khalel-import-events))
:receives temp))
;; Sign sent email automatically (add-to-list 'mu4e-view-mime-part-actions
;; (add-hook 'message-send-hook 'mml-secure-message-sign-smime) '(:name "calendar"
:handler (lambda (file)
(shell-command
(format "khal import --batch %s" file))
(khalel-import-events))
:receives temp))
(require 'khalel-icalendar) ;; Sign sent email automatically
) ;; (add-hook 'message-send-hook 'mml-secure-message-sign-smime)
(require 'khalel-icalendar)
;; (defun max/mu4e-view-import-attachment-calendar (msg attnum) ;; (defun max/mu4e-view-import-attachment-calendar (msg attnum)
;; (let* ((att (mu4e~view-get-attach msg attnum)) ;; (let* ((att (mu4e~view-get-attach msg attnum))
@ -139,9 +142,6 @@
;; (add-to-list 'mu4e-view-attachment-actions ;; (add-to-list 'mu4e-view-attachment-actions
;; '("cImport in calendar" . max/mu4e-view-import-attachment-calendar) t) ;; '("cImport in calendar" . max/mu4e-view-import-attachment-calendar) t)
;; Autoload this command so that the mbsync service can update the index
(autoload #'mu4e-update-index "mu4e" nil t)
(defun max/=mu4e () (defun max/=mu4e ()
"Start email client and view all inboxes." "Start email client and view all inboxes."
(interactive) (interactive)