
=head1 NAME


Mail::Box::Search::Grep - select messages within a mail box like grep does

=head1 CLASS INHERITANCE

Mail::Box::Search::Grep
   is a Mail::Box::Search
   is a Mail::Reporter

=head1 SYNOPSIS


 use Mail::Box::Manager;
 my $mgr    = Mail::Box::Manager->new;
 my $folder = $mgr->open('Inbox');

 my $filter = Mail::Box::Search::Grep->new
    ( $folder, label => 'selected'
    , in => 'BODY', match => qr/abc?d*e/
    );
 my @msgs   = $filter->search($folder);

 my $filter = Mail::Box::Search::Grep
    ->new(field => 'To', match => $my_email);
 if($filter->search($message)) {...}

=head1 DESCRIPTION


=head1 METHODS

=head2 Initiation

=over 4

=item B<new> OPTIONS X<new>

Create a UNIX-grep like search filter.

 OPTION               DEFAULT
 binaries             <false>
 decode               <true>
 delayed              <true>
 deleted              <false>
 details              undef
 field                undef
 in                   <$field ? 'HEAD' : 'BODY'>
 label                undef
 limit                0
 log                  'WARNINGS'
 logical              'REPLACE'
 match                <obligatory>
 multiparts           <true>
 trace                'WARNINGS'

=over 4

=item B<binaries> =E<gt> BOOLEAN

See Mail::Box::Search::new(binaries)

=item B<decode> =E<gt> BOOLEAN

See Mail::Box::Search::new(decode)

=item B<delayed> =E<gt> BOOLEAN

See Mail::Box::Search::new(delayed)

=item B<deleted> =E<gt> BOOLEAN

See Mail::Box::Search::new(deleted)

=item B<details> =E<gt> undef|REF-ARRAY|CODE|'PRINT'|'DELETE' X<new(details)>

Store the details about where the match was found.  The search may take
much longer when this feature is enabled.

When an ARRAY is specified it will contain a list of references to hashes.
Each hash contains the information of one match.  A match in a header
line will result in a line with fields C<message>, C<part>, and C<field>, where
the field is a Mail::Message::Field object.  When the match is in
the body the hash will contain a C<message>, C<part>, C<linenr>, and C<line>.

In case of a CODE reference, that routine is called for each match. The
first argument is this search object and the second a reference to same
hash as would be stored in the array.

The C<PRINT> will call printMatchedHead() or printMatchedBody() when
any matching header resp body line was found.  The output is minimized
by not reprinting the message info on multiple matches in the same
message.

C<DELETE> will flag
the message to be deleted in case of a match.  When a multipart's part
is matched, the whole message will be flagged for deletion.

=item B<field> =E<gt> undef|STRING|REGEX|CODE X<new(field)>

Not valid in combination with C<< in => BODY >>.
all. The STRING is one full field name (case-insensitive).  Use a REGEX
to select more than one header line to be scanned. CODE is a routine which
is called for each field in the header.   The CODE is called with the header
as first, and the field as second argument.  If the CODE returns true, the
message is selected.

=item B<in> =E<gt> 'HEAD'|'BODY'|'MESSAGE'

See Mail::Box::Search::new(in)

=item B<label> =E<gt> STRING

See Mail::Box::Search::new(label)

=item B<limit> =E<gt> NUMBER

See Mail::Box::Search::new(limit)

=item B<log> =E<gt> LEVEL

See Mail::Reporter::new(log)

=item B<logical> =E<gt> 'REPLACE'|'AND'|'OR'|'NOT'|'AND NOT'|'OR NOT'

See Mail::Box::Search::new(logical)

=item B<match> =E<gt> STRING|REGEX|CODE X<new(match)>

The pattern to be search for can be a REGular EXpression, or a STRING.  In
both cases, the match succeeds if it is found anywhere within the selected
fields.

With a CODE reference, that function will be called each field or body-line.
When the result is true, the details are delivered.  The call formats are

 $code->($head, $field);          # for HEAD searches
 $code->($body, $linenr, $line);  # for BODY searches

The C<$head> resp C<$body> are one message's head resp. body object.  The
C<$field> is a header line which matches.  The C<$line> and C<$linenr>
tell the matching line in the body.

Be warned that when you search C<< in => MESSAGE >> the code must accept
both formats.

=item B<multiparts> =E<gt> BOOLEAN

See Mail::Box::Search::new(multiparts)

=item B<trace> =E<gt> LEVEL

See Mail::Reporter::new(trace)

=back

=back

=head2 Searching

=over 4

=item B<inBody> PART, BODY

See Mail::Box::Search::inBody()

=item B<inHead> PART, HEAD

See Mail::Box::Search::inHead()

=item B<search> FOLDER|THREAD|MESSAGE|ARRAY-OF-MESSAGES

See Mail::Box::Search::search()

=item B<searchPart> PART

See Mail::Box::Search::searchPart()

=back

=head2 The Results

=over 4

=item B<printMatch> [FILEHANDLE], HASH

See Mail::Box::Search::printMatch()

=item B<printMatchedBody> FILEHANDLE, MATCH X<printMatchedBody>

=item B<printMatchedHead> FILEHANDLE, MATCH X<printMatchedHead>

=back

=head2 Logging and Tracing

=over 4

=item B<errors> 

See Mail::Reporter::errors()

=item B<log> [LEVEL [,STRINGS]]

See Mail::Reporter::log()

=item B<report> [LEVEL]

See Mail::Reporter::report()

=item B<reportAll> [LEVEL]

See Mail::Reporter::reportAll()

=item B<trace> [LEVEL]

See Mail::Reporter::trace()

=item B<warnings> 

See Mail::Reporter::warnings()

=back

=head2 Other Methods

=over 4

=item B<AUTOLOAD> 

See Mail::Reporter::AUTOLOAD()

=item B<DESTROY> 

See Mail::Reporter::DESTROY()

=item B<inGlobalDestruction> 

See Mail::Reporter::inGlobalDestruction()

=item B<logPriority> LEVEL

See Mail::Reporter::logPriority()

=item B<logSettings> 

See Mail::Reporter::logSettings()

=item B<notImplemented> 

See Mail::Reporter::notImplemented()

=back

=head1 SEE ALSO

A good start to read is Mail::Box-Overview.
More documentation and a mailinglist are available from the project's
website at L<http://perl.overmeer.net/mailbox/>.

=head1 AUTHOR

Mark Overmeer (L<mark@overmeer.net|mailto:mark@overmeer.net>) with the help of many.

=head1 VERSION

This code is beta, version 2.019.

Copyright (c) 2001-2002 Mark Overmeer. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
