23

Is it possible in Mutt to search for specific mail content using built-in functionality? Or, as a last resort, how can I configure grep to be used in Mutt?

The documentation only mentions the search and limit functions, which only search headers.

  • 2
    Additional to the answers below you should note that searching using mutt is very slow, regardless if you use a cache or not. If you frequently need to search I would strongly recommend an indexer such as notmuch. It's by magnitudes faster than mutt's built-in search. – Marco Sep 17 '13 at 12:48
  • 1
    Also in addition to the answers, consider looking closely at the configuration variable thorough_search. If you don't work exclusively with US-ASCII e-mail with no message-encoding, you probably want it set for searching to work the way you'd normally expect. (Took me forever to figure that out...) – a CVn Sep 17 '13 at 14:07
28

search and limit can also actually search inside messages, depending on the search patterns you give. From the Patterns subsection of the Mutt reference:

~b EXPR         messages which contain EXPR in the message body
~B EXPR         messages which contain EXPR in the whole message

That is, ~b only searches in the body, whereas ~B also searches in the headers.

Note that this can be quite slow, since it may have to download each message one by one if they are not already cached. If you have a mutt version greater or equal to 1.5.12, you can cache the ones you are downloading for later use by setting message_cachedir to a directory where you want to store message bodies, which can significantly speed up searching them (and the same for headers with header_cache).

  • Exactly what I searched for, thanks. Does message_cachedir put all messages in the cache, or only new ones ? – alex_reader Sep 17 '13 at 12:40
  • 1
    @alex_reader Only ones which you downloaded since it was set. If you do a search that includes the body across an entire folder, it should cache that entire folder as collateral. – Chris Down Sep 17 '13 at 12:40
7

You can add flags to the search command, to search the body use the search function with the ~b modifier. So to search for cheesecake inside your mail bodies:

/~b cheesecake
6

Put ~b in front of your search pattern to search only in the body of mails. For searching additionally in the headers, use ~B

There are plenty of other patterns described in the mutt manual.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.