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:
		
							parent
							
								
									71168110e0
								
							
						
					
					
						commit
						ffe662ced0
					
				
					 1 changed files with 115 additions and 106 deletions
				
			
		
							
								
								
									
										221
									
								
								ha-email.org
									
									
									
									
									
								
							
							
						
						
									
										221
									
								
								ha-email.org
									
									
									
									
									
								
							|  | @ -97,7 +97,9 @@ Next, we need some basic configuration settings and some global keybindings: | ||||||
|            :map notmuch-tree-mode-map |            :map notmuch-tree-mode-map | ||||||
|                 ("C" . notmuch-mua-new-mail))) |                 ("C" . notmuch-mua-new-mail))) | ||||||
| #+end_src | #+end_src | ||||||
|  | 
 | ||||||
| And some leader-based keybindings: | And some leader-based keybindings: | ||||||
|  | 
 | ||||||
| #+begin_src emacs-lisp :noweb yes | #+begin_src emacs-lisp :noweb yes | ||||||
|   (use-package notmuch |   (use-package notmuch | ||||||
|     :config |     :config | ||||||
|  | @ -105,19 +107,17 @@ And some leader-based keybindings: | ||||||
|       "a n" '("new mail" . notmuch-retrieve-messages) |       "a n" '("new mail" . notmuch-retrieve-messages) | ||||||
|       "a c" '("compose mail" . compose-mail)) |       "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" |       ("Mail" | ||||||
|        (("u" notmuch-retrieve-messages "new mail") |        (("u" notmuch-retrieve-messages "new mail") | ||||||
|         ("m" notmuch "read mail")) |         ("m" notmuch "read mail")) | ||||||
|        "Messages" |        "Messages" | ||||||
|        (("c" notmuch-mua-new-mail "compose") |        (("c" notmuch-mua-new-mail "compose") | ||||||
|         ("C" hey-notmuch-reply-later "reply-later")))) |         ("C" hey-notmuch-reply-later "reply-later"))))) | ||||||
| 
 |  | ||||||
|     <<hey-show-keybindings>> |  | ||||||
|     <<hey-search-keybindings>>) |  | ||||||
| 
 |  | ||||||
| #+end_src | #+end_src | ||||||
|  | 
 | ||||||
| Also, let's do some basic configuration of Emacs' mail system: | Also, let's do some basic configuration of Emacs' mail system: | ||||||
|  | 
 | ||||||
| #+begin_src emacs-lisp | #+begin_src emacs-lisp | ||||||
|   (setq mm-text-html-renderer 'shr |   (setq mm-text-html-renderer 'shr | ||||||
|         mail-specify-envelope-from t |         mail-specify-envelope-from t | ||||||
|  | @ -138,14 +138,16 @@ Do I want to sign messages by default? Nope. | ||||||
| ** Addresses | ** Addresses | ||||||
| I need to incorporate an address book again, but in the meantime, searching through a history of past email works well enough. | 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 | #+begin_src emacs-lisp | ||||||
|   (setq notmuch-address-selection-function |   (use-package notmuch | ||||||
|         (lambda (prompt collection initial-input) |     :config | ||||||
|           (completing-read prompt |     (setq notmuch-address-selection-function | ||||||
|                            (cons initial-input collection) |           (lambda (prompt collection initial-input) | ||||||
|                            nil |             (completing-read prompt | ||||||
|                            t |                              (cons initial-input collection) | ||||||
|                            nil |                              nil | ||||||
|                            'notmuch-address-history))) |                              t | ||||||
|  |                              nil | ||||||
|  |                              'notmuch-address-history)))) | ||||||
| #+end_src | #+end_src | ||||||
| ** Sending Messages | ** Sending Messages | ||||||
| Do I need to set up [[https://marlam.de/msmtp/][MSMTP]]? No, as Notmuch will do that work. | 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 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: | 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 | #+begin_src conf :tangle ~/.mbsyncrc :noweb yes | ||||||
|   # PERSONAL ACCOUNT |   # PERSONAL ACCOUNT | ||||||
|   IMAPAccount personal |   IMAPAccount personal | ||||||
|  | @ -439,69 +442,71 @@ 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/: | 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 | #+begin_src emacs-lisp | ||||||
| (setq notmuch-saved-searches '((:name "Imbox" |   (use-package notmuch | ||||||
|                                       :query "tag:inbox AND tag:screened AND tag:unread" |     :config | ||||||
|                                       :key "i" |     (setq notmuch-saved-searches '((:name "Imbox" | ||||||
|                                       :search-type 'tree) |                                           :query "tag:inbox AND tag:screened AND tag:unread" | ||||||
|                                (:name "Previously Seen" |                                           :key "i" | ||||||
|                                       :query "tag:screened AND NOT tag:unread" |                                           :search-type 'tree) | ||||||
|                                       :key "I") |                                    (:name "Previously Seen" | ||||||
|                                (:name "Unscreened" |                                           :query "tag:screened AND NOT tag:unread" | ||||||
|                                       :query "tag:inbox AND tag:unread AND NOT tag:screened AND NOT date:..14d AND NOT tag:thefeed AND NOT tag:/ledger/ AND NOT tag:old-project" |                                           :key "I") | ||||||
|                                       :key "s") |                                    (:name "Unscreened" | ||||||
|                                (:name "New Feed" |                                           :query "tag:inbox AND tag:unread AND NOT tag:screened AND NOT date:..14d AND NOT tag:thefeed AND NOT tag:/ledger/ AND NOT tag:old-project" | ||||||
|                                       :query "tag:thefeed AND tag:unread" |                                           :key "s") | ||||||
|                                       :key "f" |                                    (:name "New Feed" | ||||||
|                                       :search-type 'tree) |                                           :query "tag:thefeed AND tag:unread" | ||||||
|                                (:name "Old Feed" |                                           :key "f" | ||||||
|                                       :query "tag:thefeed" |                                           :search-type 'tree) | ||||||
|                                       :key "f" |                                    (:name "Old Feed" | ||||||
|                                       :search-type 'tree) |                                           :query "tag:thefeed" | ||||||
|                                (:name "New Receipts" |                                           :key "f" | ||||||
|                                       :query "tag:/ledger/ AND tag:unread" |                                           :search-type 'tree) | ||||||
|                                       :key "p") |                                    (:name "New Receipts" | ||||||
|                                (:name "Papertrail" |                                           :query "tag:/ledger/ AND tag:unread" | ||||||
|                                       :query "tag:/ledger/" |                                           :key "p") | ||||||
|                                       :key "P") |                                    (:name "Papertrail" | ||||||
|  |                                           :query "tag:/ledger/" | ||||||
|  |                                           :key "P") | ||||||
| 
 | 
 | ||||||
|                                ;; (push '(:name "Projects" |                                    ;; (push '(:name "Projects" | ||||||
|                                ;;               :query "tag:project AND NOT tag:unread" |                                    ;;               :query "tag:project AND NOT tag:unread" | ||||||
|                                ;;               :key "x") |                                    ;;               :key "x") | ||||||
|                                ;;       notmuch-saved-searches) |                                    ;;       notmuch-saved-searches) | ||||||
|                                (:name "Old Projects" |                                    (:name "Old Projects" | ||||||
|                                       :query "tag:old-project AND NOT tag:unread" |                                           :query "tag:old-project AND NOT tag:unread" | ||||||
|                                       :key "X"))) |                                           :key "X")))) | ||||||
| #+end_src | #+end_src | ||||||
| ** Helper Functions | ** Helper Functions | ||||||
| 
 | 
 | ||||||
| With good bucket definitions, we should be able to scan the mail quickly and deal with the entire lot of them: | 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 | #+begin_src emacs-lisp | ||||||
| (defun hey-notmuch-archive-all () |   (defun hey-notmuch-archive-all () | ||||||
|   "Archive all the emails in the current view." |     "Archive all the emails in the current view." | ||||||
|   (interactive) |     (interactive) | ||||||
|   (notmuch-search-archive-thread nil (point-min) (point-max))) |     (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. |     "Archive all the emails in the current view. | ||||||
| Mark them for deletion by cron job." |   Mark them for deletion by cron job." | ||||||
|   (interactive) |     (interactive) | ||||||
|   (notmuch-search-tag-all '("+deleted")) |     (notmuch-search-tag-all '("+deleted")) | ||||||
|   (hey-notmuch-archive-all)) |     (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." |     "Archive the currently selected thread. Add the deleted tag as well." | ||||||
|   (interactive) |     (interactive) | ||||||
|   (notmuch-search-add-tag '("+deleted")) |     (notmuch-search-add-tag '("+deleted")) | ||||||
|   (notmuch-search-archive-thread)) |     (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. |     "Prompt the user for TAG-CHANGES. | ||||||
| Apply the TAG-CHANGES to region and also archive all the emails. |   Apply the TAG-CHANGES to region and also archive all the emails. | ||||||
| When called directly, BEG and END provide the region." |   When called directly, BEG and END provide the region." | ||||||
|   (interactive (notmuch-search-interactive-tag-changes)) |     (interactive (notmuch-search-interactive-tag-changes)) | ||||||
|   (notmuch-search-tag tag-changes beg end) |     (notmuch-search-tag tag-changes beg end) | ||||||
|   (notmuch-search-archive-thread nil beg end)) |     (notmuch-search-archive-thread nil beg end)) | ||||||
| #+end_src | #+end_src | ||||||
| 
 | 
 | ||||||
| A key point in organizing emails with the Hey model, is looking at the "from" address: | A key point in organizing emails with the Hey model, is looking at the "from" address: | ||||||
|  | @ -637,53 +642,57 @@ This means: | ||||||
| ** Bucket Keybindings | ** Bucket Keybindings | ||||||
| A series of keybindings to quickly send messages to one of the pre-defined buckets. | A series of keybindings to quickly send messages to one of the pre-defined buckets. | ||||||
| #+name: hey-show-keybindings | #+name: hey-show-keybindings | ||||||
| #+begin_src emacs-lisp :tangle no | #+begin_src emacs-lisp | ||||||
|   (major-mode-hydra-define notmuch-show-mode nil |   (use-package notmuch | ||||||
|     ("Messages" |     :config | ||||||
|      (("c" notmuch-mua-new-mail "compose") |     (major-mode-hydra-define notmuch-show-mode (:quit-key "q") | ||||||
|       ("C" hey-notmuch-reply-later "reply-later")))) |       ("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 | #+end_src | ||||||
| 
 | 
 | ||||||
| The bindings in =notmuch-search-mode= are available when looking at a list of messages: | The bindings in =notmuch-search-mode= are available when looking at a list of messages: | ||||||
| 
 | 
 | ||||||
| #+name: hey-search-keybindings | #+name: hey-search-keybindings | ||||||
| #+begin_src emacs-lisp :tangle no | #+begin_src emacs-lisp | ||||||
|   (major-mode-hydra-define notmuch-search-mode nil |   (use-package notmuch | ||||||
|     ("Mail" |     :config | ||||||
|      (("r" notmuch-search-reply-to-thread "reply") |     (major-mode-hydra-define notmuch-search-mode (:color blue :title "Notmuch") | ||||||
|       ("R" notmuch-search-reply-to-thread-sender "reply-all") |       ("Mail" | ||||||
|       ("A" hey-notmuch-archive-all "archive all") |        (("r" notmuch-search-reply-to-thread "reply") | ||||||
|       ("D" hey-notmuch-delete-all "delete all") |         ("R" notmuch-search-reply-to-thread-sender "reply-all") | ||||||
|       ("d" hey-notmuch-search-delete-and-archive-thread "delete thread")) |         ("A" hey-notmuch-archive-all "archive all") | ||||||
|      "Search" |         ("D" hey-notmuch-delete-all "delete all") | ||||||
|      (("/" notmuch-search-filter "search") |         ("d" hey-notmuch-search-delete-and-archive-thread "delete thread")) | ||||||
|       ("L" hey-notmuch-filter-by-from "filter by from") |        "Search" | ||||||
|       (";" hey-notmuch-search-by-from "search by from")) |        (("/" notmuch-search-filter "search") | ||||||
|      "Messages" |         ("L" hey-notmuch-filter-by-from "filter by from") | ||||||
|      (("s" hey-notmuch-move-sender-to-spam "send to spam") |         (";" hey-notmuch-search-by-from "search by from")) | ||||||
|       ("i" hey-notmuch-move-sender-to-screened "send to screened") |        "Messages" | ||||||
|       ("p" hey-notmuch-move-sender-to-papertrail "send to papertrail") |        (("s" hey-notmuch-move-sender-to-spam "send to spam") | ||||||
|       ("f" hey-notmuch-move-sender-to-thefeed "send to feed") |         ("i" hey-notmuch-move-sender-to-screened "send to screened") | ||||||
|       ("C" hey-notmuch-reply-later "reply") |         ("p" hey-notmuch-move-sender-to-papertrail "send to papertrail") | ||||||
|       ("c" notmuch-mua-new-mail) "compose"))) |         ("f" hey-notmuch-move-sender-to-thefeed "send to feed") | ||||||
|  |         ("C" hey-notmuch-reply-later "reply") | ||||||
|  |         ("c" notmuch-mua-new-mail "compose")))) | ||||||
| 
 | 
 | ||||||
|   ;; And if I can remember the keybindings... |     ;; And if I can remember the keybindings... | ||||||
|   (define-key notmuch-search-mode-map (kbd "r") 'notmuch-search-reply-to-thread) |     (define-key notmuch-search-mode-map (kbd "r") 'notmuch-search-reply-to-thread) | ||||||
|   (define-key notmuch-search-mode-map (kbd "R") 'notmuch-search-reply-to-thread-sender) |     (define-key notmuch-search-mode-map (kbd "R") 'notmuch-search-reply-to-thread-sender) | ||||||
|   (define-key notmuch-search-mode-map (kbd "/") 'notmuch-search-filter) |     (define-key notmuch-search-mode-map (kbd "/") 'notmuch-search-filter) | ||||||
|   (define-key notmuch-search-mode-map (kbd "A") 'hey-notmuch-archive-all) |     (define-key notmuch-search-mode-map (kbd "A") 'hey-notmuch-archive-all) | ||||||
|   (define-key notmuch-search-mode-map (kbd "D") 'hey-notmuch-delete-all) |     (define-key notmuch-search-mode-map (kbd "D") 'hey-notmuch-delete-all) | ||||||
|   (define-key notmuch-search-mode-map (kbd "L") 'hey-notmuch-filter-by-from) |     (define-key notmuch-search-mode-map (kbd "L") 'hey-notmuch-filter-by-from) | ||||||
|   (define-key notmuch-search-mode-map (kbd ";") 'hey-notmuch-search-by-from) |     (define-key notmuch-search-mode-map (kbd ";") 'hey-notmuch-search-by-from) | ||||||
|   (define-key notmuch-search-mode-map (kbd "d") 'hey-notmuch-search-delete-and-archive-thread) |     (define-key notmuch-search-mode-map (kbd "d") 'hey-notmuch-search-delete-and-archive-thread) | ||||||
| 
 | 
 | ||||||
|   (define-key notmuch-search-mode-map (kbd "S") 'hey-notmuch-move-sender-to-spam) |     (define-key notmuch-search-mode-map (kbd "S") 'hey-notmuch-move-sender-to-spam) | ||||||
|   (define-key notmuch-search-mode-map (kbd "I") 'hey-notmuch-move-sender-to-screened) |     (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 "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 "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 | #+end_src | ||||||
| ** Org Integration | ** Org Integration | ||||||
| The gods ordained that Mail and Org should dance together, so step one is composing mail with org: | The gods ordained that Mail and Org should dance together, so step one is composing mail with org: | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue