Send email without invoking notmuch's backend

Discovered a bug with `use-package` where :config sections are not
called if there is a :bind section.
This commit is contained in:
Howard Abrams 2022-09-23 21:59:33 -07:00
parent 334c3f9cff
commit 13b930e6ee

View file

@ -40,12 +40,12 @@ The configuration files below expect email addresses (I store passwords and othe
#+NAME: email-address-1 #+NAME: email-address-1
#+begin_src emacs-lisp :exports none :tangle no :results silent #+begin_src emacs-lisp :exports none :tangle no :results silent
(rot13-string "ubjneq.noenzf@tznvy.pbz") (rot13-string "ubjneq@ubjneqnoenzf.pbz")
#+end_src #+end_src
#+NAME: email-address-2 #+NAME: email-address-2
#+begin_src emacs-lisp :exports none :tangle no :results silent #+begin_src emacs-lisp :exports none :tangle no :results silent
(rot13-string "ubjneq@ubjneqnoenzf.pbz") (rot13-string "ubjneq.noenzf@tznvy.pbz")
#+end_src #+end_src
#+NAME: email-address-3 #+NAME: email-address-3
@ -53,29 +53,28 @@ The configuration files below expect email addresses (I store passwords and othe
(rot13-string "ubjneq@shmmlgbnfg.pbz") (rot13-string "ubjneq@shmmlgbnfg.pbz")
#+end_src #+end_src
To use these, we set the =:noweb yes= (to pull in the /name/ of the code block) but put a pair of parens after the name to have it evaluated. For instance: To use these, we set the =:noweb yes= (to pull in the /name/ of the code block) but put a pair of parens after the name to have it evaluated. For instance, the configuration for sending mail through the MUA in Emacs:
#+begin_example #+begin_src emacs-lisp :noweb yes
,#+begin_src conf :noweb yes :tangle /tmp/foobar.txt :results silent (setq send-mail-function 'smtpmail-send-it
some-address: <<email-address-2()>> message-send-mail-function 'smtpmail-send-it
,#+end_src smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil))
#+end_example smtpmail-auth-credentials `(("smtp.gmail.com" 587 ,<<email-address-1>> nil))
smtpmail-default-smtp-server "smtp.gmail.com"
smtpmail-smtp-server "smtp.gmail.com"
smtpmail-smtp-service 587)
#+end_src
* Installation and Basic Configuration * Installation and Basic Configuration
To begin, we need the code. On Ubuntu, this is: To begin, we need the code. On Ubuntu, this is:
#+begin_src shell :tangle no #+begin_src shell :tangle no
sudo apt install -y notmuch sudo apt install -y notmuch
#+end_src #+end_src
And on MacOS, we use =brew=: And on MacOS, we use =brew=:
#+begin_src shell :tangle no #+begin_src shell :tangle no
brew install notmuch brew install notmuch
#+end_src #+end_src
Next, we need some basic configuration settings and some global keybindings: Next, we need some basic configuration settings and some global keybindings:
#+begin_src emacs-lisp :noweb yes #+begin_src emacs-lisp :noweb yes
(use-package notmuch (use-package notmuch
:init :init
@ -92,22 +91,27 @@ Next, we need some basic configuration settings and some global keybindings:
notmuch-show-indent-content nil) notmuch-show-indent-content nil)
:bind (:map notmuch-hello-mode-map :bind (:map notmuch-hello-mode-map
("U" . notmuch-retrieve-messages) ; Defined later ("U" . notmuch-retrieve-messages)
("C" . notmuch-mua-new-mail) ("C" . notmuch-mua-new-mail)
:map notmuch-tree-mode-map :map notmuch-tree-mode-map
("C" . notmuch-mua-new-mail)) ("C" . notmuch-mua-new-mail))
:config (ha-leader ; Should I put these under an "m" heading?
"a n" '("new mail" . notmuch-retrieve-messages) :config
"a m" '("read mail" . notmuch) (ha-leader ; Should I put these under an "m" heading?
"a c" '("compose mail" . notmuch-mua-new-mail)) "a n" '("new mail" . notmuch-retrieve-messages)
<<local-leader-keybindings>> "a m" '("read mail" . notmuch)
(ha-mail-hello-leader "a c" '("compose mail" . compose-mail))
"u" '("new mail" . notmuch-retrieve-messages)
"m" '("read mail" . notmuch) <<local-leader-keybindings>>
"c" '("compose" . notmuch-mua-new-mail)
"C" '("reply-later" . hey-notmuch-reply-later)) (ha-mail-hello-leader
<<hey-show-keybindings>> "u" '("new mail" . notmuch-retrieve-messages)
<<hey-search-keybindings>>) "m" '("read mail" . notmuch)
"c" '("compose" . notmuch-mua-new-mail)
"C" '("reply-later" . hey-notmuch-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
@ -117,57 +121,65 @@ Also, let's do some basic configuration of Emacs' mail system:
message-send-mail-function 'message-send-mail-with-sendmail message-send-mail-function 'message-send-mail-with-sendmail
message-sendmail-envelope-from 'header) message-sendmail-envelope-from 'header)
#+end_src #+end_src
Create a special mail perspective:
#+begin_src emacs-lisp
(defun ha-email-persp-start ()
"Create an IRC workspace and start my IRC client."
(interactive)
(persp-switch "mail")
(notmuch))
(ha-leader "a M" '("mail persp" . ha-email-persp-start))
#+end_src
* Configuration * Configuration
Do I want to sign messages by default? Nope. Do I want to sign messages by default? Nope.
#+begin_src emacs-lisp :tangle no #+begin_src emacs-lisp :tangle no
(add-hook 'message-setup-hook 'mml-secure-sign-pgpmime) (add-hook 'message-setup-hook 'mml-secure-sign-pgpmime)
#+end_src #+end_src
** 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 (setq notmuch-address-selection-function
(lambda (prompt collection initial-input) (lambda (prompt collection initial-input)
(completing-read prompt (completing-read prompt
(cons initial-input collection) (cons initial-input collection)
nil nil
t t
nil nil
'notmuch-address-history))) '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.
To do this, type ~c~ and select an option (including ~r~ to reply). To do this, type ~c~ and select an option (including ~r~ to reply).
** Retrieving Messages ** Retrieving Messages
When we start notmuch, we need to retrieve the email and then process it. Most of this is actually contained in the Notmuch configuration. When we start notmuch, we need to retrieve the email and then process it. Most of this is actually contained in the Notmuch configuration.
#+begin_src emacs-lisp #+begin_src emacs-lisp
(defun notmuch-retrieve-messages () (defun notmuch-retrieve-messages ()
"Retrieve and process my mail messages." "Retrieve and process my mail messages."
(interactive) (interactive)
(async-shell-command "notmuch new")) (async-shell-command "notmuch new"))
#+end_src #+end_src
* iSync Configuration * iSync Configuration
Using [[https://isync.sourceforge.io/][isync]] (or is it =mbsync=) for mail retrieval. I have a couple of Google Mail accounts that I want connected. Using [[https://isync.sourceforge.io/][isync]] (or is it =mbsync=) for mail retrieval. I have a couple of Google Mail accounts that I want connected.
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: There are global settings:
#+begin_src conf :tangle ~/.mbsyncrc :noweb yes #+begin_src conf :tangle ~/.mbsyncrc :noweb yes
# Note: We now tangle this file from ~/other/hamacs/ha-email.org # Note: We now tangle this file from ~/other/hamacs/ha-email.org
Create Both Create Both
SyncState * SyncState *
MaxMessages 300 MaxMessages 100
Sync All # New ReNew Flags Sync All # New ReNew Flags
#+end_src
# PERSONAL 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:
#+begin_src conf :tangle ~/.mbsyncrc :noweb yes
# PERSONAL ACCOUNT
IMAPAccount personal IMAPAccount personal
Host imap.gmail.com Host imap.gmail.com
User <<email-address-2()>> # Substitute your own email address here User <<email-address-1()>> # Substitute your own email address here
PassCmd "gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.mailpass-personal.gpg" PassCmd "gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.mailpass-personal.gpg"
SSLType IMAPS SSLType IMAPS
AuthMechs LOGIN AuthMechs LOGIN
@ -197,11 +209,14 @@ The file generally can have a =Pass= entry for the encrypted passcode, but to sh
Master :personal-remote:"[Gmail]/Trash" Master :personal-remote:"[Gmail]/Trash"
Slave :personal-local:trash Slave :personal-local:trash
ExpireUnread yes ExpireUnread yes
#+end_src
# GMAIL ACCOUNT I have other email accounts that could use or ignore.
#+begin_src conf :tangle no
# GMAIL ACCOUNT
IMAPAccount gmail IMAPAccount gmail
Host imap.gmail.com Host imap.gmail.com
User <<email-address-1()>> # Substitute your own email address here User <<email-address-2()>> # Substitute your own email address here
PassCmd "gpg -q --for-your-eyes-only --pinentry-mode loopback -d ~/.mailpass-google.gpg" PassCmd "gpg -q --for-your-eyes-only --pinentry-mode loopback -d ~/.mailpass-google.gpg"
SSLType IMAPS SSLType IMAPS
AuthMechs LOGIN AuthMechs LOGIN
@ -261,10 +276,10 @@ Here is where you can let notmuch know how you address emails. Valid settings ar
Notmuch use the email addresses configured here when formatting replies. It will avoid including your own addresses in the recipient list of replies, and will set the From address based on the address in the original email. Notmuch use the email addresses configured here when formatting replies. It will avoid including your own addresses in the recipient list of replies, and will set the From address based on the address in the original email.
#+begin_src conf-unix :tangle ~/.notmuch-config :noweb yes #+begin_src conf-unix :tangle ~/.notmuch-config :noweb yes
[user] [user]
name=Howard Abrams name=Howard Abrams
primary_email=<<email-address-1()>> primary_email=<<email-address-1()>>
other_email=<<email-address-2()>>;<<email-address-3()>> other_email=<<email-address-2()>>;<<email-address-3()>>
#+end_src #+end_src
*NB:* In the configuration above, you may see the addresses are all set to =nil=. If you are copying this from a rendered web page, note that you need to substitute that with your own email address. *NB:* In the configuration above, you may see the addresses are all set to =nil=. If you are copying this from a rendered web page, note that you need to substitute that with your own email address.
*** Configuration for "notmuch new" *** Configuration for "notmuch new"
@ -274,9 +289,9 @@ Note the following supported options:
NOTE: *Every* file/directory that goes by one of those names will be ignored, independent of its depth/location in the mail store. NOTE: *Every* file/directory that goes by one of those names will be ignored, independent of its depth/location in the mail store.
#+begin_src conf-unix :tangle ~/.notmuch-config #+begin_src conf-unix :tangle ~/.notmuch-config
[new] [new]
tags=unread;inbox; tags=unread;inbox;
ignore= ignore=
#+end_src #+end_src
*** Search configuration *** Search configuration
The following option is supported here: The following option is supported here:
@ -284,8 +299,8 @@ The following option is supported here:
- =exclude_tags= :: A ;-separated list of tags that will be excluded from search results by default. Using an excluded tag in a query will override that exclusion. - =exclude_tags= :: A ;-separated list of tags that will be excluded from search results by default. Using an excluded tag in a query will override that exclusion.
#+begin_src conf-unix :tangle ~/.notmuch-config #+begin_src conf-unix :tangle ~/.notmuch-config
[search] [search]
exclude_tags=deleted;spam; exclude_tags=deleted;spam;
#+end_src #+end_src
*** Maildir compatibility configuration *** Maildir compatibility configuration
The following option is supported here: The following option is supported here:
@ -303,8 +318,8 @@ The following option is supported here:
The =notmuch new= command will notice flag changes in filenames and update tags, while the =notmuch tag= and =notmuch restore= commands will notice tag changes and update flags in filenames. The =notmuch new= command will notice flag changes in filenames and update tags, while the =notmuch tag= and =notmuch restore= commands will notice tag changes and update flags in filenames.
#+begin_src conf-unix :tangle ~/.notmuch-config #+begin_src conf-unix :tangle ~/.notmuch-config
[maildir] [maildir]
synchronize_flags=true synchronize_flags=true
#+end_src #+end_src
That should complete the Notmuch configuration. That should complete the Notmuch configuration.
@ -312,14 +327,14 @@ That should complete the Notmuch configuration.
Then we need a shell script called when beginning a retrieval, =pre-new= that simply calls =mbsync= to download all the messages: Then we need a shell script called when beginning a retrieval, =pre-new= that simply calls =mbsync= to download all the messages:
#+begin_src shell :tangle ~/.mail/.notmuch/hooks/pre-new :shebang "#!/bin/bash" #+begin_src shell :tangle ~/.mail/.notmuch/hooks/pre-new :shebang "#!/bin/bash"
# More info about hooks: https://notmuchmail.org/manpages/notmuch-hooks-5/ # More info about hooks: https://notmuchmail.org/manpages/notmuch-hooks-5/
# Note: We now tangle this file from ~/other/hamacs/ha-email.org # Note: We now tangle this file from ~/other/hamacs/ha-email.org
echo "Starting not-much 'pre-new' script" echo "Starting not-much 'pre-new' script"
mbsync -a mbsync -a
echo "Completing not-much 'pre-new' script" echo "Completing not-much 'pre-new' script"
#+end_src #+end_src
** =post-new= ** =post-new=
And a =post-new= hook based on a filtering scheme that mimics the Hey.com workflow taken from [[https://gist.githubusercontent.com/frozencemetery/5042526/raw/57195ba748e336de80c27519fe66e428e5003ab8/post-new][this gist]] (note we have more to say on that later on) to filter and tag all messages after they have arrived: And a =post-new= hook based on a filtering scheme that mimics the Hey.com workflow taken from [[https://gist.githubusercontent.com/frozencemetery/5042526/raw/57195ba748e336de80c27519fe66e428e5003ab8/post-new][this gist]] (note we have more to say on that later on) to filter and tag all messages after they have arrived:
@ -714,9 +729,9 @@ A new option is to use [[https://github.com/jeremy-compostella/org-msg][org-msg]
org-msg-greeting-fmt "\nHi%s,\n\n" org-msg-greeting-fmt "\nHi%s,\n\n"
org-msg-recipient-names '(("<<email-address-1()>>" . "Howard Abrams")) org-msg-recipient-names '(("<<email-address-1()>>" . "Howard Abrams"))
org-msg-greeting-name-limit 3 org-msg-greeting-name-limit 3
org-msg-default-alternatives '((new . (text html)) org-msg-default-alternatives '((new . (text html))
(reply-to-html . (text html)) (reply-to-html . (text html))
(reply-to-text . (text))) (reply-to-text . (text)))
org-msg-convert-citation t org-msg-convert-citation t
org-msg-signature " org-msg-signature "