| Courier-Filter documentation | Contained in the Courier-Filter distribution. |
Courier::Filter::Module - Abstract Perl base class for filter modules used by the Courier::Filter framework
use Courier::Filter::Module::My; # Need to use a non-abstract sub-class.
my $module = Courier::Filter::Module::My->new(
logger => $logger,
inverse => 0,
trusting => 0,
testing => 0,
debugging => 0
);
my $filter = Courier::Filter->new(
...
modules => [ $module ],
...
);
package Courier::Filter::Module::My;
use base qw(Courier::Filter::Module);
Sub-classes of Courier::Filter::Module are used by the Courier::Filter mail filtering framework to determine the acceptability of messages. See Courier::Filter::Overview for an overview of how filter modules are used and for how to write them.
When overriding a method in a derived class, do not forget calling the inherited method from your overridden method.
The following constructor is provided and may be overridden:
Creates a new filter module using the %options. Initializes the filter module, by opening I/O handles, connecting to databases, creating temporary files, initializing parser libraries, etc..
%options is a list of key/value pairs representing any of the following options:
A Courier::Filter::Logger object that will be used for logging message rejections and error messages caused by this individual filter module. If no logger is specified, Courier::Filter's global logger will be used.
A boolean value controlling whether the filter module should operate with
inverse polarity (true) as opposed to normal polarity (false). Under
inverse polarity, the result of the match method is negated by the
consider method before returning it. For details on how Courier::Filter
translates match results into acceptability results, see
"How filter modules work" in Courier::Filter::Overview. Defaults to false.
A boolean value controlling whether the filter module should not be applied
to trusted messages. For details on how the trusted status is determined, see
the description of the trusted property in Courier::Message. In most
configurations, this option can be used to white-list so-called outbound
messages. Defaults to false.
A boolean value controlling whether the filter module should run in testing mode. In testing mode, planned message rejections will be logged as usual, but no messages will actually be rejected. Defaults to false.
A boolean value controlling whether the filter module should log extra debugging information. Defaults to false.
Derived classes may support additional options.
Courier::Filter::Module::new() creates a hashref as an object of the invoked
class, and stores the %options in it, but does nothing else.
The following destructor is provided and may be overridden:
Uninitializes the filter module, by closing I/O handles, disconnecting from databases, deleting temporary files, uninitializing parser libraries, etc..
Courier::Filter::Module::destroy() does nothing. Sub-classes may override
this method and define clean-up behavior.
The following class methods are provided and may be overridden:
Writes a warning message to syslog. This method may also be used as an instance method.
The following instance methods are provided and may be overridden:
Calls the match method, passing it the $message object. Returns the result
of match, negating it beforehand if the filter module has inverse polarity.
There is usually no need at all to override this method.
Examines the Courier::Message object given as $message. Returns a so-called match result consisting of an SMTP status response text, and an optional numerical SMTP status response code. For details about how match results are used by Courier::Filter, see "How filter modules work" in Courier::Filter::Overview and "Writing filter modules" in Courier::Filter::Overview.
Courier::Filter::Module::match() does nothing and returns undef.
Sub-classes should override this method and define their own matching rule.
If $logger is specified, installs a new logger for this individual filter
module. Returns the current (new) logger.
Returns a boolean value indicating whether the filter module is operating with
inverse polarity, as set through the constructor's inverse option.
Returns a boolean value indicating whether the filter module does not apply
to trusted messages, as set through the constructor's trusting option.
Returns a boolean value indicating whether the filter module is in testing
mode, as set through the constructor's testing option.
If $debugging is specified, sets the debugging mode for this individual
filter module. Returns the (newly) configured debugging mode.
Courier::Filter, Courier::Filter::Module.
For a list of prepared loggers that come with Courier::Filter, see "Bundled Courier::Filter loggers" in Courier::Filter::Overview.
For AVAILABILITY, SUPPORT, and LICENSE information, see Courier::Filter::Overview.
Julian Mehnle <julian@mehnle.net>
| Courier-Filter documentation | Contained in the Courier-Filter distribution. |
# # Courier::Filter::Module abstract base class # # (C) 2003-2008 Julian Mehnle <julian@mehnle.net> # $Id: Module.pm 210 2008-03-21 19:30:31Z julian $ # ###############################################################################
package Courier::Filter::Module; use warnings; use strict; use Error ':try'; use Courier::Error; use constant TRUE => (0 == 0); use constant FALSE => not TRUE;
# Implementation: ###############################################################################
sub new { my ($class, %options) = @_; $class ne __PACKAGE__ or throw Courier::Error('Unable to instantiate abstract ' . __PACKAGE__ . ' class'); my $self = { %options }; return bless($self, $class); }
sub destroy { my ($object) = @_; return; }
sub warn { my ($self, $text) = @_; my $class = ref($self) || $self; STDERR->printf("%s: Warning: %s\n", $class, $text); return; }
sub consider { my ($self, $message) = @_; my ($result, @code) = $self->match($message); ($result, @code) = ($result ? '' : undef) if $self->inverse; return ($result, @code); }
sub match { my ($self, $message) = @_; return undef; }
sub logger { my ($self, @logger) = @_; $self->{logger} = $logger[0] if @logger; return $self->{logger}; }
sub inverse { my ($self) = @_; # Read-only! return ($self->{inverse}); }
sub trusting { my ($self) = @_; # Read-only! return $self->{trusting}; }
sub testing { my ($self) = @_; # Read-only! return $self->{testing}; }
sub debugging { my ($self, @debugging) = @_; $self->{debugging} = $debugging[0] if @debugging; return $self->{debugging}; }
BEGIN { no warnings 'once'; *DESTROY = \&destroy; }
TRUE;