qpsmtpd/plugins/check_badmailfrom

35 lines
913 B
Plaintext
Raw Normal View History

# this plugin checks the standard badmailfrom config
sub register {
my ($self, $qp) = @_;
$self->register_hook("mail", "mail_handler");
$self->register_hook("rcpt", "rcpt_handler");
}
sub mail_handler {
my ($self, $transaction, $sender) = @_;
my @badmailfrom = $self->qp->config("badmailfrom")
or return (DECLINED);
return (DECLINED) unless ($sender->format ne "<>"
and $sender->host && $sender->user);
my $host = lc $sender->host;
my $from = $sender->user . '@' . $host;
for my $bad (@badmailfrom) {
$bad =~ s/^\s*(\S+)/$1/;
$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);
}