| 1 |
#!perl -w |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
bogus_bounce - Check that a bounce message isn't bogus |
| 6 |
|
| 7 |
=head1 DESCRIPTION |
| 8 |
|
| 9 |
This plugin is designed to reject bogus bounce messages. |
| 10 |
|
| 11 |
In our case a bogus bounce message is defined as a bounce message |
| 12 |
which has more than a single recipient. |
| 13 |
|
| 14 |
=head1 CONFIGURATION |
| 15 |
|
| 16 |
Only a single argument is recognized and is assumed to be the default |
| 17 |
action. Valid settings are: |
| 18 |
|
| 19 |
=over 8 |
| 20 |
|
| 21 |
=item log |
| 22 |
|
| 23 |
Merely log the receipt of the bogus bounce (the default behaviour). |
| 24 |
|
| 25 |
=item deny |
| 26 |
|
| 27 |
Deny with a hard error code. |
| 28 |
|
| 29 |
=item denysoft |
| 30 |
|
| 31 |
Deny with a soft error code. |
| 32 |
|
| 33 |
=back |
| 34 |
|
| 35 |
=head1 AUTHOR |
| 36 |
|
| 37 |
2010 - Steve Kemp - http://steve.org.uk/Software/qpsmtpd/ |
| 38 |
|
| 39 |
2013 - Matt Simerson - added Return Path check |
| 40 |
|
| 41 |
=cut |
| 42 |
|
| 43 |
sub register { |
| 44 |
my ($self, $qp) = (shift, shift); |
| 45 |
|
| 46 |
if (@_ % 2) { |
| 47 |
$self->{_args}{action} = shift; |
| 48 |
} |
| 49 |
else { |
| 50 |
$self->{_args} = {@_}; |
| 51 |
} |
| 52 |
|
| 53 |
if (!defined $self->{_args}{reject}) { |
| 54 |
$self->{_args}{reject} = 0; # legacy default |
| 55 |
} |
| 56 |
|
| 57 |
# we only need to check for deferral, default is DENY |
| 58 |
if ($self->{_args}{action} && $self->{_args}{action} =~ /soft/i) { |
| 59 |
$self->{_args}{reject_type} = 'temp'; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
sub hook_data_post { |
| 64 |
my ($self, $transaction) = (@_); |
| 65 |
|
| 66 |
# |
| 67 |
# Find the sender, quit processing if this isn't a bounce. |
| 68 |
# |
| 69 |
my $sender = $transaction->sender->address || undef; |
| 70 |
if ($sender && $sender ne '<>') { |
| 71 |
$self->log(LOGINFO, "pass, not a null sender"); |
| 72 |
return DECLINED; |
| 73 |
} |
| 74 |
|
| 75 |
# at this point we know it is a bounce, via the null-envelope. |
| 76 |
# |
| 77 |
# Count the recipients. Valid bounces have a single recipient |
| 78 |
# |
| 79 |
my @to = $transaction->recipients || (); |
| 80 |
if (scalar @to != 1) { |
| 81 |
$self->log(LOGINFO, "fail, bogus bounce to: " . join(',', @to)); |
| 82 |
return $self->get_reject( |
| 83 |
"fail, this bounce message does not have 1 recipient"); |
| 84 |
} |
| 85 |
|
| 86 |
# validate that Return-Path is empty, RFC 3834 |
| 87 |
|
| 88 |
my $rp = $transaction->header->get('Return-Path'); |
| 89 |
if ($rp && $rp ne '<>') { |
| 90 |
$self->log(LOGINFO, |
| 91 |
"fail, bounce messages must not have a Return-Path"); |
| 92 |
return $self->get_reject( |
| 93 |
"a bounce return path must be empty (RFC 3834)"); |
| 94 |
} |
| 95 |
|
| 96 |
$self->log(LOGINFO, "pass, single recipient, empty Return-Path"); |
| 97 |
return DECLINED; |
| 98 |
} |