Courier::Filter
Purely Perl-based mail filter framework for the Courier MTA
- Provided by: courier-filter-perl (Version: 0.200+ds-4)
- Report a bug
Purely Perl-based mail filter framework for the Courier MTA
0.200
use Courier::Filter;
use Courier::Filter::Logger::Moo;
use Courier::Filter::Module::Foo;
use Courier::Filter::Module::Bar;
my $filter = Courier::Filter->new(
mandatory => 1,
logger => Courier::Filter::Logger::Moo->new( ... ),
modules => [
Courier::Filter::Module::Foo->new( ... ),
Courier::Filter::Module::Bar->new( ... )
],
testing => 0,
debugging => 0
);
my $exit_code = $filter->run() || 0;
exit($exit_code);
For an architectural and administrative overview of the Courier::Filter framework, see Courier::Filter::Overview.
The Courier::Filter class is the heart of the Courier::Filter framework. To drive a courierfilter filter process, create a Courier::Filter object, passing the filter modules and loggers you want to use to the constructor, and call the "run()" method.
Courier::Filter will then take care of creating the courierfilter socket in the right place in a safe manner, listening for connections from Courier, asking filter modules for consideration of messages, notifying Courier of whether messages should be accepted or rejected, logging message rejections, catching and logging errors, and finally removing the socket when being terminated by Courier.
The following constructor is provided:
%options is a list of key/value pairs representing any of the following options:
For instance, given the following filter module group:
[$m1, $m2, [$m3, [$m4, $m5]], $m6]
Courier::Filter queries the filter modules in ascending order from 1 to 6.
The acceptability result returned by each module determines how Courier::Filter proceeds with considering the current message:
For instance, take the nested filter module group from above:
[$m1, $m2, [$m3, [$m4, $m5]], $m6]
| | '---g3---'| |
| '----group 2----' |
'------------group 1-------------'
Let's assume Courier::Filter queries the filter module $m3. If $m3 states an explicit reject, the consideration process is aborted and the current message is rejected. If $m3 states an implicit accept, Courier::Filter proceeds to $m4. If $m3 states an explicit accept, the rest of group 2 (including all of group 3) is skipped and the acceptability result of group 2 is assumed an implicit accept, so Courier::Filter proceeds to $m6.
If no explicit reject has occured when Courier::Filter reaches the end of the main module group, or a module in the main group states an explicit accept, the message is accepted.
Using nested groups of filter modules with normal or inverse polarity, it should be possible to implement sufficiently complex filtering policies to satisfy very most needs.
NOTE: You may also enable testing mode on individual filter module objects, see "new" in Courier::Filter::Module. Enabling testing mode globally is not the same as individually enabling testing mode on all filter modules, though. When global testing mode is enabled, Courier::Filter only ignores the final result, but still follows the rules of the normal consideration process, e.g. aborting as soon as a filter module states an explicit reject, etc. When an individual filter module is in testing mode, its individual result is ignored, and the consideration process is continued with the next filter module. So individually enabling testing mode on all filter modules allows you to thoroughly test the correctness and performance of all installed filter modules, or even to gather stochastically indepent statistics on the hit/miss rates of your filter modules.
The following instance methods are provided:
courier-filter-perl, Courier::Filter::Overview, Courier::Filter::Module, Courier::Filter::Logger
For AVAILABILITY, SUPPORT, and LICENSE information, see Courier::Filter::Overview.
Julian Mehnle <julian@mehnle.net>