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/AlignedFrom.pm ↑ Summary Authentication/Handler/LocalIP.pm »
1 package Mail::Milter::Authentication::Handler::PTR;
2 28 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 28 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 28 ▶use Mail::Milter::Authentication::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # ABSTRACT: Handler class for PTR checking
7 28 our $VERSION = '4.20261116'; # VERSION
8 28 ▶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 27 ▶sub register_metrics {
Subroutine register_metrics: called CC=1 SCAR=0.0
Pod documented
22 return {
23 27 'ptr_total' => 'The number of emails processed for PTR',
24 };
25 }
26  
27 69 ▶sub helo_callback {
Subroutine helo_callback: called CC=9 SCAR=22.1
Pod undocumented
28  
29 # On HELO
30 69 my ( $self, $helo_host ) = @_;
31 69 ▶ return if ( $self->is_local_ip_address() );
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_local_ip_address 8 61 69
32 61 ▶ return if ( $self->is_trusted_ip_address() );
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_trusted_ip_address 2 59 61
33 59 ▶ return if ( $self->is_authenticated() );
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_authenticated 0 59 59
34  
35 59 ▶ if ( ! $self->is_handler_loaded( 'IPRev' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_handler_loaded("IPRev")) 0 59 59
36 0 $self->log_error( 'PTR Config Error: IPRev is missing ');
37 0 return;
38 }
39  
40 59 my $iprev_handler = $self->get_handler('IPRev');
41 my $domains =
42 exists( $iprev_handler->{'verified_ptr'} )
43 59 ▶ ? $iprev_handler->{'verified_ptr'}
Branch: 1 branch
BranchTrueFalseTotal
exists $iprev_handler->{'verified_ptr'} ? : 22 37 59
44 : q{};
45  
46 59 my $found_match = 0;
47  
48 59 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 59 ▶ my $result = $found_match ? 'pass' : 'fail';
Branch: 1 branch
BranchTrueFalseTotal
$found_match ? : 20 39 59
55 59 $self->dbgout( 'PTRMatch', $result, LOG_DEBUG );
56 59 my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( 'x-ptr' )->safe_set_value( $result );
57 59 $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'smtp.helo' )->safe_set_value( $helo_host ) );
58 59 $header->add_child( Mail::AuthenticationResults::Header::SubEntry->new()->set_key( 'policy.ptr' )->safe_set_value( $domains ) );
59 59 $self->add_c_auth_header( $header );
60 59 $self->metric_count( 'ptr_total', { 'result' => $result} );
61 }
62  
63 28 1;
64  
65 __END__
« Authentication/Handler/AlignedFrom.pm ↑ Summary Authentication/Handler/LocalIP.pm »