Modular mimedefang-filter

This describes the modular mimedefang-filter that we have created at XS4ALL, to be used with MIMEDefang.

Here are the slides of a talk I gave at the NLUUG conference on Email and beyond, may 26 in the netherlands, and also at YAPC::EU 2005 in Braga.

To use this, download the example distribution here:
mimedefang-modular-example.tar.gz
Unpack in a separate directory (the example uses /usr/local/etc/mimedefang, but you can use any path as long as you change the use lib statement in the mimedefang-filter-select file).

Then change mimedefang to use mimedefang-filter-select as the "filter". Use the "-F" option to mimedefang-multiplexor or set the SUBFILTER setting in mimedefang.conf.

UPDATE. To support a few newer features of mimedefang, there are some updates to the files in the distribution above. These can be found in this archive: mimedefang-modular-20061110.tar.gz. The files in the 20061110 version are replacements for the files in the original distribution.

This example is pretty much the same as the suggested-minimum-filter-for-windows-clients that is supplied as an example to mimedefang, except that it is split up into multiple independent modules.

Note that the suggested-minimum-filter-for-windows-clients that is modified here, is taken from an older version of mimedefang (2.49). It does not correspond to the latest filter as distributed with mimedefang itself. The whole point of this framework is to allow you to write your own filter, from scratch. The suggested minimum filter is only used as an example of what it would look like.

The distribution contains these files:

mimedefang-filter-select
This file just loops over all filters specified in the @FilterModules in MailFilter::Settings, and on the filter_begin() call, calls each filter_begin() in all the modules, on the filter() call, calls each modules' filter(), etc etc.
Mimedefang.pm
This library is a helper that exports MIMEDefang functions and globals to each package, as requested. This is somewhat messy because MIMEDefang globals and functions live in main::, not in package Mimedefang, but it solves it by first importing all necessary MIMEDefang globals/functions into its own package. This is only compile-time overhead, not run time.
MailFilter/Settings.pm
The file that contains a list of modules to call, and some various other settings that were at the beginning of the suggested-minimum-filter-for-windows-clients file.
MailFilter/Anomy.pm
Fixup HTML using Anomy.
MailFilter/BadFilename.pm
Block bad filenames.
MailFilter/BlockPartial.pm
Block message/partial.
MailFilter/LogMailIn.pm
Log incoming mails via graphdefang.
MailFilter/QuarantineNotifications.pm
Send quarantine notifications
MailFilter/RebuildMIME.pm
Force rebuilding of all MIME parts.
MailFilter/SpamAssassin.pm
Filter spam using spamassassin.
MailFilter/StripUselessHTML.pm
Strip useless HTML parts.
MailFilter/SuspiciousChars.pm
Block mails with suspicious characters in the header.
MailFilter/Virusscan.pm
Block viruses.