Mail::Lite::Processor -- processing (identifying, parsing, extracting data from) mail-like message (also Jabber and so on)
use Data::Dumper; use Mail::Lite::Processor; my $message = new Mail::Lite::Message( do { local $/; <DATA> } ); my $processor = new Mail::Lite::Processor( rules => [ { id => 'fail', match => [ { subject => 'FAILED' } ] }, { id => 'success', match => [ { subject => 'SUCCESS' } ], processors => [ { processor => 'regexp', regexps => { 'status=~body,once' => 'Status: (.*)', }, } ] }, ], ); $processor->process( message => $message, handler => sub { warn Dumper \@_ }, ); __DATA__ From test@cpan.org Subject: SUCCESS Status: all your base are belong to us __END__
A lot of data comes in mails, so you just have to read them and parse.
In order to automate the process of identifying mails and fetching some data was created this module. One can use it to parse mails from various bots, standarterized (and not) responces and so on. Author uses it primary for parsing mails from RU TLD registry.
Processing of message is done by list of rules. Each rule have implicit internal processor -- 'match', which is checks if message fits to this rule. If so, then a list of 'processors' is executed. After that user-supported handler is called with results from all these processors. Note that by default all the matched rules are treated and copy of message is processed with each of them. You can change this behaviour by specifiyng 'last' in rule specification.
As sometimes there is info about many objects in single message, there is way to split and then identify and parse parts independently. See Mail::Lite::Processor::Split, Mail::Lite::Processor::Chain.
For further info about:
matching processor see Mail::Lite::Processor::Match
regexp processor see Mail::Lite::Processor::Regexp
split_msg processor see Mail::Lite::Processor::SplitMsg
parse_rfc822 processor see Mail::Lite::Processor::ParseRfc822
chain processor see Mail::Lite::Processor::Chain
filter processor see Mail::Lite::Processor::Filter
stub processor see Mail::Lite::Processor::Stub
An object of this class represents instance of processor which maintains it own set of rules for processing.
Create new processor instance with rules arrayref, which will call handler sub for each processed message. Optionally you can set debug level.
Process message within this processor, call handler.
Same as above, but create instance for given rules.
A list of every error and warning message that the module can generate (even the ones that will "never happen"), with a full explanation of each problem, one or more likely causes, and any suggested remedies.
A full explanation of any configuration system(s) used by the module, including the names and locations of any configuration files, and the meaning of any environment variables or properties that can be set. These descriptions must also include details of any configuration language used.
A list of all the other modules that this module relies upon, including any restrictions on versions, and an indication whether these required modules are part of the standard Perl distribution, part of the module's distribution, or must be installed separately.
A list of any modules that this module cannot be used in conjunction with. This may be due to name conflicts in the interface, or competition for system or program resources, or due to internal limitations of Perl (for example, many modules that use source code filters are mutually incompatible).
A list of known problems with the module, together with some indication whether they are likely to be fixed in an upcoming release.
Also a list of restrictions on the features the module does provide: data types that cannot be handled, performance issues and the circumstances in which they may arise, practical limitations on the size of data sets, special cases that are not (yet) handled, etc.
The initial template usually just has:
There are no known bugs in this module. Please report problems to <Maintainer name(s)> (<contact address>) Patches are welcome.
Pavel Boldin (davinchi@cpan.org)
Copyright (c) 2009 (davinchi@cpan.org). All rights reserved.
Followed by whatever licence you wish to release it under. For Perl code that is often just:
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perldoc perlartistic.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
To install Mail::Lite, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mail::Lite
CPAN shell
perl -MCPAN -e shell install Mail::Lite
For more information on module installation, please visit the detailed CPAN module installation guide.