In other news,
I also wrote a subject blocking plugin a while back called
"check_subject" that uses two config files, one matching subjects with
bad words in them and the other matching subjects from the more popular
viruses.
I disabled warnings to avoid filling my logs with pattern matching
errors. If others have suggestions as to the safe perl mechanisms for
proper pattern matching from values in a file, let me know.
Here's my source (wrapped properly to fit in this email):
-----------------------------------------------------------------------
# This plugin rejects based on pattern matches in the subject
#
# Your config files are badsubject and badsubjectv (for viri)
no warnings;
sub register {
my ($self, $qp) = @_;
$self->register_hook("data_post", "mail_handler");
}
sub mail_handler {
my ($self, $transaction) = @_;
my $connection = $self->qp->connection;
my $sender = $transaction->sender;
my $from = lc($sender->user . '@' . $sender->host);
my @badsubject = $self->qp->config("badsubject");
my @badsubjectv = $self->qp->config("badsubjectv");
my $subject = $transaction->header->get('Subject') || '';
my $whitelist = $connection->notes('whitelisthost') ||
$transaction->notes('whitelistrcpt') ||
$transaction->notes('whitelistsender');
if ($whitelist) {
$self->log(LOGWARN,
"Whitelist overrode check_subject: $whitelist");
return DECLINED;
}
if ($subject) {
for my $badsubjectv (@badsubjectv) {
if ($subject =~ /^$badsubjectv$/ and
$subject !~ /SpamCop/i) {
$self->log(4,"Message from $from matched $badsubjectv");
return (DENY,
"Message from $from looks like a virus (matched subject).");
}
}
for my $badsubject (@badsubject) {
if (lc($subject) =~ /\b$badsubject\b/i
and $subject !~ /SpamCop/i) {
$self->log(4,"Message from $from matched $badsubject");
return (DENY,
"Message from $from looks like spam (unacceptable words in subject)");
}
}
return (DECLINED);
}
return (DECLINED);
}
# You can fix the indentation on the "Message from" lines as you
# see fit.
# -- Bryan