email: refactoring

This commit is contained in:
Max Schlueter 2023-02-06 12:09:21 +01:00
parent b66a52630d
commit e6ceb1899e
2 changed files with 74 additions and 26 deletions

View File

@ -635,4 +635,4 @@ the inbox. Refile to any org-gtd incubate target (see manual)."
;; load personal modules
(load! "+mail")
(load! "email")

View File

@ -1,4 +1,4 @@
;;; +mail.el -*- lexical-binding: t; -*-
;;; email.el -*- lexical-binding: t; -*-
(after! mu4e
;; Recommended msmtp config from doom module documentation
@ -10,20 +10,21 @@
;; `set-email-account!' doesn't accept a custom match-func
(setq mu4e-contexts
(list (make-mu4e-context
:name "upcycling"
:enter-func
(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")))
(list
;; (make-mu4e-context
;; :name "upcycling"
;; :enter-func
;; (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
@ -78,16 +79,18 @@
gnus-buttonized-mime-types '("multipart/encrypted" "multipart/signed")
mml-secure-openpgp-encrypt-to-self t)
(add-to-list 'org-capture-templates `("m" "email" entry (file+headline ,(expand-file-name "newgtd/actionable.org" org-directory) "Actions")
"* NEXT Reply to [[mu4e:msgid:%:message-id][%:fromname - %:subject]] :email:\n%U\n"))
(defun max/mu4e-org-capture ()
"Invoke the email capture template for msg at point"
(interactive)
(org-capture nil "m"))
(map! :map mu4e-headers-mode-map
:vne "l" #'max/mu4e-org-capture)
;; Move message to the trash folder but do not set the trash flag
;; https://github.com/djcb/mu/issues/1136#issuecomment-1066303788
(setf (alist-get 'trash mu4e-marks)
(list :char '("d" . "")
:prompt "dtrash"
: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-view-mime-part-actions
'(:name "calendar"
@ -130,6 +133,13 @@
(map! "<f2>" #'max/=mu4e)
(after! epa
(setq epa-keyserver "keys.openpgp.org")
(map! :map epa-ks-search-mode-map
:n "f" #'epa-ks-mark-key-to-fetch
:n "i" #'epa-ks-inspect-key-to-fetch
:n "u" #'epa-ks-unmark-key-to-fetch
:n "x" #'epa-ks-do-key-to-fetch))
(use-package! jl-encrypt
:config
@ -138,3 +148,41 @@
(after! mu4e-alert
(when IS-MAC
(mu4e-alert-set-default-style 'notifier)))
;; Taken from http://pragmaticemacs.com/emacs/email-templates-in-mu4e-with-yasnippet/
(defun bjm/mu4e-get-names-for-yasnippet ()
"Return comma separated string of names for an email"
(interactive)
(let ((email-name "") str email-string email-list email-name2 tmpname)
(save-excursion
(goto-char (point-min))
;; first line in email could be some hidden line containing NO to field
(setq str (buffer-substring-no-properties (point-min) (point-max))))
;; take name from TO field - match series of names
(when (string-match "^To: \"?\\(.+\\)" str)
(setq email-string (match-string 1 str)))
;;split to list by comma
(setq email-list (split-string email-string " *, *"))
;;loop over emails
(dolist (tmpstr email-list)
;;get first word of email string
(setq tmpname (car (split-string tmpstr " ")))
;;remove whitespace or ""
(setq tmpname (replace-regexp-in-string "[ \"]" "" tmpname))
;;join to string
(setq email-name
(concat email-name ", " tmpname)))
;;remove initial comma
(setq email-name (replace-regexp-in-string "^, " "" email-name))
;;see if we want to use the name in the FROM field
;;get name in FROM field if available, but only if there is only
;;one name in TO field
(if (< (length email-list) 2)
(when (string-match "^\\([^ ,\n]+\\).+writes:$" str)
(progn (setq email-name2 (match-string 1 str))
;;prefer name in FROM field if TO field has "@"
(when (string-match "@" email-name)
(setq email-name email-name2))
)))
email-name))