31

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.

Matthias Braun
  • 7,797
  • 7
  • 45
  • 54
alex_reader
  • 819
  • 2
  • 9
  • 12
  • 3
    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](http://notmuchmail.org/). 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](http://www.mutt.org/doc/devel/manual.html#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...) – user Sep 17 '13 at 14:07

3 Answers3

38

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 STRING       If IMAP is enabled, like ~b but searches for STRING on the server, rather than downloading each message and searching it locally.
~B EXPR         messages which contain EXPR in the whole message
=B STRING       If IMAP is enabled, like ~B but searches for STRING on the server, rather than downloading each message and searching it locally.

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).

desgua
  • 61
  • 8
Chris Down
  • 122,090
  • 24
  • 265
  • 262
  • 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
9

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
Drav Sloan
  • 14,145
  • 4
  • 45
  • 43
8

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.

nickie
  • 105
  • 1
  • 1
  • 5
jofel
  • 26,513
  • 6
  • 65
  • 92