2005-06-20 16:56:36 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
check_loop - Detect mail loops
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
This plugin detects loops by counting "Received" and "Delivered-To"
|
|
|
|
header lines. It's a kluge but it duplicates what qmail-smtpd does,
|
|
|
|
and it does at least prevent messages from looping forever.
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
Takes one optional parameter, the maximum number of "hops" ("Received"
|
|
|
|
and lines plus "Delivered-To" lines) allowed. The default is 100, the
|
|
|
|
same as in qmail-smtpd.
|
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
Written by Keith C. Ivey
|
|
|
|
|
|
|
|
=head1 LICENSE
|
|
|
|
|
|
|
|
Released to the public domain, 17 June 2005.
|
|
|
|
|
|
|
|
=cut
|
2007-09-03 17:47:08 +02:00
|
|
|
|
2006-01-25 03:59:31 +01:00
|
|
|
use Qpsmtpd::DSN;
|
2005-06-20 16:56:36 +02:00
|
|
|
|
2006-01-25 03:59:31 +01:00
|
|
|
sub init {
|
2005-06-20 16:56:36 +02:00
|
|
|
my ($self, $qp, @args) = @_;
|
|
|
|
|
|
|
|
$self->{_max_hops} = $args[0] || 100;
|
|
|
|
|
|
|
|
if ( $self->{_max_hops} !~ /^\d+$/ ) {
|
|
|
|
$self->log(LOGWARN, "Invalid max_hops value -- using default");
|
|
|
|
}
|
|
|
|
$self->log(LOGWARN, "Ignoring additional arguments") if @args > 1;
|
|
|
|
}
|
|
|
|
|
2005-07-07 06:17:39 +02:00
|
|
|
sub hook_data_post {
|
2005-06-20 16:56:36 +02:00
|
|
|
my ($self, $transaction) = @_;
|
|
|
|
|
|
|
|
my $hops = 0;
|
|
|
|
$hops++ for $transaction->header->get('Received'),
|
|
|
|
$transaction->header->get('Delivered-To');
|
|
|
|
|
|
|
|
if ( $hops >= $self->{_max_hops} ) {
|
2006-01-25 03:59:31 +01:00
|
|
|
# default of too_many_hops is DENY, see comment in POD of Qpsmtpd::DSN
|
|
|
|
return Qpsmtpd::DSN->too_many_hops();
|
2005-06-20 16:56:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return DECLINED;
|
|
|
|
}
|