The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

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

CLASS HIERARCHY

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

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)) {...}

DESCRIPTION

Read Mail::Box-Overview first.

METHOD INDEX

Methods prefixed with an abbreviation are described in Mail::Reporter (MR), Mail::Box::Search (MBS).

The general methods for Mail::Box::Search::Grep objects:

   MR errors                            MR report [LEVEL]
   MR log [LEVEL [,STRINGS]]            MR reportAll [LEVEL]
      new OPTIONS                      MBS search FOLDER|THREAD|MESSAG...
  MBS printMatch [FILEHANDLE], HASH     MR trace [LEVEL]
      printMatchedBody FILEHANDLE...    MR warnings
      printMatchedHead FILEHANDLE...

The extra methods for extension writers:

   MR AUTOLOAD                          MR logPriority LEVEL
   MR DESTROY                           MR logSettings
  MBS inBody PART, BODY                 MR notImplemented
   MR inGlobalDestruction              MBS searchPart PART
  MBS inHead PART, HEAD

METHODS

new OPTIONS

Create a grep-like search filter.

 OPTION     DEFINED BY             DEFAULT
 binaries   Mail::Box::Search        0
 decode     Mail::Box::Search        1
 details    Mail::Box::Search::Grep  undef
 field      Mail::Box::Search::Grep  undef
 delayed    Mail::Box::Search        1
 deleted    Mail::Box::Search        0
 in         Mail::Box::Search        <$field?'HEAD':'BODY'>
 label      Mail::Box::Search        undef
 limit      Mail::Box::Search        0
 log        Mail::Reporter           'WARNINGS'
 logical    Mail::Box::Search        'REPLACE'
 match      Mail::Box::Search::Grep  <obligatory>
 multiparts Mail::Box::Search        1
 trace      Mail::Reporter           'WARNINGS'
  • details => undef|REF-ARRAY|CODE|'PRINT'|'DELETE'

    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 message, part, and field, where the field is a Mail::Message::Field object. When the match is in the body the hash will contain a message, part, linenr, and 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 PRINT will call printMatchedHead or printMatchedBody when any matching header resp body line was found. The output is minimalized by not reprinting the message info on multiple matches in the same message.

    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.

  • field => undef|STRING|REGEX|CODE

    Not valid in combination with 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.

  • match => STRING|REGEX|CODE

    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 $head resp $body are one message's head resp. body object. The $field is a header line which matches. The $line and $linenr tell the matching line in the body.

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

printMatchedHead FILEHANDLE, MATCH
printMatchedBody FILEHANDLE, MATCH

SEE ALSO

Mail::Box-Overview

For support and additional documentation, see http://perl.overmeer.net/mailbox/

AUTHOR

Mark Overmeer (mailbox@overmeer.net). All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

VERSION

This code is beta, version 2.018.

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.