Go to TogaWare.com Home Page. GNU/Linux Desktop Survival Guide
by Graham Williams
Duck Duck Go

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 -d yesterday, -d "5/18/2001" 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:)' freddy@ktware.de ~/mail

Copyright © 1995-2019 Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
Brought to you by Togaware and the author of open source software including Rattle and wajig.
Also the author of Data Mining with Rattle and Essentials of Data Science.