26.30 Grepmail: Search mail archives
Grepmail searches mailboxes to build a new mailbox with all emails
containing the results, so that they can be reviewed with your
favourite mail tool. The default is to search for the pattern in both
the head and body of the email. Only email headers are searched if you
specify -h; search is restricted to email bodies with -b. To be case
insensitive use -i and to ignore MIME-encoded blocks use -M. Date
searches are effected with -d which allows a date string in a variety
of formats, including
for email since 18 May 2001.
The basic use is:
$ grepmail <string> [<mbox>] > <newmbox>
So, for example, you might search for the email containing that meeting:
$ grepmail -RMi "that meeting" ~/mail > meeting.mbox
This takes about 10 minutes to search my 2GB of mail files.
But perhaps you want just a report of files in which the email appears:
$ grepmail -RMir "that meeting"
More complex patterns are possible:
$ grepmail -RMih "^From.*Freddy" ~/mail
And to search specific headers:
$ grepmail -RMiY '(^TO:|^From:)' email@example.com ~/mail
Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2021 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0