TITLE: Using notmuch to search email in Mutt
DATE: 2019-01-05
AUTHOR: John L. Godlee
====================================================================


I found that the inbuilt search facility in my email client, Mutt,
was not all that powerful, or at least I didn’t have the inclination
to learn its ways. But I already know how to use notmuch for
indexing and searching email, so I wanted to incorporate it into my
Mutt workflow.

I made sure I had notmuch on my computer:

    brew install notmuch

NeoMutt is meant to come with notmuch support out of the box, so I
didn’t need to apply the [notmuch-mutt] patch. I did use [this
mutt-notmuch-py script] though, which I included in my $PATH by
adding it to ~/bin.

  [notmuch-mutt]: https://notmuchmail.org/notmuch-mutt/
  [this mutt-notmuch-py script]: https://github.com/honza/mutt-notmuch-py

Then, I edited my muttrc to include this macro:

    # Search using notmuch
    macro index \\ "<enter-command>unset wait_key<enter><shell-escape>mutt-notmuch-py ~/.mail/temporary/search<enter><change-folder-readonly>+temporary/search<enter>" "search mail (using notmuch)"

It calls mutt-notmuch-py and puts results based on your query in
~/.mail/temporary/search as a mailbox, then switches to that
temporary mailbox.

I also wanted to make search results appear in my sidebar, to be
visible until I ran the macro again, so I added it to my sidebar
mailbox creation:

    # Notmuch search mailbox
    mailboxes "+--- search --------"
    mailboxes +temporary/search