MtPolicyd/Plugin/RBLAction.pm

filter: Statementstmt 42.1% 24 / 57 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 66.6% 4 / 6 Podpod 100% 1 / 1 totaltotal 30.5% 29 / 95 CC 12 SCAR 42.1
CC
12
Cov
29%
run
110.0
_get_reject_action
12.0
BEGIN
1.0
CRAP 67.1
« MtPolicyd/Plugin/CtIpRep.pm ↑ Summary MtPolicyd/Plugin/SqlList.pm »
1 package Mail::MtPolicyd::Plugin::RBLAction;
2  
3 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '1.11'; # VERSION
7 # ABSTRACT: mtpolicyd plugin for checking the client-address against an RBL
8  
9  
10 2 extends 'Mail::MtPolicyd::Plugin';
11 2 with 'Mail::MtPolicyd::Plugin::Role::Scoring';
12 2 with 'Mail::MtPolicyd::Plugin::Role::UserConfig' => {
13 'uc_attributes' => [ 'enabled' ],
14 };
15  
16 2 ▶use Mail::MtPolicyd::Plugin::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 ▶use Mail::RBL;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 2 has 'result_from' => ( is => 'rw', isa => 'Str', required => 1 );
22 2 has 'enabled' => ( is => 'rw', isa => 'Str', default => 'on' );
23 2 has 'mode' => ( is => 'rw', isa => 'Str', default => 'reject' );
24  
25 2 has 're_match' => ( is => 'rw', isa => 'Str', required => 1 );
26  
27 2 has 'reject_message' => (
28 is => 'ro', isa => 'Str', default => 'delivery from %IP% rejected %INFO%',
29 );
30  
31 2 has 'score' => ( is => 'rw', isa => 'Maybe[Num]' );
32  
33 sub run {
34 0 ▶ my ( $self, $r ) = @_;
Subroutine run: not called CC=10 SCAR=47.0
Pod documented
35 0 my $ip = $r->attr('client_address');
36 0 my $session = $r->session;
37  
38 0 my $enabled = $self->get_uc( $session, 'enabled' );
39 0 ▶ if( $enabled eq 'off' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enabled eq "off") 0 0 0
40 0 return;
41 }
42  
43 0 my $result_key = 'rbl-'.$self->result_from.'-result';
44 0 ▶ if( ! defined $session->{$result_key} || ref( $session->{$result_key} ) ne 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $session->{$result_key} or ref $session->{$result_key} ne "ARRAY") 0 0 0
Condition0%0/3
not defined $session->{$result_key} or ref $session->{$result_key} ne "ARRAY"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $session->{$result_key} or ref $session->{$result_key} ne "ARRAY"
not defined $session->{$result_key} ref $session->{$result_key} ne "ARRAY"
Truth table0%0/3
not(A) or B
A= not defined $session->{$result_key}B= ref $session->{$result_key} ne "ARRAY"
ABresult
1X1
011
000
45 0 $self->log( $r, 'no RBL check result for '.$self->name.' found!');
46 0 return;
47 }
48 0 my ( $ip_result, $info ) = @{$session->{$result_key}};
49  
50 0 ▶ if( ! defined $ip_result ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ip_result) 0 0 0
51 0 return;
52 }
53  
54 0 my $regex = $self->re_match;
55 0 ▶ if( $ip_result->addr !~ m/$regex/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ip_result->addr =~ /$regex/) 0 0 0
56 0 $self->log( $r, $ip_result->addr.' did not match regex '.$regex);
57 0 return;
58 }
59  
60 0 $self->log( $r, $ip_result->addr.' match regex '.$regex);
61 0 ▶ if( defined $self->score && ! $r->is_already_done('rbl-'.$self->name.'-score') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->score and not $r->is_already_done('rbl-' . $self->name . '-score')) 0 0 0
Condition0%0/3
defined $self->score and not $r->is_already_done('rbl-' . $self->name . '-score')
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->score and not $r->is_already_done('rbl-' . $self->name . '-score')
defined $self->score not $r->is_already_done('rbl-' . $self->name . '-score')
Truth table0%0/3
A and not(B)
A= defined $self->scoreB= not $r->is_already_done('rbl-' . $self->name . '-score')
ABresult
0X0
100
111
62 0 $self->add_score($r, $self->name => $self->score);
63 }
64  
65 0 ▶ if( $self->mode eq 'reject' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->mode eq "reject") 0 0 0
66 0 return Mail::MtPolicyd::Plugin::Result->new(
67 action => $self->_get_reject_action($ip, $info),
68 abort => 1,
69 );
70 }
71 0 ▶ if( $self->mode eq 'accept' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->mode eq "accept") 0 0 0
72 0 return Mail::MtPolicyd::Plugin::Result->new_dunno;
73 }
74  
75 0 return;
76 }
77  
78 sub _get_reject_action {
79 0 ▶ my ( $self, $ip, $info ) = @_;
Subroutine _get_reject_action: not called CC=3 SCAR=24.8
80 0 my $message = $self->reject_message;
81 0 $message =~ s/%IP%/$ip/;
82 0 ▶ if( defined $info && $info ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info and $info ne '') { } 0 0 0
Condition0%0/3
defined $info and $info ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $info and $info ne ""
defined $info $info ne ""
Truth table0%0/3
A and B
A= defined $infoB= $info ne ""
ABresult
0X0
100
111
83 0 $message =~ s/%INFO%/($info)/;
84 } else {
85 0 $message =~ s/%INFO%//;
86 }
87 0 return('reject '.$message);
88 }
89  
90 2 __PACKAGE__->meta->make_immutable;
91  
92 2 1;
93  
94  
95 __END__
96 =pod
97  
98 =head1 NAME
99  
100 Mail::MtPolicyd::Plugin::RBLAction - mtpolicyd plugin for checking the client-address against an RBL
101  
102 =head1 VERSION
103  
104 version 1.11
105  
106 =head1 DESCRIPTION
107  
108 This plugin can be used when a more complex evaluation of an RBL result is needed that just match/not-match.
109  
110 With this plugin you can take the same actions as with the RBL plugin, but it can match the result with a regular expression. This allows to take action based on the category in combined blacklists.
111  
112 =head1 PARAMETERS
113  
114 =over
115  
116 =item result_from (required)
117  
118 Use the query result of this RBL check.
119  
120 =item (uc_)enabled (default: on)
121  
122 Enable/disable this check.
123  
124 =item mode (default: reject)
125  
126 =over
127  
128 =item reject
129  
130 Reject the message. (reject)
131  
132 =item accept
133  
134 Stop processing an accept this message. (dunno)
135  
136 =item passive
137  
138 Only apply the score if one is given.
139  
140 =back
141  
142 =item re_match (required)
143  
144 An regular expression to check the RBL result.
145  
146 =item reject_message (default: delivery from %IP% rejected %INFO%)
147  
148 A pattern for the reject message if mode is set to 'reject'.
149  
150 =item score (default: empty)
151  
152 Apply this score if the check matched.
153  
154 =back
155  
156 =head1 EXAMPLE
157  
158 <Plugin spamhaus-rbl>
159 module = "RBL"
160 mode = "passive"
161 domain="zen.spamhaus.org"
162 </Plugin>
163 <Plugin spamhaus-rbl-sbl>
164 module = "RBLAction"
165 result_from = "spamhaus-rbl"
166 mode = "passive"
167 re_match = "^127\.0\.0\.[23]$"
168 score = 5
169 </Plugin>
170 <Plugin spamhaus-rbl-xbl>
171 module = "RBLAction"
172 result_from = "spamhaus-rbl"
173 mode = "passive"
174 re_match = "^127\.0\.0\.[4-7]$"
175 score = 5
176 </Plugin>
177 <Plugin spamhaus-rbl-pbl>
178 module = "RBLAction"
179 result_from = "spamhaus-rbl"
180 mode = "passive"
181 re_match = "^127\.0\.0\.1[01]$"
182 score = 3
183 </Plugin>
184  
185 =head1 AUTHOR
186  
187 Markus Benning <ich@markusbenning.de>
188  
189 =head1 COPYRIGHT AND LICENSE
190  
191 This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>.
192  
193 This is free software, licensed under:
194  
195 The GNU General Public License, Version 2, June 1991
196  
197 =cut
198  
« MtPolicyd/Plugin/CtIpRep.pm ↑ Summary MtPolicyd/Plugin/SqlList.pm »