Authentication/Handler/AbusixDataFeed.pm

filter: Statementstmt 75.0% 54 / 72 Branchbran 70.8% 17 / 24 Conditioncond 66.6% 4 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 84.6% 11 / 13 Podpod 0.0% 0 / 7 totaltotal 69.6% 87 / 125 CC 17 SCAR 18.6
CC
17
Cov
74%
dequeue_callback
20.0
eoh_callback
8.1
header_callback
4.0
CRAP 6.4
« Authentication/Handler/Sanitize.pm ↑ Summary Authentication/Handler/AlignedFrom.pm »
1 package Mail::Milter::Authentication::Handler::AbusixDataFeed;
2 2 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Mail::Milter::Authentication::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # ABSTRACT: Handler class for sending data to Abusix
7 2 our $VERSION = '4.20261116'; # VERSION
8 2 ▶use base 'Mail::Milter::Authentication::Handler';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Mail::DataFeed::Abusix 1.20200617.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶sub default_config {
Subroutine default_config: called CC=1 SCAR=0.0
Pod undocumented
12 return {
13 1 'feed_name' => 'name_of_feed',
14 'feed_dest' => 'server:port',
15 'feed_key' => 'this_is_a_secret',
16 'listening_port' => '25',
17 };
18 }
19  
20 6 ▶sub helo_callback {
Subroutine helo_callback: called CC=1 SCAR=0.0
Pod undocumented
21 6 my ( $self, $helo_host ) = @_;
22 6 $self->{'helo_name'} = $helo_host;
23 }
24  
25 0 ▶sub dequeue_callback {
Subroutine dequeue_callback: not called CC=4 SCAR=30.0
Pod undocumented
26 0 my ($self) = @_;
27 0 my $config = $self->handler_config();
28 0 my $dequeue_list = $self->get_dequeue_list('abusix_datafeed');
29 0 foreach my $id ( $dequeue_list->@* ) {
30 0 eval {
31 0 my $feed = $self->get_dequeue($id);
32 0 ▶ if ( $feed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($feed) { } 0 0 0
33 0 my $api = Mail::DataFeed::Abusix->new( $feed->%* );
34 0 $api->send;
35 }
36 else {
37 0 $self->log_error("AbusixDataFeed Report dequeue failed for $id");
38 }
39 };
40 0 ▶ if ( my $Error = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $Error = $@) 0 0 0
41 0 $self->handle_exception( $Error );
42 0 $self->log_error( 'AbusixDataFeed Sending Error ' . $Error );
43 }
44 0 $self->delete_dequeue($id);
45 }
46 }
47  
48 6 ▶sub envfrom_callback {
Subroutine envfrom_callback: called CC=4 SCAR=13.9
Pod undocumented
49 6 my ($self, $from) = @_;
50 6 my $config = $self->handler_config();
51  
52 $self->{ 'abusix_feed' } = {
53 feed_name => $config->{ 'feed_name' },
54 feed_dest => $config->{ 'feed_dest' },
55 feed_key => $config->{ 'feed_key' },
56 mail_from_domain => $self->get_domain_from( $from ),
57 helo => $self->{ 'helo_name' },
58 6 port => $config->{ 'listening_port' },
59 ip_address => $self->ip_address(),
60 time => time(),
61 };
62  
63 6 delete $self->{ 'first_received' };
64  
65 6 my $resolver = $self->get_object('resolver');
66 6 my @rdns;
67 6 my $packet = $resolver->query( $self->ip_address(), 'PTR' );
68 6 ▶ if ($packet) {
Branch: 1 branch
BranchTrueFalseTotal
if ($packet) 1 5 6
69 1 foreach my $rr ( $packet->answer ) {
70 # We do not consider CNAMES here
71 1 ▶ if ( $rr->type eq "PTR" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rr->type eq "PTR") 1 0 1
72 1 my $rdstring = $rr->rdstring;
73 1 $rdstring =~ s/\r//g;
74 1 $rdstring =~ s/\n//g;
75 1 push @rdns, $rdstring;
76 }
77 }
78 }
79  
80 6 $self->{ 'abusix_feed' }->{'reverse_dns'} = join( ',', @rdns );
81 }
82  
83 22 ▶sub header_callback {
Subroutine header_callback: called CC=4 SCAR=13.9
Pod undocumented
84 22 my ( $self, $header, $value ) = @_;
85 22 ▶ return if defined $self->{ 'first_received' };
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"first_received"} 12 10 22
86 10 ▶ return if lc $header ne 'received';
Branch: 1 branch
BranchTrueFalseTotal
if lc $header ne "received" 6 4 10
87 4 my $protocol = Mail::Milter::Authentication::Config::get_config()->{'protocol'};
88 4 ▶ return if $protocol ne 'smtp';
Branch: 1 branch
BranchTrueFalseTotal
if $protocol ne "smtp" 0 4 4
89  
90 4 $self->{ 'first_received' } = $value;
91 }
92  
93 6 ▶sub eoh_callback {
Subroutine eoh_callback: called CC=8 SCAR=20.9
Pod undocumented
94 6 my ( $self ) = @_;
95 6 ▶ if ( $self->is_handler_loaded('TLS') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_handler_loaded("TLS")) 4 2 6
96 4 ▶ $self->{ 'abusix_feed' }->{'used_tls'} = $self->is_encrypted() || 0; # Explicit 0 over undef if TLS handler is loaded
Condition100%2/2
$self->is_encrypted || 0
l!l
13
MC/DC100%1/1
$self->is_encrypted || 0
$self->is_encrypted
Truth table100%2/2
A
A= $self->is_encrypted
Aresult
11
00
97 }
98 6 $self->{ 'abusix_feed' }->{'used_auth'} = $self->is_authenticated();
99 6 ▶ if ( defined $self->{ 'first_received' } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"first_received"}) 4 2 6
100 4 my $used_smtp = $self->{ 'first_received' } =~ / with SMTP/;
101 4 my $used_esmtp = $self->{ 'first_received' } =~ / with ESMTP/;
102 4 ▶ if ( $used_smtp xor $used_esmtp ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($used_smtp xor $used_esmtp) 4 0 4
Condition50%2/4
$used_smtp xor $used_esmtp
l&&rl&&!r!l&&r!l&&!r
0130
MC/DC0%0/2
$used_smtp xor $used_esmtp
$used_smtp $used_esmtp
Truth table50%2/4
A xor B
A= $used_smtpB= $used_esmtp
ABresult
110
101
011
000
103 # Filters line noise!
104 4 ▶ $self->{ 'abusix_feed' }->{'used_esmtp'} = 1 if $used_esmtp;
Branch: 1 branch
BranchTrueFalseTotal
if $used_esmtp 3 1 4
105 4 ▶ $self->{ 'abusix_feed' }->{'used_esmtp'} = 0 if $used_smtp;
Branch: 1 branch
BranchTrueFalseTotal
if $used_smtp 1 3 4
106 }
107 }
108 6 $self->add_dequeue('abusix_datafeed',$self->{'abusix_feed'});
109 }
110  
111  
112 0 ▶sub close_callback {
Subroutine close_callback: not called CC=1 SCAR=6.9
Pod undocumented
113 0 my ( $self ) = @_;
114  
115 0 delete $self->{'helo_name'};
116 0 delete $self->{'abusix_feed'};
117 0 delete $self->{ 'first_received' };
118 }
119  
120 2 1;
121  
122 __END__
« Authentication/Handler/Sanitize.pm ↑ Summary Authentication/Handler/AlignedFrom.pm »