Skip Navigation

Searching mail

Pattern matching with regular expressions

Mutt has powerful regular expression matching for searching, tagging mail and limiting the message view - but only within a single mailfolder.

If regular expressions are new to you or just plain scary, you may want to read a primer such as A Tao of Regular Expressions. If you are still confused, don't panic, mutt will look at your search word and attempt a simple search for you. For example:

In the index view, hit the / key to search all the visible messages. Now, instead of entering a regular expression that you want to match, simply type the word you want to search for: joe, then hit enter. Mutt will magically translate this into the regular expression: ~f joe | ~s joe. The mutt cursor will jump to the next message with the word joe in the message's headers From: or Subject:. You can repeat the search and find the next matching message by hitting n for search-next.

All pattern-matches are case-insensitive by default unless you include capital letters in the search string.

Starting a search with the / key is a standard command for searching in many applications, try searching within a message in the pager view.

The limit command

More powerful than the search command is the limit command. In fact, once you start using the limit command, you will probably never need to use search. Instead of pressing / for search, press l for limit, type the word you want to match, joe and hit enter. Mutt will limit the display so that only the matching messages are visible. To return to the full message view, simply limit the view to a word that is guaranteed to match everything: . (a single dot is a simple regular expression that matches any character).

Mutt regular expression extensions

Mutt has some extra features specifically for searching and matching email. You have seen a couple of them already with ~f and ~s in the regular expression above. For a full explanation of all the features, which include; matching arbitrary headers, body-text, dates, boolean and/or/not and much more, see the mutt manual.

Searching across multiple mailboxes

A drawback with the Unix Way of storing mail as un-indexed text-files is that MUAs find searching over multiple mailboxes very difficult or slow. Mutt can't perform a search or limit command over multiple mail folders.

To search multiple mbox files, you may want to investigate the grepmail package and the associated grepm wrapper for mutt. Note, grepmail doesn't support searching Maildir, imap or mh mailboxes; mboxgrep and mairix are similar utilities that do support mh and Maildir. I'm not aware of any tool that searches multiple IMAP folders.

Searching using a database

A more sophisticated and faster method of searching through multiple mailboxes would be to use a database-engine to index your mail periodically - You can then use this index to build temporary folders from search queries and browse them with mutt. Mairix is one such tool, it can search multiple headers or body text; plus messages can be returned with the related threads as context. Nmzmail is a similar tool that uses the namazu search engine as a backend to do the same job.

<< | Up | >>

This document was last modified on 2012-02-28 21:23:22.
Bruno Postle <bruno@postle.net>
Copyright © 2001 Bruno Postle and others. This guide is released under the Free Documentation License. http://www.gnu.org/licenses/fdl.txt