Authentication/Handler/PTR.pm

filter: Statementstmt 83.3% 35 / 42 Branchbran 85.7% 12 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 7 / 9 Podpod 25.0% 1 / 4 totaltotal 79.7% 55 / 69 CC 9 SCAR 16.9
CC
9
Cov
84%
helo_callback
9.1
default_config
2.0
grafana_rows
2.0
CRAP 5.4
« Authentication/Handler/SenderID.pm ↑ Summary Authentication/Handler/LocalIP.pm »
1 package Mail::Milter::Authentication::Handler::PTR;
2 27 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 27 ▶use Mail::Milter::Authentication::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # ABSTRACT: Handler class for PTR checking
7 27 our $VERSION = '4.20261111'; # VERSION
8 27 ▶use base 'Mail::Milter::Authentication::Handler';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 0 ▶sub default_config {
Subroutine default_config: not called CC=1 SCAR=6.9
Pod undocumented
11 0 return {};
12 }
13  
14 0 ▶sub grafana_rows {
Subroutine grafana_rows: not called CC=1 SCAR=6.9
Pod undocumented
15 0 my ( $self ) = @_;
16 0 my @rows;
17 0 push @rows, $self->get_json( 'PTR_metrics' );
18 0 return \@rows;
19 }
20  
21 26 ▶sub register_metrics {
Subroutine register_metrics: called CC=1 SCAR=0.0
Pod documented
22 return {
23 26 'ptr_total' => 'The number of emails processed for PTR',
24 };
25 }
26  
27 68 ▶sub helo_callback {
Subroutine helo_callback: called CC=9 SCAR=22.1
Pod undocumented
28  
29 # On HELO
30 68 my ( $self, $helo_host ) = @_;
31 68 ▶ return if ( $self->is_local_ip_address() );
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_local_ip_address 8 60 68
32 60 ▶ return if ( $self->is_trusted_ip_address() );
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_trusted_ip_address 2 58 60
33 58 ▶ return if ( $self->is_authenticated() );
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_authenticated 0 58 58
34  
35 58 ▶ if ( ! $self->is_handler_loaded( 'IPRev' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_handler_loaded("IPRev")) 0 58 58
36 0 $self->log_error( 'PTR Config Error: IPRev is missing ');
37 0 return;
38 }
39  
40 58 my $iprev_handler = $self->get_handler('IPRev');
41 my $domains =
42 exists( $iprev_handler->{'verified_ptr'} )
43 58 ▶ ? $iprev_handler->{'verified_ptr'}
Branch: 1 branch
BranchTrueFalseTotal
exists $iprev_handler->{'verified_ptr'} ? : 22 36 58
44 : q{};
45  
46 58 my $found_match = 0;
47  
48 58 foreach my $domain ( split ',', $domains ) {
49 22 ▶ if ( lc $domain eq lc $helo_host ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $domain eq lc $helo_host) 20 2 22
50 20 $found_match = 1;
51 }
52 }
53  
54 58 ▶ my $result = $found_match ? 'pass' : 'fail';
Branch: 1 branch
BranchTrueFalseTotal
$found_match ? : 20 38 58
55 58 $self->dbgout( 'PTRMatch', $result, LOG_DEBUG );
56 58 my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( 'x-ptr' )->safe_set_value( $result );
57 58 $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'smtp.helo' )->safe_set_value( $helo_host ) );
58 58 $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'policy.ptr' )->safe_set_value( $domains ) );
59 58 $self->add_c_auth_header( $header );
60 58 $self->metric_count( 'ptr_total', { 'result' => $result} );
61 }
62  
63 27 1;
64  
65 __END__
« Authentication/Handler/SenderID.pm ↑ Summary Authentication/Handler/LocalIP.pm »