2012-04-29 05:41:31 +02:00
|
|
|
#!perl -Tw
|
2004-09-25 13:40:43 +02:00
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
check_basicheaders - Make sure both From and Date headers are present, and
|
2007-09-03 17:47:08 +02:00
|
|
|
do optional range checking on the Date header.
|
2004-09-25 13:40:43 +02:00
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
2007-09-03 17:47:08 +02:00
|
|
|
Rejects messages that do not have a From or Date header or are completely
|
2004-09-25 13:40:43 +02:00
|
|
|
empty.
|
|
|
|
|
|
|
|
Can also reject messages where the date in the Date header is more than
|
|
|
|
some number of the days in the past or future.
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
Takes one optional parameter, the number of days in the future or past
|
|
|
|
beyond which to reject messages. (The default is to not reject messages
|
|
|
|
based on the date.)
|
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
Written by Jim Winstead Jr.
|
|
|
|
|
|
|
|
=head1 LICENSE
|
|
|
|
|
|
|
|
Released to the public domain, 26 March 2004.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
use Date::Parse qw(str2time);
|
|
|
|
|
|
|
|
sub register {
|
|
|
|
my ($self, $qp, @args) = @_;
|
|
|
|
|
|
|
|
if (@args > 0) {
|
|
|
|
$self->{_days} = $args[0];
|
2005-06-22 16:08:57 +02:00
|
|
|
$self->log(LOGWARN, "WARNING: Ignoring additional arguments.") if (@args > 1);
|
2004-09-25 13:40:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-07 06:17:39 +02:00
|
|
|
sub hook_data_post {
|
2004-09-25 13:40:43 +02:00
|
|
|
my ($self, $transaction) = @_;
|
|
|
|
|
|
|
|
return (DENY, "You have to send some data first")
|
2006-12-16 12:56:48 +01:00
|
|
|
if $transaction->data_size == 0;
|
2004-09-25 13:40:43 +02:00
|
|
|
|
2010-11-08 22:42:43 +01:00
|
|
|
my $header = $transaction->header;
|
2004-09-25 13:40:43 +02:00
|
|
|
return (DENY, "Mail with no From header not accepted here")
|
2010-11-08 22:42:43 +01:00
|
|
|
unless $header && $header->get('From');
|
2004-09-25 13:40:43 +02:00
|
|
|
|
2010-11-08 22:42:43 +01:00
|
|
|
my $date = $header->get('Date');
|
2004-09-25 13:40:43 +02:00
|
|
|
|
|
|
|
return (DENY, "Mail with no Date header not accepted here")
|
|
|
|
unless $date;
|
|
|
|
|
|
|
|
return (DECLINED) unless defined $self->{_days};
|
|
|
|
|
|
|
|
my $ts = str2time($date);
|
|
|
|
|
|
|
|
return (DECLINED) unless $ts;
|
|
|
|
|
|
|
|
return (DENY, "The Date in the header was too far in the past")
|
|
|
|
if $ts < time - ($self->{_days}*24*3600);
|
|
|
|
|
|
|
|
return (DENY, "The Date in the header was too far in the future")
|
|
|
|
if $ts > time + ($self->{_days}*24*3600);
|
|
|
|
|
|
|
|
return (DECLINED);
|
|
|
|
}
|