Get the mail system working again.

Wrapping code in `use-package` expressions instead of `noweb`
references, allows me to execute sections, resulting in
easier-to-maintain code.
This commit is contained in:
Howard Abrams 2024-09-28 08:35:56 -07:00
parent 71168110e0
commit ffe662ced0

View file

@ -97,7 +97,9 @@ Next, we need some basic configuration settings and some global keybindings:
:map notmuch-tree-mode-map
("C" . notmuch-mua-new-mail)))
#+end_src
And some leader-based keybindings:
#+begin_src emacs-lisp :noweb yes
(use-package notmuch
:config
@ -105,19 +107,17 @@ And some leader-based keybindings:
"a n" '("new mail" . notmuch-retrieve-messages)
"a c" '("compose mail" . compose-mail))
(major-mode-hydra-define notmuch-hello-mode nil
(major-mode-hydra-define notmuch-hello-mode (:quit-key "q")
("Mail"
(("u" notmuch-retrieve-messages "new mail")
("m" notmuch "read mail"))
"Messages"
(("c" notmuch-mua-new-mail "compose")
("C" hey-notmuch-reply-later "reply-later"))))
<<hey-show-keybindings>>
<<hey-search-keybindings>>)
("C" hey-notmuch-reply-later "reply-later")))))
#+end_src
Also, let's do some basic configuration of Emacs' mail system:
#+begin_src emacs-lisp
(setq mm-text-html-renderer 'shr
mail-specify-envelope-from t
@ -138,6 +138,8 @@ Do I want to sign messages by default? Nope.
** Addresses
I need to incorporate an address book again, but in the meantime, searching through a history of past email works well enough.
#+begin_src emacs-lisp
(use-package notmuch
:config
(setq notmuch-address-selection-function
(lambda (prompt collection initial-input)
(completing-read prompt
@ -145,7 +147,7 @@ I need to incorporate an address book again, but in the meantime, searching thro
nil
t
nil
'notmuch-address-history)))
'notmuch-address-history))))
#+end_src
** Sending Messages
Do I need to set up [[https://marlam.de/msmtp/][MSMTP]]? No, as Notmuch will do that work.
@ -173,6 +175,7 @@ There are global settings:
The following section is for my /personal/ (not too general) account.
The file generally can have a =Pass= entry for the encrypted passcode, but to show how to connect to more than one accounts, I'm using a GPG daemon:
#+begin_src conf :tangle ~/.mbsyncrc :noweb yes
# PERSONAL ACCOUNT
IMAPAccount personal
@ -439,7 +442,9 @@ To allow me to keep Vedang's and my code side-by-side in the same Emacs variable
A list of pre-defined searches act like "Folder buttons" at the top to quickly see files that match those /buckets/:
#+begin_src emacs-lisp
(setq notmuch-saved-searches '((:name "Imbox"
(use-package notmuch
:config
(setq notmuch-saved-searches '((:name "Imbox"
:query "tag:inbox AND tag:screened AND tag:unread"
:key "i"
:search-type 'tree)
@ -470,35 +475,35 @@ A list of pre-defined searches act like "Folder buttons" at the top to quickly s
;; notmuch-saved-searches)
(:name "Old Projects"
:query "tag:old-project AND NOT tag:unread"
:key "X")))
:key "X"))))
#+end_src
** Helper Functions
With good bucket definitions, we should be able to scan the mail quickly and deal with the entire lot of them:
#+begin_src emacs-lisp
(defun hey-notmuch-archive-all ()
(defun hey-notmuch-archive-all ()
"Archive all the emails in the current view."
(interactive)
(notmuch-search-archive-thread nil (point-min) (point-max)))
(defun hey-notmuch-delete-all ()
(defun hey-notmuch-delete-all ()
"Archive all the emails in the current view.
Mark them for deletion by cron job."
Mark them for deletion by cron job."
(interactive)
(notmuch-search-tag-all '("+deleted"))
(hey-notmuch-archive-all))
(defun hey-notmuch-search-delete-and-archive-thread ()
(defun hey-notmuch-search-delete-and-archive-thread ()
"Archive the currently selected thread. Add the deleted tag as well."
(interactive)
(notmuch-search-add-tag '("+deleted"))
(notmuch-search-archive-thread))
(defun hey-notmuch-tag-and-archive (tag-changes &optional beg end)
(defun hey-notmuch-tag-and-archive (tag-changes &optional beg end)
"Prompt the user for TAG-CHANGES.
Apply the TAG-CHANGES to region and also archive all the emails.
When called directly, BEG and END provide the region."
Apply the TAG-CHANGES to region and also archive all the emails.
When called directly, BEG and END provide the region."
(interactive (notmuch-search-interactive-tag-changes))
(notmuch-search-tag tag-changes beg end)
(notmuch-search-archive-thread nil beg end))
@ -637,20 +642,24 @@ This means:
** Bucket Keybindings
A series of keybindings to quickly send messages to one of the pre-defined buckets.
#+name: hey-show-keybindings
#+begin_src emacs-lisp :tangle no
(major-mode-hydra-define notmuch-show-mode nil
#+begin_src emacs-lisp
(use-package notmuch
:config
(major-mode-hydra-define notmuch-show-mode (:quit-key "q")
("Messages"
(("c" notmuch-mua-new-mail "compose")
("C" hey-notmuch-reply-later "reply-later"))))
(define-key notmuch-show-mode-map (kbd "C") 'hey-notmuch-reply-later)
(define-key notmuch-show-mode-map (kbd "C") 'hey-notmuch-reply-later))
#+end_src
The bindings in =notmuch-search-mode= are available when looking at a list of messages:
#+name: hey-search-keybindings
#+begin_src emacs-lisp :tangle no
(major-mode-hydra-define notmuch-search-mode nil
#+begin_src emacs-lisp
(use-package notmuch
:config
(major-mode-hydra-define notmuch-search-mode (:color blue :title "Notmuch")
("Mail"
(("r" notmuch-search-reply-to-thread "reply")
("R" notmuch-search-reply-to-thread-sender "reply-all")
@ -667,7 +676,7 @@ The bindings in =notmuch-search-mode= are available when looking at a list of me
("p" hey-notmuch-move-sender-to-papertrail "send to papertrail")
("f" hey-notmuch-move-sender-to-thefeed "send to feed")
("C" hey-notmuch-reply-later "reply")
("c" notmuch-mua-new-mail) "compose")))
("c" notmuch-mua-new-mail "compose"))))
;; And if I can remember the keybindings...
(define-key notmuch-search-mode-map (kbd "r") 'notmuch-search-reply-to-thread)
@ -683,7 +692,7 @@ The bindings in =notmuch-search-mode= are available when looking at a list of me
(define-key notmuch-search-mode-map (kbd "I") 'hey-notmuch-move-sender-to-screened)
(define-key notmuch-search-mode-map (kbd "P") 'hey-notmuch-move-sender-to-papertrail)
(define-key notmuch-search-mode-map (kbd "f") 'hey-notmuch-move-sender-to-thefeed)
(define-key notmuch-search-mode-map (kbd "C") 'hey-notmuch-reply-later)
(define-key notmuch-search-mode-map (kbd "C") 'hey-notmuch-reply-later))
#+end_src
** Org Integration
The gods ordained that Mail and Org should dance together, so step one is composing mail with org: