2012-06-22 11:38:01 +02:00
|
|
|
#!perl -w
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2012-06-28 01:17:01 +02:00
|
|
|
bogus_bounce - Check that a bounce message isn't bogus
|
2012-06-22 11:38:01 +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/
|
2012-06-22 11:38:01 +02:00
|
|
|
|
2013-03-11 04:38:03 +01:00
|
|
|
2013 - Matt Simerson - added Return Path check
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
2013-03-11 04:38:03 +01:00
|
|
|
|
2012-06-22 11:38:01 +02:00
|
|
|
sub register {
|
2012-06-23 06:32:40 +02:00
|
|
|
my ($self, $qp) = (shift, shift);
|
2012-06-22 11:38:01 +02:00
|
|
|
|
2012-06-23 06:32:40 +02:00
|
|
|
if ( @_ % 2 ) {
|
|
|
|
$self->{_args}{action} = shift;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$self->{_args} = { @_ };
|
|
|
|
};
|
2012-06-22 11:38:01 +02:00
|
|
|
|
2012-06-23 06:32:40 +02:00
|
|
|
if ( ! defined $self->{_args}{reject} ) {
|
|
|
|
$self->{_args}{reject} = 0; # legacy default
|
|
|
|
};
|
|
|
|
|
|
|
|
# we only need to check for deferral, default is DENY
|
|
|
|
if ( $self->{_args}{action} =~ /soft/i ) {
|
|
|
|
$self->{_args}{reject_type} = 'temp';
|
2012-06-22 11:38:01 +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.
|
2012-06-22 11:38:01 +02:00
|
|
|
#
|
|
|
|
my $sender = $transaction->sender->address || undef;
|
2012-06-23 06:32:40 +02:00
|
|
|
if ( $sender && $sender ne '<>') {
|
|
|
|
$self->log(LOGINFO, "pass, not a null sender");
|
|
|
|
return DECLINED;
|
|
|
|
};
|
2012-06-22 11:38:01 +02:00
|
|
|
|
2013-03-11 04:38:03 +01:00
|
|
|
# at this point we know it is a bounce, via the null-envelope.
|
2012-06-22 11:38:01 +02:00
|
|
|
#
|
2013-03-11 04:38:03 +01:00
|
|
|
# Count the recipients. Valid bounces have a single recipient
|
2012-06-22 11:38:01 +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));
|
|
|
|
return $self->get_reject( "fail, this bounce message does not have 1 recipient" );
|
2012-06-23 06:32:40 +02:00
|
|
|
};
|
2012-06-22 11:38:01 +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');
|
|
|
|
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)" );
|
|
|
|
};
|
2012-06-22 11:38:01 +02:00
|
|
|
|
2013-03-11 04:38:03 +01:00
|
|
|
$self->log(LOGINFO, "pass, single recipient, empty Return-Path");
|
|
|
|
return DECLINED;
|
2012-06-22 11:38:01 +02:00
|
|
|
}
|