NAME

grepmail - search mailboxes for mail matching a regular expression

SYNOPSIS

grepmail [-vihblrm] [-e <regex>] [-d "datespec"] [mailbox ...]

DESCRIPTION

    grepmail looks for mail messages containing a pattern, and prints the resulting messages on standard out.

    By default grepmail looks in both header and body for the specified pattern.

    When redirected to a file, the result is another mailbox, which can, in turn, be handled by standard User Agents, such as elm, or even used as input for another instance of grepmail.

    The pattern is optional if -d is used, and must precede the -d flag unless it is specified using -e.

OPTIONS AND ARGUMENTS

Many of the options and arguments are analogous to those of grep.

pattern

The pattern to search for in the mail message. May be any Perl regular expression, but should be quoted on the command line to protect against globbing (shell expansion). To search for more than one pattern, use the form "(pattern1|pattern2|...)".

mailbox

Mailboxes must be traditional, UNIX /bin/mail mailbox format. The mailboxes may be compressed by gzip, bzip2, or tzip, in which case gunzip, bzip2, or tzip must be installed on the system.

If no mailbox is specified, takes input from stdin, which can be compressed or not. grepmail's behavior is undefined when ASCII and binary data is piped together as input.

-b

Asserts that the pattern must match in the body of the email.

-D

Enable debug mode, which prints diagnostic messages.

-d

Date specifications must be of the form of: - a date like "today", "yesterday", "5/18/93", "5 days ago", "5 weeks ago", - OR "before", "after", or "since", followed by a date as defined above, - OR "between <date> and <date>", where <date> is defined as above.

-e

Explicitely specify the search pattern. This is useful for specifying patterns that begin with "-", which would otherwise be interpreted as a flag.

-h

Asserts that the pattern must match in the header of the email.

-i

Make the search case-insensitive (by analogy to grep -i).

-l

Output the names of files having an email matching the expression, (by analogy to grep -l).

-m

Append "X-Mailfolder: <folder>" to all email headers, indicating which folder contained the matched email.

-r

Generate a report of the names of the files containing emails matching the expression, along with a count of the number of matching emails.

-v

Invert the sense of the search, (by analogy to grep -v). Note that this affects only -h and -b, not -d. This results in the set of emails printed being the complement of those that would be printed without the -v switch.

EXAMPLES

Get all email that you mailed yesterday

grepmail -d yesterday sent-mail

Get all email that you mailed before the first of June 1998 that pertains to research:

grepmail research -d "before 6/1/92" sent-mail

Get all email you received since 8/20/98 that wasn't about research or your job, ignoring case:

grepmail -iv "(research|job)" -d "since 8/20/98" saved-mail

Get all email about mime but not about Netscape. Constrain the search to match the body, since most headers contain the text "mime":

grepmail -b mime saved-mail | grepmail Netscape -v

Print a list of all mailboxes containing a message from Rodney. Constrain the search to the headers, since quoted emails may match the pattern:

grepmail -hl "^From.*Rodney" saved-mail*

Find all emails with the text "Pilot" in both the header and the body:

grepmail -hb "Pilot" saved-mail*

Print a count of the number of messages about grepmail in all saved-mail mailboxes:

grepmail -br grepmail saved-mail*

FILES

grepmail will not create temporary files while decompressing compressed archives. The last version to do this was 3.5. While the new design uses more memory, the code is much simpler, and there is less chance that email can be read by malicious third parties. Memory usage is determined by the size of the largest email message in the mailbox.

AUTHOR

David Coppit, <coppit@cs.virginia.edu>,
http://www.cs.virginia.edu/~dwc3q/index.html

SEE ALSO

elm(1), mail(1), grep(1), perl(1), printmail(1), Mail::Internet(3) Crocker, D. H., Standard for the Format of Arpa Internet Text Messages, RFC822.