2012-04-29 10:35:59 +02:00
|
|
|
#!perl -w
|
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
|
|
|
|
|
2012-05-13 05:27:49 +02:00
|
|
|
The following optional parameters exist:
|
2004-09-25 13:40:43 +02:00
|
|
|
|
2012-05-13 05:27:49 +02:00
|
|
|
=head2 days
|
2004-09-25 13:40:43 +02:00
|
|
|
|
2012-05-13 05:27:49 +02:00
|
|
|
The number of days in the future or past beyond which to reject messages. When
|
|
|
|
unset, messages are not rejected based on the date.
|
2004-09-25 13:40:43 +02:00
|
|
|
|
2012-05-13 05:27:49 +02:00
|
|
|
check_basicheaders [ days 3 ]
|
2004-09-25 13:40:43 +02:00
|
|
|
|
2012-05-13 05:27:49 +02:00
|
|
|
=head2 reject_type
|
2004-09-25 13:40:43 +02:00
|
|
|
|
2012-05-13 05:27:49 +02:00
|
|
|
Whether to issue a permanent or temporary rejection. The default is permanent.
|
2004-09-25 13:40:43 +02:00
|
|
|
|
2012-05-13 05:27:49 +02:00
|
|
|
check_basicheaders reject_type [ temp | perm ]
|
2004-09-25 13:40:43 +02:00
|
|
|
|
2012-05-13 05:27:49 +02:00
|
|
|
Switching to a temporary rejection is most useful when testing the plugin. It
|
|
|
|
allows an administrator to watch for a test period and make sure no valid mail
|
|
|
|
is getting rejected.
|
2004-09-25 13:40:43 +02:00
|
|
|
|
2012-05-13 05:27:49 +02:00
|
|
|
=head1 AUTHOR
|
2004-09-25 13:40:43 +02:00
|
|
|
|
2012-05-13 05:27:49 +02:00
|
|
|
2004 - Written by Jim Winstead Jr.
|
2004-09-25 13:40:43 +02:00
|
|
|
|
2012-05-13 05:27:49 +02:00
|
|
|
2012 - added logging, named arguments, reject_type, tests - Matt Simerson
|
2004-09-25 13:40:43 +02:00
|
|
|
|
2012-05-13 05:27:49 +02:00
|
|
|
=head1 LICENSE
|
2004-09-25 13:40:43 +02:00
|
|
|
|
2012-05-13 05:27:49 +02:00
|
|
|
Released to the public domain, 26 March 2004.
|
2004-09-25 13:40:43 +02:00
|
|
|
|
2012-05-13 05:27:49 +02:00
|
|
|
=cut
|
2004-09-25 13:40:43 +02:00
|
|
|
|
2012-05-13 05:27:49 +02:00
|
|
|
use Date::Parse qw(str2time);
|
2004-09-25 13:40:43 +02:00
|
|
|
|
2012-05-13 05:27:49 +02:00
|
|
|
sub register {
|
|
|
|
my ($self, $qp, @args) = @_;
|
|
|
|
|
|
|
|
if ( @args == 1 ) {
|
|
|
|
$self->log(LOGWARN, "deprecated arguments. Update your arguments to this plugin");
|
|
|
|
$self->{_args}{days} = $args[0];
|
|
|
|
}
|
|
|
|
elsif ( @args % 2 ) {
|
|
|
|
$self->log(LOGWARN, "invalid arguments");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$self->{_args} = { @args };
|
|
|
|
};
|
|
|
|
}
|
2004-09-25 13:40:43 +02:00
|
|
|
|
2012-05-13 05:27:49 +02:00
|
|
|
sub hook_data_post {
|
|
|
|
my ($self, $transaction) = @_;
|
|
|
|
|
|
|
|
my $deny = $self->{_args}{reject_type} eq 'temp' ? DENYSOFT : DENY;
|
|
|
|
|
|
|
|
if ( $transaction->data_size == 0 ) {
|
|
|
|
$self->log(LOGINFO, "fail: no data");
|
|
|
|
return ($deny, "You have to send some data first");
|
|
|
|
};
|
|
|
|
|
|
|
|
my $header = $transaction->header or do {
|
|
|
|
$self->log(LOGINFO, "fail: no headers");
|
|
|
|
return ($deny, "missing header");
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( ! $header->get('From') ) {
|
|
|
|
$self->log(LOGINFO, "fail: no from");
|
|
|
|
return ($deny, "We require a valid From header")
|
|
|
|
};
|
|
|
|
|
|
|
|
my $date = $header->get('Date') or do {
|
|
|
|
$self->log(LOGINFO, "fail: no date");
|
|
|
|
return ($deny, "We require a valid Date header");
|
|
|
|
};
|
|
|
|
|
|
|
|
my $days = $self->{_args}{days};
|
|
|
|
if ( ! defined $days ) {
|
|
|
|
$self->log(LOGINFO, "pass: no days arg");
|
|
|
|
return (DECLINED);
|
|
|
|
};
|
|
|
|
|
|
|
|
my $ts = str2time($date) or do {
|
|
|
|
$self->log(LOGINFO, "skip: date not parseable ($date)");
|
|
|
|
return (DECLINED);
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( $ts < time - ($days*24*3600) ) {
|
|
|
|
$self->log(LOGINFO, "fail: date too old ($date)");
|
|
|
|
return ($deny, "The Date in the header is too far in the past")
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( $ts > time + ($days*24*3600) ) {
|
|
|
|
$self->log(LOGINFO, "fail: date in future ($date)");
|
|
|
|
return ($deny, "The Date in the header is too far in the future")
|
|
|
|
};
|
|
|
|
|
|
|
|
$self->log(LOGINFO, "pass");
|
|
|
|
return (DECLINED);
|
2004-09-25 13:40:43 +02:00
|
|
|
}
|