Spam actions when destinations have different thresholds
Julian Field
MailScanner at ecs.soton.ac.uk
Fri Jul 29 09:39:26 IST 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 29 Jul 2005, at 08:20, Matt Hampton wrote:
> Julian Field wrote:
>
>
>> I have got some code somewhere that shows you how to remove
>> recipients individually from a sendmail message in MailScanner.
>> You could use that in a Custom Function on "Spam Actions" to
>> remove a set of users which you work out somehow.
>>
>
> That would be very much appreciated........
This code has some calls to a couple of bits of other code in it, but
it is pretty obvious what it does. It's from our Custom Function to
auto-delete spam for individual users at the gateway.
It calls Address2Threshold which takes an email address and returns
the Required SpamAssassin Score value for that email address.
my($message) = @_;
my($to, $action, $lowercase, $changed, %recips);
return 'deliver' unless $message;
return 'deliver' unless @{$message->{to}};
$action = 'deliver';
# Build the hash of recipients and say we have not changed anything
$changed = 0;
foreach $to (@{$message->{to}}) {
$lowercase = lc($to); # To avoid occasional bug in Perl
$recips{$lowercase} = 1;
}
foreach $to (@{$message->{to}}) {
$lowercase = lc($to);
#if (exists $ECSthresholds{$lowercase}) {
if (defined(Address2Threshold($lowercase))) {
delete $recips{$lowercase};
MailScanner::Log::InfoLog("ECSthresholds: Deleting user %s",
$lowercase);
$changed = 1;
}
}
# If nothing has changed, just deliver the message
unless ($changed) {
MailScanner::Log::InfoLog("ECSthresholds: Returning action
deliver %s",
join(',',@{$message->{touser}}));
return 'deliver';
}
my(@newto, @newtodomain, @newtouser);
my($user, $domain);
# Have we deleted all the recipients?
@newto = keys %recips;
unless (@newto) {
MailScanner::Log::InfoLog("ECSthresholds: Returning action
delete " .
"for all recipients: %s", join(',',@{$message->
{touser}}));
return 'delete';
}
# We know we have deleted some of the recipients but not all.
# Delete the recipients from the message, add the new list back in,
# then setup all the message data structures for the new recipient
list.
$global::MS->{mta}->DeleteRecipients($message);
$global::MS->{mta}->AddRecipients($message, @newto);
# Work out the user @ domain components
foreach $to (@newto) {
($user, $domain) = MailScanner::Message::address2userdomain($to);
push @newtouser, $user;
push @newtodomain, $domain;
}
#Now push the new recipients details back into the message structures
@{$message->{to}} = @newto;
@{$message->{touser}} = @newtouser;
@{$message->{todomain}} = @newtodomain;
MailScanner::Log::InfoLog("ECSthresholds: Reducing recipient list
to %s",
join(',',@{$message->{touser}}));
return 'deliver';
}
>
> ------------------------ MailScanner list ------------------------
> To unsubscribe, email jiscmail at jiscmail.ac.uk with the words:
> 'leave mailscanner' in the body of the email.
> Before posting, read the Wiki (http://wiki.mailscanner.info/) and
> the archives (http://www.jiscmail.ac.uk/lists/mailscanner.html).
>
> Support MailScanner development - buy the book off the website!
>
- --
Julian Field
www.MailScanner.info
Buy the MailScanner book at www.MailScanner.info/store
PGP footprint: EE81 D763 3DB0 0BFD E1DC 7222 11F6 5947 1415 B654
-----BEGIN PGP SIGNATURE-----
Version: PGP Desktop 9.0.1 (Build 2185)
iQA/AwUBQunrQBH2WUcUFbZUEQKwMACg0xO3ov1eeYpfAb3wXOOPPri5SDQAoKYy
ze6UZv73y1KJadgf/MX8K29U
=HsX5
-----END PGP SIGNATURE-----
------------------------ MailScanner list ------------------------
To unsubscribe, email jiscmail at jiscmail.ac.uk with the words:
'leave mailscanner' in the body of the email.
Before posting, read the Wiki (http://wiki.mailscanner.info/) and
the archives (http://www.jiscmail.ac.uk/lists/mailscanner.html).
Support MailScanner development - buy the book off the website!
More information about the MailScanner
mailing list