| 1 |
#!perl -w |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
loop - Detect mail loops |
| 6 |
|
| 7 |
=head1 DESCRIPTION |
| 8 |
|
| 9 |
This plugin detects loops by counting "Received" and "Delivered-To" |
| 10 |
header lines. It's a kluge but it duplicates what qmail-smtpd does, |
| 11 |
and it does at least prevent messages from looping forever. |
| 12 |
|
| 13 |
=head1 CONFIGURATION |
| 14 |
|
| 15 |
Takes one optional parameter, the maximum number of "hops" ("Received" |
| 16 |
and lines plus "Delivered-To" lines) allowed. The default is 100, the |
| 17 |
same as in qmail-smtpd. |
| 18 |
|
| 19 |
=head1 AUTHOR |
| 20 |
|
| 21 |
Written by Keith C. Ivey |
| 22 |
|
| 23 |
=head1 LICENSE |
| 24 |
|
| 25 |
Released to the public domain, 17 June 2005. |
| 26 |
|
| 27 |
=cut |
| 28 |
|
| 29 |
use Qpsmtpd::DSN; |
| 30 |
|
| 31 |
sub init { |
| 32 |
my ($self, $qp, @args) = @_; |
| 33 |
|
| 34 |
$self->{_max_hops} = $args[0] || 100; |
| 35 |
|
| 36 |
if ($self->{_max_hops} !~ /^\d+$/) { |
| 37 |
$self->log(LOGWARN, "Invalid max_hops value -- using default"); |
| 38 |
$self->{_max_hops} = 100; |
| 39 |
} |
| 40 |
$self->log(LOGWARN, "Ignoring additional arguments") if @args > 1; |
| 41 |
} |
| 42 |
|
| 43 |
sub hook_data_post { |
| 44 |
my ($self, $transaction) = @_; |
| 45 |
|
| 46 |
my $hops = 0; |
| 47 |
$hops++ |
| 48 |
for $transaction->header->get('Received'), |
| 49 |
$transaction->header->get('Delivered-To'); |
| 50 |
|
| 51 |
if ($hops >= $self->{_max_hops}) { |
| 52 |
|
| 53 |
# default of too_many_hops is DENY, see comment in POD of Qpsmtpd::DSN |
| 54 |
return Qpsmtpd::DSN->too_many_hops(); |
| 55 |
} |
| 56 |
|
| 57 |
return DECLINED; |
| 58 |
} |