blib/lib/Mail/Milter/Authentication/Handler/AbusixDataFeed.pm

filter: Statementstmt 92.9% 66 / 71 Branchbran 85.0% 17 / 20 Conditioncond 66.6% 4 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 92.3% 12 / 13 Podpod 0.0% 0 / 6 totaltotal 84.0% 100 / 119 CC 14 SCAR 14.2
CC
14
Cov
90%
eoh_callback
8.1
header_callback
4.0
envfrom_callback
4.0
CRAP 4.1
↑ Summary
1 package Mail::Milter::Authentication::Handler::AbusixDataFeed;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Mail::Milter::Authentication 2.201811;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use base 'Mail::Milter::Authentication::Handler';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # ABSTRACT: Send data to Abusix
7 1 our $VERSION = '2.20181213'; ## VERSION
8  
9 1 ▶use English qw{ -no_match_vars };
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Sys::Syslog qw{:standard :macros};
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Mail::DataFeed::Abusix;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub default_config {
14 return {
15 1 ▶ 'feed_name' => 'name_of_feed',
Subroutine default_config: called CC=1 SCAR=0.0
Pod undocumented
16 'feed_dest' => 'server:port',
17 'feed_key' => 'this_is_a_secret',
18 'listening_port' => '25',
19 };
20 }
21  
22 sub helo_callback {
23 6 ▶ my ( $self, $helo_host ) = @_;
Subroutine helo_callback: called CC=1 SCAR=0.0
Pod undocumented
24 6 $self->{'helo_name'} = $helo_host;
25 6 return;
26 }
27  
28 sub envfrom_callback {
29 6 ▶ my ($self, $from) = @_;
Subroutine envfrom_callback: called CC=4 SCAR=13.9
Pod undocumented
30 6 my $config = $self->handler_config();
31  
32 $self->{ 'abusix_feed' } = Mail::DataFeed::Abusix->new(
33 'feed_name' => $config->{ 'feed_name' },
34 'feed_dest' => $config->{ 'feed_dest' },
35 6 'feed_key' => $config->{ 'feed_key' },
36 );
37 6 $self->{ 'abusix_feed' }->mail_from_domain( $self->get_domain_from( $from ) );
38 6 $self->{ 'abusix_feed' }->helo( $self->{ 'helo_name' } );
39 6 $self->{ 'abusix_feed' }->port( $config->{ 'listening_port' } );
40 6 $self->{ 'abusix_feed' }->ip_address( $self->ip_address() );
41  
42 6 delete $self->{ 'first_received' };
43  
44 6 my $resolver = $self->get_object('resolver');
45 6 my @rdns;
46 6 my $packet = $resolver->query( $self->ip_address(), 'PTR' );
47 6 ▶ if ($packet) {
Branch: 1 branch
BranchTrueFalseTotal
if ($packet) 1 5 6
48 1 foreach my $rr ( $packet->answer ) {
49 # We do not consider CNAMES here
50 1 ▶ if ( $rr->type eq "PTR" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rr->type eq "PTR") 1 0 1
51 1 my $rdatastr = $rr->rdatastr;
52 1 $rdatastr =~ s/\r//g;
53 1 $rdatastr =~ s/\n//g;
54 1 push @rdns, $rdatastr;
55 }
56 }
57 }
58 6 $self->{ 'abusix_feed' }->reverse_dns( join( ',', @rdns ) );
59  
60 6 return;
61 }
62  
63 sub header_callback {
64 22 ▶ my ( $self, $header, $value ) = @_;
Subroutine header_callback: called CC=4 SCAR=13.9
Pod undocumented
65 22 ▶ return if defined $self->{ 'first_received' };
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"first_received"} 12 10 22
66 10 ▶ return if lc $header ne 'received';
Branch: 1 branch
BranchTrueFalseTotal
if lc $header ne "received" 6 4 10
67 4 my $protocol = Mail::Milter::Authentication::Config::get_config()->{'protocol'};
68 4 ▶ return if $protocol ne 'smtp';
Branch: 1 branch
BranchTrueFalseTotal
if $protocol ne "smtp" 0 4 4
69  
70 4 $self->{ 'first_received' } = $value;
71 4 return;
72 }
73  
74 sub eoh_callback {
75 6 ▶ my ( $self ) = @_;
Subroutine eoh_callback: called CC=8 SCAR=20.9
Pod undocumented
76 6 ▶ if ( $self->is_handler_loaded('TLS') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_handler_loaded("TLS")) 4 2 6
77 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
78 }
79 6 $self->{ 'abusix_feed' }->used_auth( $self->is_authenticated() );
80 6 ▶ if ( defined $self->{ 'first_received' } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"first_received"}) 4 2 6
81 4 my $used_smtp = $self->{ 'first_received' } =~ / with SMTP/;
82 4 my $used_esmtp = $self->{ 'first_received' } =~ / with ESMTP/;
83 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
84 # Filters line noise!
85 4 ▶ $self->{ 'abusix_feed' }->used_esmtp( 1 ) if $used_esmtp;
Branch: 1 branch
BranchTrueFalseTotal
if $used_esmtp 3 1 4
86 4 ▶ $self->{ 'abusix_feed' }->used_esmtp( 0 ) if $used_smtp;
Branch: 1 branch
BranchTrueFalseTotal
if $used_smtp 1 3 4
87 }
88 }
89 6 $self->{ 'abusix_feed' }->send();
90 6 return;
91 }
92  
93  
94 sub close_callback {
95 0 ▶ my ( $self ) = @_;
Subroutine close_callback: not called CC=1 SCAR=6.9
Pod undocumented
96  
97 0 delete $self->{'helo_name'};
98 0 delete $self->{'abusix_feed'};
99 0 delete $self->{ 'first_received' };
100 0 return;
101 }
102  
103 1 1;
104  
105 __END__
106  
107 =head1 NAME
108  
109 Authentication Milter - AbusixDataFeed Module
110  
111 =head1 DESCRIPTION
112  
113 Send data back to Abusix
114  
115 =head1 CONFIGURATION
116  
117 "AbusixDataFeed" : {
118 "feed_name" : "id",
119 "feed_dest" : "server:port",
120 "feed_key" : "secret",
121 "listening_port" : "25"
122 },
123  
124 =head1 SYNOPSIS
125  
126 =head1 AUTHORS
127  
128 Marc Bradshaw E<lt>marc@marcbradshaw.netE<gt>
129  
130 =head1 COPYRIGHT
131  
132 Copyright 2018
133  
134 This library is free software; you may redistribute it and/or
135 modify it under the same terms as Perl itself.
136  
137  
138  
↑ Summary