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.
Document Links
- A Tao of Regular Expressions
-
This is an overview of regular expressions for people who are scared of them
http://www.let.uu.nl/~Michael.Moortgat/personal/Courses/TT02/tao_regexps.html
- the mutt manual
-
Everything you ever wanted to know about mutt
http://www.mutt.org/doc/manual/
- grepmail
-
grepmail searches normal or compressed mbox files for a given regular expression and returns those emails that match the query.
http://grepmail.sourceforge.net/
- grepm wrapper
-
grepm is a little wrapper script to assist in using grepmail with the mutt MUA
http://www.barsnick.net/sw/grepm.html
- mutt-users archive
-
web searchable mailing list archive
http://groups.yahoo.com/group/mutt-users/
- glimpse
-
A powerful indexing and query system for UNIX that allows you to search through all your files very quickly.
http://www.webglimpse.org/
- mboxgrep
-
a small utility that scans a mailbox for messages matching a regular expression.
http://mboxgrep.sourceforge.net/
- mairix
-
mairix is a program for indexing and searching email messages stored in Maildir or MH folders
http://www.rpcurnow.force9.co.uk/mairix/
- nmzmail
-
nmzmail is a tool to use the namazu2 search engine from within the mutt mail reader to search mail stored in maildir folders
http://www.ecademix.com/JohannesHofmann/nmzmail.html
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