SpamMonkey/Test/check_uridnsbl.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 64 CC 8 SCAR 36.1
CC
8
Cov
0%
test
56.0
init
6.0
BEGIN
2.0
CRAP 37.1
1 package SpamMonkey::Test::check_uridnsbl;
2 use strict;
3 use SpamMonkey::Utils;
4 sub init {
5 my ($self, $conf) = @_;
6 $conf->{settings}{uridnsbl} = [ $conf->{settings}{uridnsbl} ]
7 unless ref $conf->{settings}{uridnsbl};
8 $conf->{settings}{uridnsbl} = {
9 map {
10 my ($name, $url, $type) = split /\s+/, $_, 3;
11 $name => { url => $url, type => $type }
12 } @{$conf->{settings}{uridnsbl}}
13 };
14 $conf->{settings}{uridnsbl_skip_domain} = {
15 map { map { $_ => 1 } split /\s+/, $_ }
16 @{$conf->{settings}{uridnsbl_skip_domain}}};
17 }
18  
19 sub test {
20 my ($class, $monkey, $text_r, $bl) = @_;
21 $monkey->get_uris($text_r);
22 my $settings = $monkey->{conf}{settings};
23 return unless my $bl_stuff= $settings->{uridnsbl}->{$bl};
24 #my $hits = 0;
25 my @uris = $monkey->uris;
26 return unless @uris;
27 while ($settings->{uridnsbl_max_domains} > 0 and
28 @uris > $settings->{uridnsbl_max_domains}) {
29 splice @uris, rand(@uris),1;
30 }
31 URL: for (@uris) {
32 my $uri = URI->new($_);
33 next if $uri->isa("URI::mailto");
34 for (keys %{$settings->{uridnsbl_skip_domain}}) {
35 next URL if $uri->host =~ /$_\$/;
36 }
37 my @bits = SpamMonkey::Utils->host_to_ip($uri->host);
38 return 1 unless @bits; # Dead hosts are a threat in themselves
39 my $ip = join ".", (reverse(@bits), $bl_stuff->{url});
40 if (SpamMonkey::Utils->rbl_check($ip, $bl_stuff->{type},
41 $settings->{uridnsbl_timeout})) {
42 #$hits++;
43 return 1;
44 }
45 }
46 return;
47 #return (1) x $hits;
48 }
49 1;