| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 57 | |||||||||||
| 58 | # Outer limits lose | ||||||||||
| 59 | 0 | ▶ | return ($InvalidIP . $IP) if $IP eq '0.0.0.0'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 0 | ▶ | return ($InvalidIP . $IP) if $IP eq '255.255.255.255'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 65 | 0 | ▶ | return ($InvalidIP . $IP) if $x =~ /^0\d/; # no leading zeroes allowed | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 77 | 0 | ▶ | return ($OK) unless $name; # If it's ok with MAPS, it's OK with us. | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 0 | ▶ | return ($relay ? $RlyBlackHole . $IP : $RcvBlackHole . $IP); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 1 | 1; | |||||||||
| 82 | |||||||||||
| 83 | __END__ | ||||||||||