Harry R. Schwartz

Code writer, sometime Internet enthusiast, attractive nuisance.

The author at the Palais du Luxembourg in Paris, November 2022. hacker news gitlab sourcehut pinboard librarything 1B41 8F2C 23DE DD9C 807E A74F 841B 3DAE 25AE 721B

Vancouver

British Columbia

Canada

vegan


Searching Email from mutt on OS X

hrs

Published .
Tags: beards.

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"
  • 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 to xargs on line 53, since that’s specific to GNU readline and not strictly necessary.

  • Add a binding to your .muttrc to trigger the search. I’ve adapted this from the mutt-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.

  1. mutt-notmuch’s author, Stephano Zacchiroli, is a former Debian Project Leader, so that’s no surprise. 


You might like these textually similar articles: