| 1 | package Mail::DKIM::AuthorDomainPolicy; | ||||||||||||||||||||||||||||
| 2 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 10 | our $VERSION = '1.20261116'; # VERSION | |||||||||||||||||||||||||||
| 5 | # ABSTRACT: represents an Author Domain Signing Practices (ADSP) record | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # Copyright 2005-2009 Messiah College. | ||||||||||||||||||||||||||||
| 8 | # Jason Long <jlong@messiah.edu> | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # Copyright (c) 2004 Anthony D. Urso. All rights reserved. | ||||||||||||||||||||||||||||
| 11 | # This program is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||
| 12 | # modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 10 | ▶ | use base 'Mail::DKIM::Policy'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # base class is used for parse(), as_string() | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 10 | ▶ | use Mail::DKIM::DNS; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub fetch { | ||||||||||||||||||||||||||
|
Subroutine
fetch: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 23 | 0 | my %prms = @_; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | my $self; | |||||||||||||||||||||||||||
| 26 | 0 | my $had_error= not eval { | |||||||||||||||||||||||||||
| 27 | 0 | local $SIG{__DIE__}; | |||||||||||||||||||||||||||
| 28 | 0 | $self= $class->SUPER::fetch(%prms); | |||||||||||||||||||||||||||
| 29 | 0 | 1 | |||||||||||||||||||||||||||
| 30 | }; | ||||||||||||||||||||||||||||
| 31 | 0 | my $E = $@; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ( $self && !$self->is_implied_default_policy ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self and not $self->is_implied_default_policy
MC/DC0%0/2
$self and not $self->is_implied_default_policy
$self
not $self->is_implied_default_policy
Truth table0%0/3
A and not(B)
A= $selfB= not $self->is_implied_default_policy
| |||||||||||||||||||||||||||||
| 34 | 0 | return $self; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # didn't find a policy; check the domain itself | ||||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||
| 39 | #FIXME- not good to have this code duplicated between | ||||||||||||||||||||||||||||
| 40 | #here and get_lookup_name() | ||||||||||||||||||||||||||||
| 41 | # | ||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if ( $prms{Author} && !$prms{Domain} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$prms{"Author"} and not $prms{"Domain"}
MC/DC0%0/2
$prms{"Author"} and not $prms{"Domain"}
$prms{"Author"}
not $prms{"Domain"}
Truth table0%0/3
A and not(B)
A= $prms{"Author"}B= not $prms{"Domain"}
| |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | $prms{Domain} = ( $prms{Author} =~ /\@([^@]*)$/ and $1 ); | ||||||||||||||||||||||||||
|
Condition0%0/3
$prms{'Author'} =~ /\@([^\@]*)$/ && $1
MC/DC0%0/2
$prms{'Author'} =~ /\@([^\@]*)$/ && $1
$prms{'Author'} =~ /\@([^\@]*)$/
$1
Truth table0%0/3
A && B
A= $prms{'Author'} =~ /\@([^\@]*)$/B= $1
| |||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | unless ( $prms{Domain} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | die "no domain to fetch policy for\n"; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | my @resp = Mail::DKIM::DNS::query( $prms{Domain}, 'MX' ); | |||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ( !@resp && $@ eq 'NXDOMAIN' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not @resp and $@ eq "NXDOMAIN"
MC/DC0%0/2
not @resp and $@ eq "NXDOMAIN"
not @resp
$@ eq "NXDOMAIN"
Truth table0%0/3
not(A) and B
A= not @respB= $@ eq "NXDOMAIN"
| |||||||||||||||||||||||||||||
| 52 | 0 | return $class->nxdomain_policy; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | die $E if $had_error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | return $self; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # get_lookup_name() - determine name of record to fetch | ||||||||||||||||||||||||||||
| 61 | # | ||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub get_lookup_name { | ||||||||||||||||||||||||||
|
Subroutine
get_lookup_name: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 64 | 0 | my ($prms) = @_; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # in ADSP, the record to fetch is determined based on the From header | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ( $prms->{Author} && !$prms->{Domain} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$prms->{"Author"} and not $prms->{"Domain"}
MC/DC0%0/2
$prms->{"Author"} and not $prms->{"Domain"}
$prms->{"Author"}
not $prms->{"Domain"}
Truth table0%0/3
A and not(B)
A= $prms->{"Author"}B= not $prms->{"Domain"}
| |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | $prms->{Domain} = ( $prms->{Author} =~ /\@([^@]*)$/ and $1 ); | ||||||||||||||||||||||||||
|
Condition0%0/3
$prms->{'Author'} =~ /\@([^\@]*)$/ && $1
MC/DC0%0/2
$prms->{'Author'} =~ /\@([^\@]*)$/ && $1
$prms->{'Author'} =~ /\@([^\@]*)$/
$1
Truth table0%0/3
A && B
A= $prms->{'Author'} =~ /\@([^\@]*)$/B= $1
| |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | unless ( $prms->{Domain} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | die "no domain to fetch policy for\n"; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | # IETF seems poised to create policy records this way | ||||||||||||||||||||||||||||
| 77 | 0 | return '_adsp._domainkey.' . $prms->{Domain}; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 83 | 1 | return $class->parse( String => '' ); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | #undocumented private class method | ||||||||||||||||||||||||||||
| 88 | 10 | our $DEFAULT_POLICY; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub default { | ||||||||||||||||||||||||||
|
Subroutine
default: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 91 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 92 | 0 | ▶ | $DEFAULT_POLICY ||= $class->new; | ||||||||||||||||||||||||||
|
Condition0%0/3
$Mail::DKIM::AuthorDomainPolicy::DEFAULT_POLICY ||= $class->new
MC/DC0%0/2
$Mail::DKIM::AuthorDomainPolicy::DEFAULT_POLICY ||= $class->new
$Mail::DKIM::AuthorDomainPolicy::DEFAULT_POLICY
$class->new
Truth table0%0/3
A ||= B
A= $Mail::DKIM::AuthorDomainPolicy::DEFAULT_POLICYB= $class->new
| |||||||||||||||||||||||||||||
| 93 | 0 | return $DEFAULT_POLICY; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | #undocumented private class method | ||||||||||||||||||||||||||||
| 97 | 10 | our $NXDOMAIN_POLICY; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub nxdomain_policy { | ||||||||||||||||||||||||||
|
Subroutine
nxdomain_policy: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 100 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 101 | 0 | ▶ | if ( !$NXDOMAIN_POLICY ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | $NXDOMAIN_POLICY = $class->new; | |||||||||||||||||||||||||||
| 103 | 0 | $NXDOMAIN_POLICY->policy('NXDOMAIN'); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 0 | return $NXDOMAIN_POLICY; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 2 | ▶ | sub apply { | ||||||||||||||||||||||||||
|
Subroutine
apply: called CC=6 SCAR=23.5
Pod
documented
| |||||||||||||||||||||||||||||
| 110 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 111 | 2 | my ($dkim) = @_; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | # first_party indicates whether there is a DKIM signature with | ||||||||||||||||||||||||||||
| 114 | # a d= tag matching the address in the From: header | ||||||||||||||||||||||||||||
| 115 | 2 | my $first_party; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | my @passing_signatures = | ||||||||||||||||||||||||||||
| 118 | 0 | ▶ | grep { $_->result && $_->result eq 'pass' } $dkim->signatures; | ||||||||||||||||||||||||||
|
Condition0%0/3
$_->result && $_->result eq 'pass'
MC/DC0%0/2
$_->result && $_->result eq 'pass'
$_->result
$_->result eq 'pass'
Truth table0%0/3
A && B
A= $_->resultB= $_->result eq 'pass'
| |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 2 | foreach my $signature (@passing_signatures) { | |||||||||||||||||||||||||||
| 121 | 0 | my $author_domain = $dkim->message_originator->host; | |||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ( lc $author_domain eq lc $signature->domain ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | # found a first party signature | ||||||||||||||||||||||||||||
| 125 | 0 | $first_party = 1; | |||||||||||||||||||||||||||
| 126 | 0 | last; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 2 | ▶ | return 'accept' if $first_party; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 2 | ▶ | return 'reject' if ( $self->signall_strict ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 1 | return 'neutral'; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub is_implied_default_policy { | ||||||||||||||||||||||||||
|
Subroutine
is_implied_default_policy: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 138 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 139 | 0 | my $default_policy = ref($self)->default; | |||||||||||||||||||||||||||
| 140 | 0 | return ( $self == $default_policy ); | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 0 | ▶ | sub location { | ||||||||||||||||||||||||||
|
Subroutine
location: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 145 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 146 | 0 | return $self->{Domain}; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 0 | ▶ | sub name { | ||||||||||||||||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 150 | 0 | return 'ADSP'; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 5 | ▶ | sub policy { | ||||||||||||||||||||||||||
|
Subroutine
policy: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||
| 155 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | (@_) | ||||||||||||||||||||||||||||
| 158 | 5 | ▶ | and $self->{tags}->{dkim} = shift; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 5 | ▶ | if ( defined $self->{tags}->{dkim} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 5 | return $self->{tags}->{dkim}; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | else { | ||||||||||||||||||||||||||||
| 164 | 0 | return 'unknown'; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | sub signall { | ||||||||||||||||||||||||||
|
Subroutine
signall: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 170 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | return $self->policy | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->policy && $self->policy =~ /all/i
MC/DC0%0/2
$self->policy && $self->policy =~ /all/i
$self->policy
$self->policy =~ /all/i
Truth table0%0/3
A && B
A= $self->policyB= $self->policy =~ /all/i
| |||||||||||||||||||||||||||||
| 173 | && ( $self->policy =~ /all/i ); | ||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 2 | ▶ | sub signall_strict { | ||||||||||||||||||||||||||
|
Subroutine
signall_strict: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 178 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 2 | ▶ | return $self->policy | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->policy && $self->policy =~ /discardable/i
MC/DC50%1/2
$self->policy && $self->policy =~ /discardable/i
$self->policy
$self->policy =~ /discardable/i
Truth table66%2/3
A && B
A= $self->policyB= $self->policy =~ /discardable/i
| |||||||||||||||||||||||||||||
| 181 | && ( $self->policy =~ /discardable/i ); | ||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 10 | 1; | |||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | __END__ | ||||||||||||||||||||||||||||