Log::Procmail

Perl extension for reading procmail logfiles
Download

Log::Procmail Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Philippe Bruhat
  • Publisher web site:
  • http://search.cpan.org/~book/

Log::Procmail Tags


Log::Procmail Description

Perl extension for reading procmail logfiles Log::Procmail is a Perl module for reading procmail logfiles.Log::ProcmailLog::Procmail reads procmail(1) logfiles and returns the abstracts one by one.$log = Log::Procmail->new( @files ); Constructor for the procmail log reader. Returns a reference to a Log::Procmail object. The constructor accepts a list of file as parameter. This allows you to read records from several files in a row: $log = Log::Procmail->new( "$ENV{HOME}/.procmail/log.2", "$ENV{HOME}/.procmail/log.1", "$ENV{HOME}/.procmail/log", ); When $log reaches the end of the file "log", it doesn't close the file. So, after procmail processes some incoming mail, the next call to next() will return the new records.$rec = $log->next Return a Log::Procmail::Abstract object that represent an entry in the log file. Return undef if there is no record left in the file. When the Log::Procmail object reaches the end of a file, and this file is not the last of the stack, it closes the current file and opens the next one. When it reaches the end of the last file, the file is not closed. Next time the record method is called, it will check again in case new abstracts were appended. Procmail(1) log look like the following: From karen644552@btinternet.com Fri Feb 8 20:37:24 2002 Subject: Stock Market Volatility Beating You Up? (18@2) Folder: /var/spool/mail/book 2840 Some informational messages can be put by procmail(1) in the log file. If the errors attribute is true, these lines are returned one at a time. With errors enabled, you have to check that next() actually returns a Log::Procmail::Abstract object. Here is an example: $log->errors(1); # fetch data while ( $rec = $log->next ) { # if it's an error line if ( !ref $rec ) { # this is not a log, but an informational message # do something with it next; } # normal log processing }$log->push( $file ); Push one or more files on top of the list of log files to examine. When Log::Procmail runs out of abstracts to return (i.e. it reaches the end of the file), it transparently opens the next file (if there is one) and keeps returning new abstracts.$log->errors( ); Set or get the error flag. If set, when the next() method will return the string found in the log file, instead of ignoring it. Be careful: it is a simple string, not a Log::Procmail::Abstract object. Default is to return no error.$fh = $log->fh() Returns the currently opened filehandle, from which the next call to next() will try to read a record.$select = $log->select() Return a IO::Select object that watches the currently opened filehandle. You are not supposed to use add() or remove() on the returned IO::Select object. Additional warning for MSWin32, NetWare, dos, VMS, riscos and beos: on those systems, select() returns undef. (Check ext/IO/t/io_sel.t in the Perl sources for details. Hint: look for the message 4-arg select is only valid on sockets.)Log::Procmail::AbstractLog::Procmail::Abstract is a class that hold the abstract information. Since the abstract hold From, Date, Subject, Folder and Size information, all this can be accessed and modified through the from(), date(), subject(), folder() and size() methods.Log::Procmail::next() returns a Log::Procmail::Abstract object.Log::Procmail::Abstract accessors The Log::Procmail::Abstract object accessors are named from(), date(), subject(), folder() and size(). They return the relevant information when called without argument, and set it to their first argument otherwise. # count mail received per folder while( $rec = $log->next ) { $folder{ $rec->folder }++ } The source() accessor returns the name of the log file or the string representation of the handle, if a filehandle was given.$rec->ymd() Return the date in the form yyyymmmddhhmmss where each field is what you think it is. This method is read-only.EXAMPLESHere is an example procmail biff-like script, courtesy of Ian Langworth: #/usr/bin/perl -w use strict; use Log::Procmail; use constant LOGFILE => "$ENV{HOME}/procmail.log"; use constant VALID_FOLDERS => ; my $format = "\%8s: \%-30.30s / %s\n"; my $log = Log::Procmail->new( LOGFILE ); $log->errors(1); while ( $log->select->can_read ) { my $rec = $log->next; # error? warn "$rec\n", next unless ref $rec; # ignore mailboxes we don't care about next unless grep { $_ eq $rec->folder } @{ VALID_FOLDERS() }; # print data printf $format, From => $rec->from; printf $format, Subject => $rec->subject, $rec->folder; }SYNOPSIS use Log::Procmail; my $log = new Log::Procmail 'procmail.log'; # loop on every abstract while(my $rec = $log->next) { # do something with $rec->folder, $rec->size, etc. } Requirements: · Perl


Log::Procmail Related Software