2003-08-31 10:24:06 +02:00
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
check_badmailfrom - checks the standard badmailfrom config
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
Reads the "badmailfrom" configuration like qmail-smtpd does. From the
|
|
|
|
qmail-smtpd docs:
|
|
|
|
|
|
|
|
"Unacceptable envelope sender addresses. qmail-smtpd will reject every
|
|
|
|
recipient address for a message if the envelope sender address is
|
|
|
|
listed in badmailfrom. A line in badmailfrom may be of the form
|
|
|
|
@host, meaning every address at host."
|
|
|
|
|
|
|
|
=cut
|
2002-09-10 13:00:31 +02:00
|
|
|
|
|
|
|
sub register {
|
|
|
|
my ($self, $qp) = @_;
|
|
|
|
$self->register_hook("mail", "mail_handler");
|
|
|
|
$self->register_hook("rcpt", "rcpt_handler");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub mail_handler {
|
2002-09-10 13:04:18 +02:00
|
|
|
my ($self, $transaction, $sender) = @_;
|
2003-08-31 10:24:06 +02:00
|
|
|
|
2002-09-10 19:17:15 +02:00
|
|
|
my @badmailfrom = $self->qp->config("badmailfrom")
|
|
|
|
or return (DECLINED);
|
|
|
|
|
|
|
|
return (DECLINED) unless ($sender->format ne "<>"
|
|
|
|
and $sender->host && $sender->user);
|
|
|
|
|
2002-09-10 13:04:18 +02:00
|
|
|
my $host = lc $sender->host;
|
2004-06-18 07:47:45 +02:00
|
|
|
my $from = lc($sender->user) . '@' . $host;
|
2002-09-10 19:17:15 +02:00
|
|
|
|
2002-09-10 13:00:31 +02:00
|
|
|
for my $bad (@badmailfrom) {
|
2003-08-31 10:24:06 +02:00
|
|
|
$bad =~ s/^\s*(\S+).*/$1/;
|
|
|
|
next unless $bad;
|
2004-06-18 07:47:45 +02:00
|
|
|
$bad = lc $bad;
|
2003-08-31 10:24:06 +02:00
|
|
|
warn "Bad badmailfrom config: No \@ sign in $bad\n" and next unless $bad =~ m/\@/;
|
2002-09-10 13:00:31 +02:00
|
|
|
$transaction->notes('badmailfrom', "Mail from $bad not accepted here")
|
|
|
|
if ($bad eq $from)
|
|
|
|
|| (substr($bad,0,1) eq '@' && $bad eq "\@$host");
|
|
|
|
}
|
|
|
|
return (DECLINED);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub rcpt_handler {
|
|
|
|
my ($self, $transaction, $rcpt) = @_;
|
|
|
|
my $note = $transaction->notes('badmailfrom');
|
|
|
|
return (DENY, $note) if $note;
|
|
|
|
return (DECLINED);
|
|
|
|
}
|