qpsmtpd/plugins/check_loop
Robert Spier 90daeb3786 r483@dog: rspier | 2005-07-06 21:17:00 -0700
The great plugin renaming in the name of inheritance and standardization commit.
 
 1. new concept of standard hook_ names.
 2. Plugin::init
 3. renamed many subroutines in plugins (and cleaned up register subs)
 4. updated README.plugins
 


git-svn-id: https://svn.perl.org/qpsmtpd/trunk@479 958fd67b-6ff1-0310-b445-bb7760255be9
2005-07-07 04:17:39 +00:00

53 lines
1.1 KiB
Perl

#!/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
sub register {
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;
}
sub hook_data_post {
my ($self, $transaction) = @_;
my $hops = 0;
$hops++ for $transaction->header->get('Received'),
$transaction->header->get('Delivered-To');
if ( $hops >= $self->{_max_hops} ) {
return DENY, "Too many hops. This message is looping.";
}
return DECLINED;
}