Searching Email from mutt
on OS X
WARNING: I’m not on a Mac any more, but I’ve had this draft sitting around forever and it should probably be out in the world. I think all of the information should still be accurate, but I might be wrong!
mutt works differently from most mail clients. It does very little on its own and relies on external tools for almost everything, including indexing and searching your mail. Since your (gigs of) mail are almost certainly stored locally you’ll need to build and query a local index to find mail quickly.
notmuch is a popular tool for indexing mail, and it’s usually paired with mutt-notmuch for use with mutt. I’ve had an easy time using it on Debian,1 but setting it up on OS X is a bit more of a hassle.
Here are the steps that worked for me:
- Install and configure notmuch. I’m not going to describe that part; it’s available through Homebrew and the rest of the process is covered in plenty of detail elsewhere.
- Make sure that notmuch is run regularly. I automatically run it every time I fetch mail:
macro index O \
"<shell-escape>mbsync personal work; notmuch new<enter>" \
"run mbsync to sync all mail"
- Add the
mutt-notmuch
script to a bin directory and make it executable. It’s available for download here.
mutt-notmuch
is a Perl script, so you’ll need to install the requisite dependencies:
$ sudo cpan Mail::Box::Maildir String::ShellQuote Term::ReadLine::Stub Term::ReadLine::Gnu
-
Since we’re on a Mac we’ll need to tweak the script a bit. Remove the
-r
option toxargs
on line 53, since that’s specific to GNUreadline
and not strictly necessary. -
Add a binding to your
.muttrc
to trigger the search. I’ve adapted this from themutt-notmuch
documentation:
macro index S \
"<enter-command>set my_old_pipe_decode=\$pipe_decode my_old_wait_key=\$wait_key nopipe_decode nowait_key<enter>\
<shell-escape>notmuch-mutt -r --prompt search<enter>\
<change-folder-readonly>`echo ${XDG_CACHE_HOME:-$HOME/.cache}/notmuch/mutt/results`<enter>\
<enter-command>set pipe_decode=\$my_old_pipe_decode wait_key=\$my_old_wait_key<enter>" \
"notmuch: search mail"
You should now be prompted for a search term when you hit S
! Happy notmuching.
-
mutt-notmuch
’s author, Stephano Zacchiroli, is a former Debian Project Leader, so that’s no surprise. ↩
You might like these textually similar articles: