.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "GREPMAIL 1p" .TH GREPMAIL 1p "2023-09-24" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" grepmail \- search mailboxes for mail matching a regular expression .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 4 \& grepmail [\-\-help|\-\-version] [\-abBDFhHilLmrRuvVw] [\-C ] \& [\-j ] [\-s ] [\-d ] \& [\-X ] [\-Y ] \& [[\-e] |\-E |\-f ] .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" .RS 2 \&\fIgrepmail\fR looks for mail messages containing a pattern, and prints the resulting messages on standard out. .Sp By default \fIgrepmail\fR looks in both header and body for the specified pattern. .Sp When redirected to a file, the result is another mailbox, which can, in turn, be handled by standard User Agents, such as \fIelm\fR, or even used as input for another instance of \fIgrepmail\fR. .Sp At least one of \fB\-E\fR, \fB\-e\fR, \fB\-d\fR, \fB\-s\fR, or \fB\-u\fR must be specified. The pattern is optional if \fB\-d\fR, \fB\-s\fR, and/or \fB\-u\fR is used. The \fB\-e\fR flag is optional if there is no file whose name is the pattern. The \fB\-E\fR option can be used to specify complex search expressions involving logical operators. (See below.) .Sp If a mailbox can not be found, grepmail first searches the directory specified by the \s-1MAILDIR\s0 environment variable (if one is defined), then searches the \&\f(CW$HOME\fR/mail, \f(CW$HOME\fR/Mail, and \f(CW$HOME\fR/Mailbox directories. .RE .SH "OPTIONS AND ARGUMENTS" .IX Header "OPTIONS AND ARGUMENTS" Many of the options and arguments are analogous to those of grep. .IP "\fBpattern\fR" 2 .IX Item "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 \&\*(L"(pattern1|pattern2|...)\*(R". .Sp Note that complex pattern features such as \*(L"(?>...)\*(R" require that you use a version of perl which supports them. You can use the pattern \*(L"()\*(R" to indicate that you do not want to match anything. This is useful if you want to initialize the cache without printing any output. .IP "\fBmailbox\fR" 2 .IX Item "mailbox" Mailboxes must be traditional, \s-1UNIX\s0 \f(CW\*(C`/bin/mail\*(C'\fR mailbox format. The mailboxes may be compressed by gzip, bzip2, lzip or xz, in which case the associated compression tool must be installed on the system, as well as a recent version of the Mail::Mbox::MessageParser Perl module that supports the format. .Sp If no mailbox is specified, takes input from stdin, which can be compressed or not. grepmail's behavior is undefined when \s-1ASCII\s0 and binary data is piped together as input. .IP "\fB\-a\fR" 2 .IX Item "-a" Use arrival date instead of sent date. .IP "\fB\-b\fR" 2 .IX Item "-b" Asserts that the pattern must match in the body of the email. .IP "\fB\-B\fR" 2 .IX Item "-B" Print the body but with only minimal ('From ', 'From:', 'Subject:', 'Date:') headers. This flag can be used with \-H, in which case it will print only short headers and no email bodies. .IP "\fB\-C\fR" 2 .IX Item "-C" Specifies the location of the cache file. The default is \&\f(CW$HOME\fR/.grepmail\-cache. .IP "\fB\-D\fR" 2 .IX Item "-D" Enable debug mode, which prints diagnostic messages. .IP "\fB\-d\fR" 2 .IX Item "-d" Date specifications must be of the form of: \- a date like \*(L"today\*(R", \*(L"yesterday\*(R", \*(L"5/18/93\*(R", \*(L"5 days ago\*(R", \*(L"5 weeks ago\*(R", \- \s-1OR\s0 \*(L"before\*(R", \*(L"after\*(R", or \*(L"since\*(R", followed by a date as defined above, \- \s-1OR\s0 \*(L"between and \*(R", where is defined as above. .Sp Simple date expressions will first be parsed by Date::Parse. If this fails, grepmail will attempt to parse the date with Date::Manip, if the module is installed on the system. Use an empty pattern (i.e. \fB\-d ""\fR) to find emails without a \*(L"Date: ...\*(R" line in the header. .Sp Date specifications without times are interpreted as having a time of midnight of that day (which is the morning), except for \*(L"after\*(R" and \*(L"since\*(R" specifications, which are interpreted as midnight of the following day. For example, \*(L"between today and tomorrow\*(R" is the same as simply \*(L"today\*(R", and returns emails whose date has the current day. (\*(L"now\*(R" is interpreted as \&\*(L"today\*(R".) The date specification \*(L"after July 5th\*(R" will return emails whose date is midnight July 6th or later. .IP "\fB\-E\fR" 2 .IX Item "-E" Specify a complex search expression using logical operators. The current syntax allows the user to specify search expressions using Perl syntax. Three values can be used: \f(CW$email\fR (the entire email message), \f(CW$email_header\fR (just the header), or \f(CW$email_body\fR (just the body). A search is specified in the form \&\*(L"$email =~ /pattern/\*(R", and multiple searches can be combined using \*(L"&&\*(R" and \&\*(L"||\*(R" for \*(L"and\*(R" and \*(L"or\*(R". .Sp For example, the expression .Sp .Vb 1 \& $email_header =~ /^From: .*\e@coppit.org/ && $email =~ /grepmail/i .Ve .Sp will find all emails which originate from coppit.org (you must escape the \*(L"@\*(R" sign with a backslash), and which contain the keyword \*(L"grepmail\*(R" anywhere in the message, in any capitalization. .Sp \&\fB\-E\fR is incompatible with \fB\-b\fR, \fB\-h\fR, and \fB\-e\fR. \fB\-i\fR, \fB\-M\fR, \fB\-S\fR, and \&\fB\-Y\fR have not yet been implemented. .Sp \&\s-1NOTE:\s0 The syntax of search expressions may change in the future. In particular, support for size, date, and other constraints may be added. The syntax may also be simplified in order to make expression formation easier to use (and perhaps at the expense of reduced functionality). .IP "\fB\-e\fR" 2 .IX Item "-e" Explicitly specify the search pattern. This is useful for specifying patterns that begin with \*(L"\-\*(R", which would otherwise be interpreted as a flag. .IP "\fB\-f\fR" 2 .IX Item "-f" Obtain patterns from \s-1FILE,\s0 one per line. The empty file contains zero patterns, and therefore matches nothing. .IP "\fB\-F\fR" 2 .IX Item "-F" Force grepmail to process all files and streams as though they were mailboxes. (i.e. Skip checks for non-mailbox \s-1ASCII\s0 files or binary files that don't look like they are compressed using known schemes.) .IP "\fB\-h\fR" 2 .IX Item "-h" Asserts that the pattern must match in the header of the email. .IP "\fB\-H\fR" 2 .IX Item "-H" Print the header but not body of matching emails. .IP "\fB\-i\fR" 2 .IX Item "-i" Make the search case-insensitive (by analogy to \fIgrep \-i\fR). .IP "\fB\-j\fR" 2 .IX Item "-j" Asserts that the email \*(L"Status:\*(R" header must contain the given flags. Order and case are not important, so use \fI\-j \s-1AR\s0\fR or \fI\-j ra\fR to search for emails which have been read and answered. .IP "\fB\-l\fR" 2 .IX Item "-l" Output the names of files having an email matching the expression, (by analogy to \fIgrep \-l\fR). .IP "\fB\-L\fR" 2 .IX Item "-L" Follow symbolic links. (Implies \fI\-R\fR) .IP "\fB\-M\fR" 2 .IX Item "-M" Causes grepmail to ignore non-text \s-1MIME\s0 attachments. This removes false positives resulting from binaries encoded as \s-1ASCII\s0 attachments. .IP "\fB\-m\fR" 2 .IX Item "-m" Append \*(L"X\-Mailfolder: \*(R" to all email headers, indicating which folder contained the matched email. .IP "\fB\-n\fR" 2 .IX Item "-n" Prefix each line with line number information. If multiple files are specified, the filename will precede the line number. \s-1NOTE:\s0 When used in conjunction with \fB\-m\fR, the X\-Mailfolder header has the same line number as the next (blank) line. .IP "\fB\-q\fR" 2 .IX Item "-q" Quiet mode. Suppress the output of warning messages about non-mailbox files, directories, etc. .IP "\fB\-r\fR" 2 .IX Item "-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. .IP "\fB\-R\fR" 2 .IX Item "-R" Causes grepmail to recurse any directories encountered. .IP "\fB\-s\fR" 2 .IX Item "-s" Return emails which match the size (in bytes) specified with this flag. Note that this size includes the length of the header. .Sp Size constraints must be of the form of: \- 12345: match size of exactly 12345 \- <12345, <=12345, >12345, >=12345: match size less than, less than or equal, greater than, or greater than or equal to 12345 \- 10000\-12345: match size between 10000 and 12345 inclusive .IP "\fB\-S\fR" 2 .IX Item "-S" Ignore signatures. The signature consists of everything after a line consisting of \*(L"\-\- \*(R". .IP "\fB\-u\fR" 2 .IX Item "-u" Output only unique emails, by analogy to \fIsort \-u\fR. Grepmail determines email uniqueness by the Message-ID header. .IP "\fB\-v\fR" 2 .IX Item "-v" Invert the sense of the search, by analogy to \fIgrep \-v\fR. This results in the set of emails printed being the complement of those that would be printed without the \fB\-v\fR switch. .IP "\fB\-V\fR" 2 .IX Item "-V" Print the version and exit. .IP "\fB\-w\fR" 2 .IX Item "-w" Search for only those lines which contain the pattern as part of a word group. That is, the start of the pattern must match the start of a word, and the end of the pattern must match the end of a word. (Note that the start and end need not be for the \fIsame\fR word.) .Sp If you are familiar with Perl regular expressions, this flag simply puts a \&\*(L"\eb\*(R" before and after the search pattern. .IP "\fB\-X\fR" 2 .IX Item "-X" Specify a regular expression for the signature separator. By default this pattern is '^\-\- $'. .IP "\fB\-Y\fR" 2 .IX Item "-Y" Specify a pattern which indicates specific headers to be searched. The search will automatically treat headers which span multiple lines as one long line. This flag implies \fB\-h\fR. .Sp In the style of procmail, special strings in the pattern will be expanded as follows: .RS 2 .Sp .RS 2 If the regular expression contains \*(L"^TO:\*(R" it will be substituted by .Sp .Vb 1 \& ^((Original\-)?(Resent\-)?(To|Cc|Bcc)|(X\-Envelope|Apparently(\-Resent)?)\-To): .Ve .Sp which should match all headers with destination addresses. .Sp If the regular expression contains \*(L"^FROM_DAEMON:\*(R" it will be substituted by .Sp .Vb 1 \& (^(Mailing\-List:|Precedence:.*(junk|bulk|list)|To: Multiple recipients of |(((Resent\-)?(From|Sender)|X\-Envelope\-From):|>?From )([^>]*[^(.%@a\-z0\-9])?(Post(ma?(st(e?r)?|n)|office)|(send)?Mail(er)?|daemon|m(mdf|ajordomo)|n?uucp|LIST(SERV|proc)|NETSERV|o(wner|ps)|r(e(quest|sponse)|oot)|b(ounce|bs\e.smtp)|echo|mirror|s(erv(ices?|er)|mtp(error)?|ystem)|A(dmin(istrator)?|MMGR|utoanswer))(([^).!:a\-z0\-9][\-_a\-z0\-9]*)?[%@>\et ][^<)]*(\e(.*\e).*)?)? .Ve .Sp which should catch mails coming from most daemons. .Sp If the regular expression contains \*(L"^FROM_MAILER:\*(R" it will be substituted by .Sp .Vb 1 \& (^(((Resent\-)?(From|Sender)|X\-Envelope\-From):|>?From)([^>]*[^(.%@a\-z0\-9])?(Post(ma(st(er)?|n)|office)|(send)?Mail(er)?|daemon|mmdf|n?uucp|ops|r(esponse|oot)|(bbs\e.)?smtp(error)?|s(erv(ices?|er)|ystem)|A(dmin(istrator)?|MMGR))(([^).!:a\-z0\-9][\-_a\-z0\-9]*)?[%@>\et][^<)]*(\e(.*\e).*)?)?$([^>]|$)) .Ve .Sp (a stripped down version of \*(L"^FROM_DAEMON:\*(R"), which should catch mails coming from most mailer-daemons. .Sp So, to search for all emails to or from \*(L"Andy\*(R": .Sp .Vb 1 \& grepmail \-Y \*(Aq(^TO:|^From:)\*(Aq Andy mailbox .Ve .RE .RE .RS 2 .RE .IP "\fB\-\-help\fR" 2 .IX Item "--help" Print a help message summarizing the usage. .IP "\fB\-\-\fR" 2 .IX Item "--" All arguments following \fI\-\-\fR are treated as mail folders. .SH "EXAMPLES" .IX Header "EXAMPLES" Count the number of emails. (\*(L".\*(R" matches every email.) .PP .Vb 1 \& grepmail \-r . sent\-mail .Ve .PP Get all email between 2000 and 3000 bytes about books .PP .Vb 1 \& grepmail books \-s 2000\-3000 sent\-mail .Ve .PP Get all email that you mailed yesterday .PP .Vb 1 \& grepmail \-d yesterday sent\-mail .Ve .PP Get all email that you mailed before the first thursday in June 1998 that pertains to research (requires Date::Manip): .PP .Vb 1 \& grepmail research \-d "before 1st thursday in June 1998" sent\-mail .Ve .PP Get all email that you mailed before the first of June 1998 that pertains to research: .PP .Vb 1 \& grepmail research \-d "before 6/1/98" sent\-mail .Ve .PP Get all email you received since 8/20/98 that wasn't about research or your job, ignoring case: .PP .Vb 1 \& grepmail \-iv "(research|job)" \-d "since 8/20/98" saved\-mail .Ve .PP Get all email about mime but not about Netscape. Constrain the search to match the body, since most headers contain the text \*(L"mime\*(R": .PP .Vb 1 \& grepmail \-b mime saved\-mail | grepmail Netscape \-v .Ve .PP Print a list of all mailboxes containing a message from Rodney. Constrain the search to the headers, since quoted emails may match the pattern: .PP .Vb 1 \& grepmail \-hl "^From.*Rodney" saved\-mail* .Ve .PP Find all emails with the text \*(L"Pilot\*(R" in both the header and the body: .PP .Vb 1 \& grepmail \-hb "Pilot" saved\-mail* .Ve .PP Print a count of the number of messages about grepmail in all saved-mail mailboxes: .PP .Vb 1 \& grepmail \-br grepmail saved\-mail* .Ve .PP Remove any duplicates from a mailbox: .PP .Vb 1 \& grepmail \-u saved\-mail .Ve .PP Convert a Gnus mailbox to mbox format: .PP .Vb 1 \& grepmail . gnus\-mailbox\-dir/* > mbox .Ve .PP Search for all emails to or from an address (taking into account wrapped headers and different header names): .PP .Vb 1 \& grepmail \-Y \*(Aq(^TO:|^From:)\*(Aq my@email.address saved\-mail .Ve .PP Find all emails from postmasters: .PP .Vb 1 \& grepmail \-Y \*(Aq^FROM_MAILER:\*(Aq . saved\-mail .Ve .SH "FILES" .IX Header "FILES" grepmail will \fInot\fR 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. .SH "ENVIRONMENT" .IX Header "ENVIRONMENT" The \s-1MAILDIR\s0 environment variable can be used to specify the default mail directory. This directory will be searched if the specified mailbox can not be found directly. .PP The \s-1HOME\s0 environment variable is also used to find mailboxes if they can not be found directly. It is also used to store grepmail state information such as its cache file. .SH "BUGS AND LIMITATIONS" .IX Header "BUGS AND LIMITATIONS" .ie n .IP "Patterns containing ""$"" may cause problems" 2 .el .IP "Patterns containing ``$'' may cause problems" 2 .IX Item "Patterns containing $ may cause problems" Currently I look for \*(L"$\*(R" followed by a non-word character and replace it with the line ending for the current file (either \*(L"\en\*(R" or \*(L"\er\en\*(R"). This may cause problems with complex patterns specified with \-E, but I'm not aware of any. .IP "Mails without bodies cause problems" 2 .IX Item "Mails without bodies cause problems" According to \s-1RFC 822,\s0 mail messages need not have message bodies. I've found and removed one bug related to this. I'm not sure if there are others. .IP "Complex single-point dates not parsed correctly" 2 .IX Item "Complex single-point dates not parsed correctly" If you specify a point date like \*(L"September 1, 2004\*(R", grepmail creates a date range that includes the entire day of September 1, 2004. If you specify a complex point date such as \*(L"today\*(R", \*(L"1st Monday in July\*(R", or \*(L"9/1/2004 at 0:00\*(R" grepmail may parse the time incorrectly. .Sp The reason for this problem is that Date::Manip, as of version 5.42, forces default values for parsed dates and times. This means that grepmail has a hard time determining whether the user supplied certain time/date fields. (e.g. Did Date::Manip provide a default time of 0:00, or did the user specify it?) grepmail tries to work around this problem, but the workaround is inherently incomplete in some rare cases. .IP "File names that look like flags cause problems." 2 .IX Item "File names that look like flags cause problems." In some special circumstances, grepmail will be confused by files whose names look like flags. In such cases, use the \fB\-e\fR flag to specify the search pattern. .SH "LICENSE" .IX Header "LICENSE" This code is distributed under the \s-1GNU\s0 General Public License (\s-1GPL\s0) Version 2. See the file \s-1LICENSE\s0 in the distribution for details. .SH "AUTHOR" .IX Header "AUTHOR" David Coppit .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBelm\fR\|(1), \fBmail\fR\|(1), \fBgrep\fR\|(1), \fBperl\fR\|(1), \fBprintmail\fR\|(1), \fBMail::Internet\fR\|(3), \&\fBprocmailrc\fR\|(5). Crocker, D. H., Standard for the Format of Arpa Internet Text Messages, \s-1RFC 822.\s0