2012-04-29 10:35:59 +02:00
|
|
|
#!perl -w
|
2010-05-05 00:37:52 +02:00
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2012-06-28 01:17:01 +02:00
|
|
|
bogus_bounce - Check that a bounce message isn't bogus
|
2010-05-05 00:37:52 +02:00
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
This plugin is designed to reject bogus bounce messages.
|
|
|
|
|
|
|
|
In our case a bogus bounce message is defined as a bounce message
|
|
|
|
which has more than a single recipient.
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
Only a single argument is recognized and is assumed to be the default
|
|
|
|
action. Valid settings are:
|
|
|
|
|
|
|
|
=over 8
|
|
|
|
|
|
|
|
=item log
|
|
|
|
|
|
|
|
Merely log the receipt of the bogus bounce (the default behaviour).
|
|
|
|
|
|
|
|
=item deny
|
|
|
|
|
|
|
|
Deny with a hard error code.
|
|
|
|
|
|
|
|
=item denysoft
|
|
|
|
|
|
|
|
Deny with a soft error code.
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
2012-06-23 06:32:40 +02:00
|
|
|
2010 - Steve Kemp - http://steve.org.uk/Software/qpsmtpd/
|
2010-05-05 00:37:52 +02:00
|
|
|
|
2013-03-11 04:38:03 +01:00
|
|
|
2013 - Matt Simerson - added Return Path check
|
2010-05-05 00:37:52 +02:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
sub register {
|
2012-06-23 06:32:40 +02:00
|
|
|
my ($self, $qp) = (shift, shift);
|
2010-05-05 00:37:52 +02:00
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
if (@_ % 2) {
|
2012-06-23 06:32:40 +02:00
|
|
|
$self->{_args}{action} = shift;
|
|
|
|
}
|
|
|
|
else {
|
2013-04-21 06:50:39 +02:00
|
|
|
$self->{_args} = {@_};
|
|
|
|
}
|
2010-05-05 00:37:52 +02:00
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
if (!defined $self->{_args}{reject}) {
|
|
|
|
$self->{_args}{reject} = 0; # legacy default
|
|
|
|
}
|
2012-06-23 06:32:40 +02:00
|
|
|
|
|
|
|
# we only need to check for deferral, default is DENY
|
2013-04-21 06:50:39 +02:00
|
|
|
if ($self->{_args}{action} && $self->{_args}{action} =~ /soft/i) {
|
2012-06-23 06:32:40 +02:00
|
|
|
$self->{_args}{reject_type} = 'temp';
|
2010-05-05 00:37:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub hook_data_post {
|
|
|
|
my ($self, $transaction) = (@_);
|
|
|
|
|
|
|
|
#
|
2013-03-11 04:38:03 +01:00
|
|
|
# Find the sender, quit processing if this isn't a bounce.
|
2010-05-05 00:37:52 +02:00
|
|
|
#
|
|
|
|
my $sender = $transaction->sender->address || undef;
|
2013-04-21 06:50:39 +02:00
|
|
|
if ($sender && $sender ne '<>') {
|
2012-06-23 06:32:40 +02:00
|
|
|
$self->log(LOGINFO, "pass, not a null sender");
|
|
|
|
return DECLINED;
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
2010-05-05 00:37:52 +02:00
|
|
|
|
2013-03-11 04:38:03 +01:00
|
|
|
# at this point we know it is a bounce, via the null-envelope.
|
2010-05-05 00:37:52 +02:00
|
|
|
#
|
2013-03-11 04:38:03 +01:00
|
|
|
# Count the recipients. Valid bounces have a single recipient
|
2010-05-05 00:37:52 +02:00
|
|
|
#
|
|
|
|
my @to = $transaction->recipients || ();
|
2013-03-11 04:38:03 +01:00
|
|
|
if (scalar @to != 1) {
|
|
|
|
$self->log(LOGINFO, "fail, bogus bounce to: " . join(',', @to));
|
2013-04-21 06:50:39 +02:00
|
|
|
return $self->get_reject(
|
|
|
|
"fail, this bounce message does not have 1 recipient");
|
|
|
|
}
|
2010-05-05 00:37:52 +02:00
|
|
|
|
2013-03-11 04:38:03 +01:00
|
|
|
# validate that Return-Path is empty, RFC 3834
|
|
|
|
|
|
|
|
my $rp = $transaction->header->get('Return-Path');
|
2013-04-21 06:50:39 +02:00
|
|
|
if ($rp && $rp ne '<>') {
|
|
|
|
$self->log(LOGINFO,
|
|
|
|
"fail, bounce messages must not have a Return-Path");
|
|
|
|
return $self->get_reject(
|
|
|
|
"a bounce return path must be empty (RFC 3834)");
|
|
|
|
}
|
2010-05-05 00:37:52 +02:00
|
|
|
|
2013-03-11 04:38:03 +01:00
|
|
|
$self->log(LOGINFO, "pass, single recipient, empty Return-Path");
|
|
|
|
return DECLINED;
|
2010-05-05 00:37:52 +02:00
|
|
|
}
|