Audit/MAPS.pm

filter: Statementstmt 37.9% 22 / 58 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 62.5% 5 / 8 Podpod 0.0% 0 / 2 totaltotal 30.6% 27 / 88 CC 13 SCAR 40.8
CC
13
Cov
28%
_checkit
110.0
rblcheck
20.0
myALRM
2.0
CRAP 59.4
« Audit/Vacation.pm ↑ Summary Audit/MimeEntity.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Mail::Audit::MAPS;
3 {
4 1 $Mail::Audit::MAPS::VERSION = '2.228';
5 }
6 # ABSTRACT: Mail::Audit plugin for RBL checking
7 1 ▶use Mail::Audit;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 our $host = '.blackholes.mail-abuse.org';
9 1 1;
10  
11 package Mail::Audit;
12 {
13 1 $Mail::Audit::VERSION = '2.228';
14 }
15  
16 1 ▶use Net::SMTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Mail::Internet;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Sys::Hostname;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 0 ▶sub myALRM { die "alarm\n" }
Subroutine myALRM: not called CC=1 SCAR=6.9
Pod undocumented
21  
22 0 ▶sub rblcheck {
Subroutine rblcheck: not called CC=4 SCAR=30.0
Pod undocumented
23 0 my ($self, $timeout) = (shift, shift);
24 0 $self->_log(1, "Performing RBL check");
25 0 my @recieved = $self->received;
26 0 my $rcvcount = 0;
27 0 ▶ $timeout = 10 unless defined $timeout;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $timeout 0 0 0
28  
29 # Catch ALRM signals so we can timeout DNS lookups
30 0 $SIG{ALRM} = 'myALRM';
31 0 &myALRM() if 0; # make -w shut up
32 0 for (@recieved) {
33 0 my $x = _checkit($rcvcount, $_, $timeout);
34 0 ▶ if ($x) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x) 0 0 0
35 0 $self->_log(2,
36 "Check returned $x after " . (1 + $rcvcount) . " recieved headers");
37 0 return $x;
38 }
39 0 $rcvcount++; # Any further Received lines won't be the first.
40 }
41 0 $self->_log(2, "Check was fine");
42 0 return '';
43 }
44  
45 0 ▶sub _checkit {
Subroutine _checkit: not called CC=10 SCAR=47.0
46 0 my $OK = '';
47 0 my $InvalidIP = '1 Invalid IP address ';
48 0 my $RcvBlackHole = '2 Received from RBL-registered spam site ';
49 0 my $RlyBlackHole = '3 Relayed through RBL-registered spam site ';
50  
51 0 my ($relay, $rcvd, $timeout) = @_;
52 0 my ($IP, @IP) = $rcvd =~ /((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}))/;
53 0 my ($name, $x);
54  
55 # We can't complain if there's no IP address in this Received header.
56 0 ▶ return ($OK) unless defined $IP;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $IP 0 0 0
57  
58 # Outer limits lose
59 0 ▶ return ($InvalidIP . $IP) if $IP eq '0.0.0.0';
Branch: 1 branch
BranchTrueFalseTotal
if $IP eq "0.0.0.0" 0 0 0
60 0 ▶ return ($InvalidIP . $IP) if $IP eq '255.255.255.255';
Branch: 1 branch
BranchTrueFalseTotal
if $IP eq "255.255.255.255" 0 0 0
61  
62 # All @IP components must be >= 0 and <= 255
63 0 foreach $x (@IP) {
64 0 ▶ return ($InvalidIP . $IP) if $x > 255;
Branch: 1 branch
BranchTrueFalseTotal
if $x > 255 0 0 0
65 0 ▶ return ($InvalidIP . $IP) if $x =~ /^0\d/; # no leading zeroes allowed
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ /^0\d/ 0 0 0
66 }
67  
68 #
69 # Wrap the gethostbyname call with eval in case it times out.
70 #
71 0 eval {
72 0 alarm($timeout);
73 0 ($name) = gethostbyname(join('.', reverse @IP) . $Mail::Audit::MAPS::host);
74 0 alarm(0);
75 };
76 0 ▶ return ($OK) if $@ =~ /^alarm/; # Timed out. Let it through.
Branch: 1 branch
BranchTrueFalseTotal
if $@ =~ /^alarm/ 0 0 0
77 0 ▶ return ($OK) unless $name; # If it's ok with MAPS, it's OK with us.
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 0 0
78 0 ▶ return ($relay ? $RlyBlackHole . $IP : $RcvBlackHole . $IP);
Branch: 1 branch
BranchTrueFalseTotal
$relay ? : 0 0 0
79 }
80  
81 1 1;
82  
83 __END__
« Audit/Vacation.pm ↑ Summary Audit/MimeEntity.pm »