2012-06-22 11:38:01 +02:00
|
|
|
#!perl -w
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2012-06-23 02:21:09 +02:00
|
|
|
badmailfromto - checks the badmailfromto config
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
2012-06-23 02:21:09 +02:00
|
|
|
Much like the similar badmailfrom, this plugin references both the
|
2012-06-22 11:38:01 +02:00
|
|
|
FROM: and TO: lines, and if they both are present in the badmailfromto
|
|
|
|
config file (a tab delimited list of FROM/TO pairs), then the message is
|
|
|
|
blocked as if the recipient (TO) didn't exist. This is specifically designed
|
|
|
|
to not give the impression that the sender is blocked (good for cases of
|
|
|
|
harassment).
|
|
|
|
|
2012-06-23 02:21:09 +02:00
|
|
|
Based heavily on badmailfrom.
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Qpsmtpd::Constants;
|
|
|
|
|
|
|
|
sub hook_mail {
|
2013-04-21 06:50:39 +02:00
|
|
|
my ($self, $transaction, $sender, %param) = @_;
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
my @badmailfromto = $self->qp->config("badmailfromto");
|
2013-04-21 06:50:39 +02:00
|
|
|
return DECLINED if $self->is_sender_immune($sender, \@badmailfromto);
|
|
|
|
|
|
|
|
my $host = lc $sender->host;
|
|
|
|
my $from = lc($sender->user) . '@' . $host;
|
|
|
|
|
|
|
|
for my $bad (@badmailfromto) {
|
|
|
|
$bad =~ s/^\s*(\S+).*/$1/;
|
|
|
|
next unless $bad;
|
|
|
|
$bad = lc $bad;
|
|
|
|
if ($bad !~ m/\@/) {
|
|
|
|
$self->log(LOGWARN, 'bad config, no @ sign in ' . $bad);
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
if ($bad eq $from || (substr($bad, 0, 1) eq '@' && $bad eq "\@$host")) {
|
|
|
|
$transaction->notes('badmailfromto', $bad);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (DECLINED);
|
2012-06-22 11:38:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub hook_rcpt {
|
|
|
|
my ($self, $transaction, $rcpt, %param) = @_;
|
|
|
|
my $recipient = lc($rcpt->user) . '@' . lc($rcpt->host);
|
|
|
|
my $sender = $transaction->notes('badmailfromto') or do {
|
2012-06-23 02:07:29 +02:00
|
|
|
$self->log(LOGDEBUG, "pass, sender not listed");
|
2012-06-22 11:38:01 +02:00
|
|
|
return (DECLINED);
|
|
|
|
};
|
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
foreach ($self->qp->config("badmailfromto")) {
|
2012-06-22 11:38:01 +02:00
|
|
|
my ($from, $to) = m/^\s*(\S+)\t(\S+).*/;
|
|
|
|
return (DENY, "mail to $recipient not accepted here")
|
2013-04-21 06:50:39 +02:00
|
|
|
if lc($from) eq $sender && lc($to) eq $recipient;
|
2012-06-22 11:38:01 +02:00
|
|
|
}
|
2012-06-23 02:07:29 +02:00
|
|
|
$self->log(LOGDEBUG, "pass, recipient not listed");
|
2012-06-22 11:38:01 +02:00
|
|
|
return (DECLINED);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub is_sender_immune {
|
2013-04-21 06:50:39 +02:00
|
|
|
my ($self, $sender, $badmf) = @_;
|
2012-06-22 11:38:01 +02:00
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
if (!scalar @$badmf) {
|
2012-06-23 02:07:29 +02:00
|
|
|
$self->log(LOGDEBUG, 'skip, empty list');
|
2012-06-22 11:38:01 +02:00
|
|
|
return 1;
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
2012-06-22 11:38:01 +02:00
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
if (!$sender || $sender->format eq '<>') {
|
2012-06-23 02:07:29 +02:00
|
|
|
$self->log(LOGDEBUG, 'skip, null sender');
|
2012-06-22 11:38:01 +02:00
|
|
|
return 1;
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
2012-06-22 11:38:01 +02:00
|
|
|
|
2013-04-21 06:50:39 +02:00
|
|
|
if (!$sender->host || !$sender->user) {
|
2012-06-23 02:07:29 +02:00
|
|
|
$self->log(LOGDEBUG, 'skip, missing user or host');
|
2012-06-22 11:38:01 +02:00
|
|
|
return 1;
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
return;
|
2013-04-21 06:50:39 +02:00
|
|
|
}
|