From e2ee6f13e5d0e2f064143479193fbe4bbc8aeaf8 Mon Sep 17 00:00:00 2001 From: Johan Almqvist Date: Sun, 11 Jul 2010 17:28:58 -0700 Subject: new plugin check_badmailfrom_patterns Signed-off-by: Robert --- plugins/check_badmailfrom_patterns | 64 ++++++++++++++++++++++++++++++++++++ 1 files changed, 64 insertions(+), 0 deletions(-) create mode 100644 plugins/check_badmailfrom_patterns diff --git a/plugins/check_badmailfrom_patterns b/plugins/check_badmailfrom_patterns new file mode 100644 index 0000000..528e49d --- /dev/null +++ b/plugins/check_badmailfrom_patterns @@ -0,0 +1,64 @@ +#!/usr/bin/perl + +=pod + +=head1 SYNOPSIS + +This plugin checks the badmailfrom_patterns config. This allows +special patterns to be denied (e.g. FQDN-VERP, percent hack, bangs, +double ats). + +=head1 CONFIG + +Configuration is placed in the following file: + +F + +Patterns are stored in the format pattern\sresponse, where pattern +is a Perl pattern expression. Don't forget to anchor the pattern +(front ^ and back $) if you want to restrict it from matching +anywhere in the string. + + ^streamsendbouncer@.*\.mailengine1\.com$ Your right-hand side VERP doesn't fool me + ^return.*@.*\.pidplate\.biz$ I don' want it regardless of subdomain + ^admin.*\.ppoonn400\.com$ + +=head1 AUTHOR + +Johan Almqvist based on L + +This software is free software and may be distributed under the same +terms as qpsmtpd itself. + +=cut + +sub hook_mail { + my ($self, $transaction, $sender, %param) = @_; + + my @badmailfrom = $self->qp->config("badmailfrom_patterns") + or return (DECLINED); + + return (DECLINED) if ($sender->format eq "<>"); + + my $host = lc $sender->host; + my $from = lc($sender->user) . '@' . $host; + + for (@badmailfrom) { + my ($pattern, $response) = split /\s+/, $_, 2; + next unless $from =~ /$pattern/; + $response = "Your envelope sender is in my badmailfrom_patterns list" + unless $response; + $transaction->notes('badmailfrom_patterns', $response); + } + return (DECLINED); +} + +sub hook_rcpt { + my ($self, $transaction, $rcpt, %param) = @_; + my $note = $transaction->notes('badmailfrom_patterns'); + if ($note) { + $self->log(LOGINFO, $note); + return (DENY, $note); + } + return (DECLINED); +} -- 1.7.2.2