All,
I'm about to embark on the process of writing a new corporate spam filter and rather than 're-invent the wheel' I'm thinking of using SpamAssassin as the main engine and write the filter around it. Unfortunately I have not been able to determine exactly how to do this with a perl based sendmail milter, specifically PerlMx… (Note: I've got to use PerlMx as it's being used for another project, so now that it's been purchased they want to best use made out of it. I'd rather use MIMEDefang but there ya go...)
Searching the archives I did find the following, written by Matt Sergeant on 14th Nov 2001:
> This should be really trivial with Sendmail::Milter and the new alternate
> message class system.
>
> Just write a Milter class with something like what's below. Filling in the
> missing bits and writing MyMessageClass.pm and MySAMessageClass.pm is left
> as an exercise (it's really easy, but ask if you need more help).
>
> NB: I wrote this in about 2 minutes while composing this email. It's
> guaranteed not to work right, as I've never used Milter, but it looks really
> trivial, so someone should pick this up and run with it.
>
> use Sendmail::Milter;
> use Mail::SpamAssassin;
> use MyMessageClass;
> use MySAMessageClass;
>
> my %my_milter_callbacks =
> (
> connect => \&connect,
> header => \&header_cb,
> body => \&body_cb,
> eom => \&process_spam,
> );
>
> my $current_msg;
>
> sub connect {
> $current_msg = MyMessageClass->new();
> }
>
> sub header_cb {
> my ($ctx, $header, $value) = @_;
> # maybe do: $value =~ s/[\r\n]+\s*/ /g; # fold continuations
> $current_msg->set_header($header => $value);
> }
>
> sub body_cb {
> my ($ctx, $body_part, $len) = @_;
> $current_msg->add_body_part($body_part);
> }
>
> sub process_spam {
> my $spam_test = Mail::SpamAssassin->new({
> use_my_mail_class => 'MySAMessageClass' }
> );
> my $status = $spam_test->check($current_msg);
> if ($status->is_spam) {
> # treat as spam accordingly
> }
> else {
> # treat as non-spam
> }
> }
>
> BEGIN {
> Sendmail::Milter::auto_setconn("spamassassin");
> Sendmail::Milter::register(
> spamassassin => \%my_milter_callbacks,
> SMFI_CURR_ACTS,
> );
> Sendmail::Milter::main();
> }
>
Unfortunately my knowledge of OO programming is non-existent and my module writing is not much better! Could someone fill in the gaps for me? Specifically the 'MyMessageClass.pm' and 'MySAMessageClass.pm' modules. I've had a bit of a go at it myself but I'm being pushed into timescales that don't allow for the learning curve involved.
Any help would be greatly appreciated.
Thank you,
Ian Marsh
Internet Services Team
Hampshire County Council