qpsmtpd/plugins/check_badmailfrom_patterns
Robert 61de599c1b Normalize #! lines on all plugins
find . -type f | xargs -n1 perl -pi.bak -0777 -e '$want = "#!perl -Tw"; s/\A#!.*\n/$want\n/; s/\A([^#])/$want\n\1/s'
2012-04-28 20:41:31 -07:00

65 lines
1.7 KiB
Perl

#!perl -Tw
=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<config/badmailfrom_patterns>
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 <johan-qpsmtpd@almqvist.net> based on L<check_badmailfrom>
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);
}