| 1 | package Mail::DKIM::DkPolicy; | ||||||||||||||||||||||||||||
| 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 DomainKeys Sender Signing Policy 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 | 10 | ▶ | use Mail::DKIM::DNS; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # get_lookup_name() - determine name of record to fetch | ||||||||||||||||||||||||||||
| 19 | # | ||||||||||||||||||||||||||||
| 20 | 1 | ▶ | sub get_lookup_name { | ||||||||||||||||||||||||||
|
Subroutine
get_lookup_name: called CC=7 SCAR=26.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 22 | 1 | my ($prms) = @_; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # in DomainKeys, the record to fetch is determined based on the | ||||||||||||||||||||||||||||
| 25 | # Sender header, then the From header | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | if ( $prms->{Author} && !$prms->{Sender} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$prms->{"Author"} and not $prms->{"Sender"}
MC/DC0%0/2
$prms->{"Author"} and not $prms->{"Sender"}
$prms->{"Author"}
not $prms->{"Sender"}
Truth table33%1/3
A and not(B)
A= $prms->{"Author"}B= not $prms->{"Sender"}
| |||||||||||||||||||||||||||||
| 28 | 0 | $prms->{Sender} = $prms->{Author}; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | 1 | ▶ | if ( $prms->{Sender} && !$prms->{Domain} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$prms->{"Sender"} and not $prms->{"Domain"}
MC/DC0%0/2
$prms->{"Sender"} and not $prms->{"Domain"}
$prms->{"Sender"}
not $prms->{"Domain"}
Truth table33%1/3
A and not(B)
A= $prms->{"Sender"}B= not $prms->{"Domain"}
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # pick domain from email address | ||||||||||||||||||||||||||||
| 33 | 0 | ▶ | $prms->{Domain} = ( $prms->{Sender} =~ /\@([^@]*)$/ and $1 ); | ||||||||||||||||||||||||||
|
Condition0%0/3
$prms->{'Sender'} =~ /\@([^\@]*)$/ && $1
MC/DC0%0/2
$prms->{'Sender'} =~ /\@([^\@]*)$/ && $1
$prms->{'Sender'} =~ /\@([^\@]*)$/
$1
Truth table0%0/3
A && B
A= $prms->{'Sender'} =~ /\@([^\@]*)$/B= $1
| |||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | ▶ | unless ( $prms->{Domain} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | die "no domain to fetch policy for\n"; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # IETF seems poised to create policy records this way | ||||||||||||||||||||||||||||
| 41 | #my $host = '_policy._domainkey.' . $prms{Domain}; | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # but Yahoo! policy records are still much more common | ||||||||||||||||||||||||||||
| 44 | # see historic RFC4870, section 3.6 | ||||||||||||||||||||||||||||
| 45 | 1 | return '_domainkey.' . $prms->{Domain}; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 2 | my $class = shift; | |||||||||||||||||||||||||||
| 51 | 2 | return $class->parse( String => 'o=~' ); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | #undocumented private class method | ||||||||||||||||||||||||||||
| 56 | 10 | our $DEFAULT_POLICY; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 1 | ▶ | sub default { | ||||||||||||||||||||||||||
|
Subroutine
default: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 60 | 1 | ▶ | $DEFAULT_POLICY ||= $class->new; | ||||||||||||||||||||||||||
|
Condition33%1/3
$Mail::DKIM::DkPolicy::DEFAULT_POLICY ||= $class->new
MC/DC0%0/2
$Mail::DKIM::DkPolicy::DEFAULT_POLICY ||= $class->new
$Mail::DKIM::DkPolicy::DEFAULT_POLICY
$class->new
Truth table33%1/3
A ||= B
A= $Mail::DKIM::DkPolicy::DEFAULT_POLICYB= $class->new
| |||||||||||||||||||||||||||||
| 61 | 1 | return $DEFAULT_POLICY; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub apply { | ||||||||||||||||||||||||||
|
Subroutine
apply: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 67 | 0 | my ($dkim) = @_; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | my $first_party; | |||||||||||||||||||||||||||
| 70 | 0 | foreach my $signature ( $dkim->signatures ) { | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | next if $signature->result ne 'pass'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | my $oa = $dkim->message_sender->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 | 0 | ▶ | return 'accept' if $first_party; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 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
| |||||||||||||||||||||||||||||
| 84 | 0 | return 'neutral'; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 1 | ▶ | sub flags { | ||||||||||||||||||||||||||
|
Subroutine
flags: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | (@_) | ||||||||||||||||||||||||||||
| 92 | 1 | ▶ | and $self->{tags}->{t} = shift; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 1 | $self->{tags}->{t}; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 1 | ▶ | sub is_implied_default_policy { | ||||||||||||||||||||||||||
|
Subroutine
is_implied_default_policy: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 100 | 1 | my $default_policy = ref($self)->default; | |||||||||||||||||||||||||||
| 101 | 1 | return ( $self == $default_policy ); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | sub name { | ||||||||||||||||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 106 | 0 | return 'sender'; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 3 | ▶ | sub note { | ||||||||||||||||||||||||||
|
Subroutine
note: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 111 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | (@_) | ||||||||||||||||||||||||||||
| 114 | 3 | ▶ | and $self->{tags}->{n} = shift; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 3 | $self->{tags}->{n}; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 3 | ▶ | sub policy { | ||||||||||||||||||||||||||
|
Subroutine
policy: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 121 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | (@_) | ||||||||||||||||||||||||||||
| 124 | 3 | ▶ | and $self->{tags}->{o} = shift; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 3 | ▶ | if ( defined $self->{tags}->{o} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 2 | return $self->{tags}->{o}; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | else { | ||||||||||||||||||||||||||||
| 130 | 1 | return '~'; # the default | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | sub signall { | ||||||||||||||||||||||||||
|
Subroutine
signall: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 136 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 137 | 0 | ▶ | return ( $self->policy && $self->policy eq '-' ); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->policy && $self->policy eq '-'
MC/DC0%0/2
$self->policy && $self->policy eq '-'
$self->policy
$self->policy eq '-'
Truth table0%0/3
A && B
A= $self->policyB= $self->policy eq '-'
| |||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | sub signsome { | ||||||||||||||||||||||||||
|
Subroutine
signsome: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 141 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | ▶ | $self->policy | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | or return 1; | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | ▶ | $self->policy eq '~' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | and return 1; | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 0 | return; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 1 | ▶ | sub testing { | ||||||||||||||||||||||||||
|
Subroutine
testing: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||
| 154 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 155 | 1 | my $t = $self->flags; | |||||||||||||||||||||||||||
| 156 | 1 | ▶ | ( $t && $t =~ /y/i ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$t and $t =~ /y/i
MC/DC0%0/2
$t and $t =~ /y/i
$t
$t =~ /y/i
Truth table33%1/3
A and B
A= $tB= $t =~ /y/i
| |||||||||||||||||||||||||||||
| 157 | and return 1; | ||||||||||||||||||||||||||||
| 158 | 1 | return; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 10 | 1; | |||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | __END__ | ||||||||||||||||||||||||||||