Author: NealePickett
This script was written for use with this setup, but should be usable with any other MDA.
It first checks the recipient address to see if it's of the form spam-user@ or ham-user@, extracting the user that way if so. Otherwise it uses the sender's address as the user. Then it goes through the message, looking for tokens, and passing them into dspam. Future releases of dspam may obviate this script entirely.
#! /usr/bin/perl
# Get arguments
$class = $ARGV[0] || die; shift;
$sender = $ARGV[0] || die; shift;
$recip = $ARGV[0] || die; shift;
if ($recip =~ /^(spam|ham)-(\w+)@/) {
# username is part of the recipient
$user = $2;
} elsif ($sender =~ /^(\w+)@/) {
# username is in the sender
$user = $1;
} else {
print "Can't determine user\n";
exit 75; # EX_TEMPFAIL
}
# Pull out DSPAM signatures and send them to the dspam program
while (<>) {
if ((! $subj) && (/^Subject: /)) {
$subj = $_;
} elsif (/(!DSPAM:[a-f0-9]+!)/) {
open(F, "|/usr/local/bin/dspam --source=error --class=$class --user $user");
print F "$subj\n$1\n";
close(F);
} elsif (/(X-DSPAM-Signature: [a-f0-9]+)/) {
open(F, "|/usr/local/bin/dspam --source=error --class=$class --user $user");
print F "$subj\n$1\n";
close(F);
}
}
