Searching through all your different mailboxes can be cumbersome without
tools that were made for the job. A simple grep -Er will return many
headers and lines without context, apart from being really slow.
These applications index your messages in their own databases for fast
searching. Remember to schedule the update of the databases, probably
All of them usually create a virtual maildir, containing symbolic
links to the original messages (or a copy in case of mbox). If one wants
to rename (for setting/clearing flags), delete or edit the mails, it is
only possible using the original message. There is currently no way to
do this in mutt, but there is a small shell
can be called by a macro.
Mairix is a program for
indexing and searching email messages stored in Maildir, MH or mbox
folders. The mailboxes can also be in gzip (version 0.17) or bzip2
(version 0.18) format, which makes it great for archived mailboxes.
(Check out archivemail.)
When you perform a lookup, it creates copies or symbolic links to the
directory specified by mfolder, depending on whether you've configured
it to ouput in Maildir, mbox, MH or raw format. (the former is the
mu is yet another mail indexer which
integrates well with Mutt. It is based on
Sqlite (for mail metadata) and
Xapian (for full text search). A very brief
(and surely biased by author's final choice) among mu, mairix, and
nmzmail (discussed above) has been blogged
Querying is performed using the Xapian query language.
At first, you will need to index all your Maildirs; assuming they are
all stored recursively under a single directory, you can do that with
mu-index -m PATH
If the dir is ~/Maildir or some other common place (e.g. defined in
$MAILDIR), you can avoid passing -m.
Then, you can periodically update the index via cron or any other mean.
You can do that with the following cron entry:
31 */2 * * * on_ac_power && mu-index -q
With about 20'000 mails it is quite fast and finishes in a few seconds.
Macros for Mutt integration are reported below.
~/.mutt/macros ## Search mail # Mairix macro generic ,f "<shell-escape>mairix " "search via mairix" # Namazu/nmzmail macro generic ,F "<shell-escape>nmzmail -r ~/.maildir/.Search<enter>" "search via nmzmail" # Load the results mailbox macro generic ,,f "<change-folder><kill-line>=.Search<enter>" "load the search results mailbox" # Mu # first macro does the search according to user query, second macro jumps to result list macro index <F8> "<shell-escape>rm -rf ~/.mu/results; mu-find -o l -l ~/.mu/results " "mu-find" macro index <F9> "<change-folder-readonly>~/.mu/results\n" "display mu-find results"
Of course, macros can be written to immediately change to the folder
with the results, though YMMV.