NAME
grepmail - search mailboxes for mail matching a regular expression
SYNOPSIS
grepmail [-e <regex>] [-vihblrm] [-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 all flags 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 or bzip2, in which case gunzip 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.
- -h
-
Asserts that the pattern must match in the header of the email.
- -i
-
Make the search case-insensitive (by analogy to grep -i).
- -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.
- -l
-
Output the names of files having an email matching the expression, (by analogy to grep -l).
- -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.
- -m
-
Append "X-Mailfolder: <folder>" to all email headers, indicating which folder contained the matched email.
- -e
-
Explicitely specify the search pattern. This is useful for specifying patterns that begin with "-", which would otherwise be interpreted as a flag.
- -d
-
Date specifications must be of the form of: - a date like "today", "1st thursday in June 1992", "05/10/93", "12:30 Dec 12th 1880", "8:00pm december tenth", - OR "before", "after", or "since", followed by a date as defined above, - OR "between <date> and <date>", where <date> is defined as above.
EXAMPLES
Get all email that you mailed yesterday
grepmail -d yesterday sent-mail
Get all email that you mailed before the first thursday in June 1998 that pertains to research:
grepmail research -d "before 1st thursday in June 1992" sent-mail
Get all email you received since 8/20/98 that wasn't about research or your job, ignoring case:
grepmail "(research|job)" -i -d "since 8/20/98" -v 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 mime -b 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 "^From.*Rodney" -h -l saved-mail*
Find all emails with the text "Pilot" in both the header and the body:
grepmail "Pilot" -h -b saved-mail*
Print a count of the number of messages about grepmail in all saved-mail mailboxes:
grepmail grepmail -b -r saved-mail*
AUTHOR
David Coppit, <coppit@cs.virginia.edu>,
http://www.cs.virginia.edu/~dwc3q/index.thml
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.