Debian Codegraph @

plugins/async/rhsbl

raw
1 #!perl -w
2
3 use Qpsmtpd::Plugin::Async::DNSBLBase;
4
5 sub init {
6 my $self = shift;
7 my $class = ref $self;
8
9 no strict 'refs';
10 push @{"${class}::ISA"}, 'Qpsmtpd::Plugin::Async::DNSBLBase';
11 }
12
13 sub hook_mail {
14 my ($self, $transaction, $sender) = @_;
15 my $class = ref $self;
16
17 return DECLINED if $sender->format eq '<>';
18
19 my %rhsbl_zones =
20 map { (split /\s+/, $_, 2)[0, 1] } $self->qp->config('rhsbl_zones');
21 return DECLINED unless %rhsbl_zones;
22
23 my $sender_host = $sender->host;
24
25 my @A_zones = grep { defined($rhsbl_zones{$_}) } keys %rhsbl_zones;
26 my @TXT_zones = grep { !defined($rhsbl_zones{$_}) } keys %rhsbl_zones;
27
28 if (@A_zones) {
29
30 # message templates for responding to the client
31 $transaction->notes(rhsbl_templates =>
32 {map { +"$sender_host.$_" => $rhsbl_zones{$_} } @A_zones});
33 }
34
35 return DECLINED
36 unless $class->lookup($self->qp,
37 [map { "$sender_host.$_" } @A_zones],
38 [map { "$sender_host.$_" } @TXT_zones],
39 );
40
41 return YIELD;
42 }
43
44 sub process_a_result {
45 my ($class, $qp, $result, $query) = @_;
46
47 my $transaction = $qp->transaction;
48 $transaction->notes('rhsbl',
49 $transaction->notes('rhsbl_templates')->{$query})
50 unless $transaction->notes('rhsbl');
51 }
52
53 sub process_txt_result {
54 my ($class, $qp, $result, $query) = @_;
55
56 my $transaction = $qp->transaction;
57 $transaction->notes('rhsbl', $result) unless $transaction->notes('rhsbl');
58 }
59
60 sub hook_rcpt {
61 my ($self, $transaction, $rcpt) = @_;
62 my $host = $transaction->sender->host;
63
64 my $note = $transaction->notes('rhsbl');
65 return (DENY, "Mail from $host rejected because it $note") if $note;
66 return DECLINED;
67 }
68
69 =head1 NAME
70
71 rhsbl - handle RHSBL lookups
72
73 =head1 DESCRIPTION
74
75 Pluging that checks the host part of the sender's address against a
76 configurable set of RBL services.
77
78 =head1 CONFIGURATION
79
80 This plugin reads the lists to use from the rhsbl_zones configuration
81 file. Normal domain based dns blocking lists ("RBLs") which contain TXT
82 records are specified simply as:
83
84 dsn.rfc-ignorant.org
85
86 To configure RBL services which do not contain TXT records in the DNS,
87 but only A records, specify, after a whitespace, your own error message
88 to return in the SMTP conversation e.g.
89
90 abuse.rfc-ignorant.org does not support abuse@domain
91
92 =cut