| 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
| |||||||||||
| 32 | 61 | ▶ | return if ( $self->is_trusted_ip_address() ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 59 | ▶ | return if ( $self->is_authenticated() ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | |||||||||||
| 35 | 59 | ▶ | if ( ! $self->is_handler_loaded( 'IPRev' ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 50 | 20 | $found_match = 1; | |||||||||
| 51 | } | ||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 59 | ▶ | my $result = $found_match ? 'pass' : 'fail'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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__ | ||||||||||