| 1 | package Mail::DKIM::DkimPolicy; | ||||||||||||||||||||||||||||||||||
| 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 a DKIM Sender Signing Practices record | ||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | # Copyright 2005-2007 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 | # get_lookup_name() - determine name of record to fetch | ||||||||||||||||||||||||||||||||||
| 22 | # | ||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub get_lookup_name { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_lookup_name: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 24 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 25 | 0 | my ($prms) = @_; | |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | # in DKIM, the record to fetch is determined based on the From header | ||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | 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"}
| |||||||||||||||||||||||||||||||||||
| 30 | 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
| |||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | unless ( $prms->{Domain} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 34 | 0 | die "no domain to fetch policy for\n"; | |||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | # IETF seems poised to create policy records this way | ||||||||||||||||||||||||||||||||||
| 38 | 0 | return '_policy._domainkey.' . $prms->{Domain}; | |||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 43 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||
| 44 | 0 | return $class->parse( String => 'o=~' ); | |||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | #undocumented private class method | ||||||||||||||||||||||||||||||||||
| 48 | 10 | our $DEFAULT_POLICY; | |||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub default { | ||||||||||||||||||||||||||||||||
|
Subroutine
default: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 51 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | $DEFAULT_POLICY ||= $class->new; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$Mail::DKIM::DkimPolicy::DEFAULT_POLICY ||= $class->new
MC/DC0%0/2
$Mail::DKIM::DkimPolicy::DEFAULT_POLICY ||= $class->new
$Mail::DKIM::DkimPolicy::DEFAULT_POLICY
$class->new
Truth table0%0/3
A ||= B
A= $Mail::DKIM::DkimPolicy::DEFAULT_POLICYB= $class->new
| |||||||||||||||||||||||||||||||||||
| 53 | 0 | return $DEFAULT_POLICY; | |||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub apply { | ||||||||||||||||||||||||||||||||
|
Subroutine
apply: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 58 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 59 | 0 | my ($dkim) = @_; | |||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||
| 61 | # first_party indicates whether there is a DKIM signature with | ||||||||||||||||||||||||||||||||||
| 62 | # an i= tag matching the address in the From: header | ||||||||||||||||||||||||||||||||||
| 63 | 0 | my $first_party; | |||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||
| 65 | #FIXME - if there are multiple verified signatures, each one | ||||||||||||||||||||||||||||||||||
| 66 | # should be checked | ||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||
| 68 | 0 | foreach my $signature ( $dkim->signatures ) { | |||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||
| 70 | # only valid/verified signatures are considered | ||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | next unless ( $signature->result && $signature->result eq 'pass' ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$signature->result and $signature->result eq "pass"
MC/DC0%0/2
$signature->result and $signature->result eq "pass"
$signature->result
$signature->result eq "pass"
Truth table0%0/3
A and B
A= $signature->resultB= $signature->result eq "pass"
| |||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | 0 | my $oa = $dkim->message_originator->address; | |||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ( $signature->identity_matches($oa) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | # found a first party signature | ||||||||||||||||||||||||||||||||||
| 77 | 0 | $first_party = 1; | |||||||||||||||||||||||||||||||||
| 78 | 0 | last; | |||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||
| 82 | #TODO - consider testing flag | ||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | return 'accept' if $first_party; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | return 'reject' if ( $self->signall_strict && !$self->testing ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->signall_strict and not $self->testing
MC/DC0%0/2
$self->signall_strict and not $self->testing
$self->signall_strict
not $self->testing
Truth table0%0/3
A and not(B)
A= $self->signall_strictB= not $self->testing
| |||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ( $self->signall ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||
| 89 | # is there ANY valid signature? | ||||||||||||||||||||||||||||||||||
| 90 | 0 | my $verify_result = $dkim->result; | |||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | return 'accept' if $verify_result eq 'pass'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | return 'reject' if ( $self->signall && !$self->testing ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->signall and not $self->testing
MC/DC0%0/2
$self->signall and not $self->testing
$self->signall
not $self->testing
Truth table0%0/3
A and not(B)
A= $self->signallB= not $self->testing
| |||||||||||||||||||||||||||||||||||
| 95 | 0 | return 'neutral'; | |||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub flags { | ||||||||||||||||||||||||||||||||
|
Subroutine
flags: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 100 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||
| 102 | (@_) | ||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | and $self->{tags}->{t} = shift; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||
| 105 | 0 | $self->{tags}->{t}; | |||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub is_implied_default_policy { | ||||||||||||||||||||||||||||||||
|
Subroutine
is_implied_default_policy: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 110 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 111 | 0 | my $default_policy = ref($self)->default; | |||||||||||||||||||||||||||||||||
| 112 | 0 | return ( $self == $default_policy ); | |||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub location { | ||||||||||||||||||||||||||||||||
|
Subroutine
location: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 117 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 118 | 0 | return $self->{Domain}; | |||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | sub name { | ||||||||||||||||||||||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 122 | 0 | return 'author'; | |||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub policy { | ||||||||||||||||||||||||||||||||
|
Subroutine
policy: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 127 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||
| 129 | (@_) | ||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | and $self->{tags}->{dkim} = shift; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if ( defined $self->{tags}->{dkim} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 133 | 0 | return $self->{tags}->{dkim}; | |||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||
| 135 | elsif ( defined $self->{tags}->{o} ) { | ||||||||||||||||||||||||||||||||||
| 136 | 0 | return $self->{tags}->{o}; | |||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||
| 138 | else { | ||||||||||||||||||||||||||||||||||
| 139 | 0 | return 'unknown'; | |||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | sub signall { | ||||||||||||||||||||||||||||||||
|
Subroutine
signall: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 145 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | return $self->policy | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$self->policy && ($self->policy =~ /all/i || $self->policy eq '-')
$self->policy =~ /all/i or $self->policy eq "-"
MC/DC0%0/3
$self->policy && ($self->policy =~ /all/i || $self->policy eq '-')
$self->policy
$self->policy =~ /all/i
$self->policy eq "-"
Truth table0%0/4
A && B or C
A= $self->policyB= $self->policy =~ /all/iC= $self->policy eq "-"
| |||||||||||||||||||||||||||||||||||
| 148 | && ( $self->policy =~ /all/i | ||||||||||||||||||||||||||||||||||
| 149 | || $self->policy eq '-' ); # an older symbol for "all" | ||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | sub signall_strict { | ||||||||||||||||||||||||||||||||
|
Subroutine
signall_strict: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 154 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | return $self->policy | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$self->policy && ($self->policy =~ /strict/i || $self->policy eq '!')
$self->policy =~ /strict/i or $self->policy eq "!"
MC/DC0%0/3
$self->policy && ($self->policy =~ /strict/i || $self->policy eq '!')
$self->policy
$self->policy =~ /strict/i
$self->policy eq "!"
Truth table0%0/4
A && B or C
A= $self->policyB= $self->policy =~ /strict/iC= $self->policy eq "!"
| |||||||||||||||||||||||||||||||||||
| 157 | && ( $self->policy =~ /strict/i | ||||||||||||||||||||||||||||||||||
| 158 | || $self->policy eq '!' ); # "!" is an older symbol for "strict" | ||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | sub signsome { | ||||||||||||||||||||||||||||||||
|
Subroutine
signsome: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 162 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | $self->policy | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 165 | or return 1; | ||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | $self->policy eq '~' | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 168 | and return 1; | ||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||
| 170 | 0 | return; | |||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | sub testing { | ||||||||||||||||||||||||||||||||
|
Subroutine
testing: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 175 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 176 | 0 | my $t = $self->flags; | |||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | ( $t && $t =~ /y/i ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$t and $t =~ /y/i
MC/DC0%0/2
$t and $t =~ /y/i
$t
$t =~ /y/i
Truth table0%0/3
A and B
A= $tB= $t =~ /y/i
| |||||||||||||||||||||||||||||||||||
| 178 | and return 1; | ||||||||||||||||||||||||||||||||||
| 179 | 0 | return; | |||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||
| 182 | 10 | 1; | |||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||
| 184 | __END__ | ||||||||||||||||||||||||||||||||||