Courier::Filter::Module::MIMEParts - A MIME part filter module for the Courier::Filter framework
0.1
use Courier::Filter::Module::MIMEParts; my $module = Courier::Filter::Module::MIMEParts->new( max_size => $max_size, signatures => [ { # One or more of the following options: mime_type => 'text/html' || qr/html/, file_name => 'file_name.ext' || qr/\.(exe|com|pif|lnk)$/, size => 106496, digest_md5 => 'b09e26c292759d654633d3c8ed00d18d', # Optionally: response => $response_text }, ... ], logger => $logger, inverse => 0, trusting => 0, testing => 0, debugging => 0 ); my $filter = Courier::Filter->new( ... modules => [ $module ], ... );
This class is a filter module class for use with Courier::Filter. It matches a message if one of the message's MIME parts matches one of the configured signatures.
The following constructor is provided:
Creates a new MIMEParts filter module.
%options is a list of key/value pairs representing any of the following options:
An integer value controlling the maximum size (in bytes) of the overall message text for a message to be processed by this filter module. Messages larger than this value will never be processed, and thus will never match. If undef, there is no size limit. Defaults to undef.
As MIME processing is completely done in-memory in this version of the filter module, you should definitely restrict the message size to some sensible value that easily fits in your server's memory. 1024**2 (1MB) should be appropriate for most uses of this filter module.
REQUIRED. A reference to an array containing the list of signatures against which messages' MIME parts are to be matched. A signature in turn is a reference to a hash containing one or more so-called signature aspects (as key/value pairs). Aspects may either be scalar values (for exact, case-sensitive matches), or regular expression objects created with the qr// operator (for inexact, partial matches).
qr//
For a signature to match a MIME part, all of the signature's aspects must match those of the MIME part. For the filter module to match a message, any of the signatures must match any of the message's MIME parts.
An aspect can be any of the following:
The MIME type of the MIME part ('type/sub-type').
The file name of the MIME part.
The exact size (in bytes) of the decoded MIME part.
The MD5 digest of the decoded MIME part (32 hex digits, as printed by `md5sum`).
Every signature may also contain a response option containing a string that is to be returned as the match result in case of a match. Defaults to "Prohibited MIME part detected.".
response
So for instance, a signature list could look like this:
signatures => [ { mime_type => qr/html/, response => 'No HTML mail, please.' }, { file_name => qr/\.(exe|com|pif|lnk)$/, response => 'Executable content detected' }, { size => 106496, digest_md5 => 'b09e26c292759d654633d3c8ed00d18d', response => 'Worm detected: W32.Swen' }, { size => 22528, response => 'Worm suspected: W32.Mydoom' } ]
All options of the Courier::Filter::Module constructor are also supported. Please see "new()" in Courier::Filter::Module for their descriptions.
See "Instance methods" in Courier::Filter::Module for a description of the provided instance methods.
Courier::Filter::Module, Courier::Filter::Overview.
For AVAILABILITY, SUPPORT, COPYRIGHT, and LICENSE information, see Courier::Filter::Overview.
Julian Mehnle <julian@mehnle.net>
To install Courier::Filter, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Courier::Filter
CPAN shell
perl -MCPAN -e shell install Courier::Filter
For more information on module installation, please visit the detailed CPAN module installation guide.