"Fossies" - the Fresh Open Source Software Archive

Member "Mail-Box-3.007/examples/grep.pl" (15 Feb 2019, 936 Bytes) of package /linux/privat/Mail-Box-3.007.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/perl
    2 
    3 # Demonstration of a simple search.
    4 #
    5 # This code can be used and modified without restriction.
    6 # Mark Overmeer, <mailbox@overmeer.net>, 17 feb 2002
    7 # Updated 16 jan 2003 to work more like unix-grep syntax
    8 
    9 use warnings;
   10 use strict;
   11 use lib '..', '.';
   12 
   13 use Mail::Box::Manager 2.008;
   14 use Mail::Box::Search::Grep;
   15 
   16 #
   17 # Get the command line arguments.
   18 #
   19 
   20 die "Usage: $0 pattern mailboxes\n"
   21     unless @ARGV >= 2;
   22 
   23 my ($pattern, @mailboxes) = @ARGV;
   24 
   25 my $mgr = Mail::Box::Manager->new;
   26 
   27 foreach my $mailbox (@mailboxes)
   28 {   my $folder = $mgr->open($mailbox);
   29     unless(defined $folder)
   30     {   warn "*** Cannot open folder $mailbox.\n";
   31         next;
   32     }
   33 
   34     print "*** Scanning through $mailbox\n"
   35        if @mailboxes > 1;
   36 
   37     my $grep = Mail::Box::Search::Grep->new
   38       ( in      => 'MESSAGE'
   39       , match   => qr/$pattern/
   40       , details => 'PRINT'
   41       );
   42 
   43     $grep->search($folder);
   44     $folder->close;
   45 }