Harry R. Schwartz

Software engineer, nominal scientist, gentleman of the internet. Member, ←Hotline Webring→.

Searching Email from mutt on OS X

Published 16 Jul 2016. 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:

macro index O \
  "<shell-escape>mbsync personal work; notmuch new<enter>" \
  "run mbsync to sync all mail"
sudo cpan Mail::Box::Maildir String::ShellQuote Term::ReadLine::Stub Term::ReadLine::Gnu
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.