| 1 | package Mail::DKIM::Common; | ||||||||||||||
| 2 | 18 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 18 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 18 | our $VERSION = '1.20261116'; # VERSION | |||||||||||||
| 5 | # ABSTRACT: Common class for Mail::DKIM | ||||||||||||||
| 6 | |||||||||||||||
| 7 | # Copyright 2005-2007 Messiah College. All rights reserved. | ||||||||||||||
| 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 | 18 | ▶ | use Mail::Address; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | |||||||||||||||
| 16 | 18 | ▶ | use base 'Mail::DKIM::MessageParser'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | 18 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 18 | |||||||||||||||
| 19 | 352 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 20 | 352 | my $class = shift; | |||||||||||||
| 21 | 352 | return $class->new_object(@_); | |||||||||||||
| 22 | } | ||||||||||||||
| 23 | |||||||||||||||
| 24 | 405975 | ▶ | sub add_header { | ||||||||||||
|
Subroutine
add_header: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||
| 25 | 405975 | my $self = shift; | |||||||||||||
| 26 | 405975 | my ($line) = @_; | |||||||||||||
| 27 | |||||||||||||||
| 28 | 405975 | ▶ | foreach my $algorithm ( @{ $self->{header_algorithms} || [] } ) { | ||||||||||||
|
Condition100%2/2
$self->{'header_algorithms'} || []
MC/DC100%1/1
$self->{'header_algorithms'} || []
$self->{'header_algorithms'}
Truth table100%2/2
A
A= $self->{'header_algorithms'}
| |||||||||||||||
| 29 | 124 | $algorithm->add_header($line); | |||||||||||||
| 30 | } | ||||||||||||||
| 31 | |||||||||||||||
| 32 | # not /^([^:]+?)\s*:/, which is quadratic in a whitespace run | ||||||||||||||
| 33 | 405975 | ▶ | if ( $line =~ /^([^:]*[^\s:])\s*:(.*)/s ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 34 | 405972 | my $field_name = lc $1; | |||||||||||||
| 35 | 405972 | my $contents = $2; | |||||||||||||
| 36 | 405972 | $self->handle_header( $field_name, $contents, $line ); | |||||||||||||
| 37 | } | ||||||||||||||
| 38 | 405975 | push @{ $self->{headers} }, $line; | |||||||||||||
| 39 | } | ||||||||||||||
| 40 | |||||||||||||||
| 41 | 342 | ▶ | sub add_body { | ||||||||||||
|
Subroutine
add_body: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||
| 42 | 342 | my $self = shift; | |||||||||||||
| 43 | 342 | ▶ | if ( $self->{algorithm} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 44 | 0 | $self->{algorithm}->add_body(@_); | |||||||||||||
| 45 | } | ||||||||||||||
| 46 | 342 | foreach my $algorithm ( @{ $self->{algorithms} } ) { | |||||||||||||
| 47 | 605 | $algorithm->add_body(@_); | |||||||||||||
| 48 | } | ||||||||||||||
| 49 | } | ||||||||||||||
| 50 | |||||||||||||||
| 51 | 405969 | ▶ | sub handle_header { | ||||||||||||
|
Subroutine
handle_header: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 52 | 405969 | my $self = shift; | |||||||||||||
| 53 | 405969 | my ( $field_name, $contents, $line ) = @_; | |||||||||||||
| 54 | |||||||||||||||
| 55 | 405969 | push @{ $self->{header_field_names} }, $field_name; | |||||||||||||
| 56 | |||||||||||||||
| 57 | # TODO - detect multiple occurrences of From: or Sender: | ||||||||||||||
| 58 | # header and reject them | ||||||||||||||
| 59 | |||||||||||||||
| 60 | 405969 | $self->{headers_by_name}->{$field_name} = $contents; | |||||||||||||
| 61 | } | ||||||||||||||
| 62 | |||||||||||||||
| 63 | 353 | ▶ | sub init { | ||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 64 | 353 | my $self = shift; | |||||||||||||
| 65 | 353 | $self->SUPER::init(@_); | |||||||||||||
| 66 | |||||||||||||||
| 67 | #initialize variables | ||||||||||||||
| 68 | 353 | $self->{headers} = []; | |||||||||||||
| 69 | 353 | $self->{headers_by_name} = {}; | |||||||||||||
| 70 | 353 | $self->{header_field_names} = []; | |||||||||||||
| 71 | } | ||||||||||||||
| 72 | |||||||||||||||
| 73 | 0 | ▶ | sub load { | ||||||||||||
|
Subroutine
load: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 74 | 0 | my $self = shift; | |||||||||||||
| 75 | 0 | my ($fh) = @_; | |||||||||||||
| 76 | |||||||||||||||
| 77 | 0 | ▶ | while (<$fh>) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 78 | 0 | $self->PRINT($_); | |||||||||||||
| 79 | } | ||||||||||||||
| 80 | 0 | $self->CLOSE; | |||||||||||||
| 81 | } | ||||||||||||||
| 82 | |||||||||||||||
| 83 | 0 | ▶ | sub message_attributes { | ||||||||||||
|
Subroutine
message_attributes: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||
| 84 | 0 | my $self = shift; | |||||||||||||
| 85 | 0 | my @attributes; | |||||||||||||
| 86 | |||||||||||||||
| 87 | 0 | ▶ | if ( my $message_id = $self->message_id ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 88 | 0 | push @attributes, "message-id=<$message_id>"; | |||||||||||||
| 89 | } | ||||||||||||||
| 90 | |||||||||||||||
| 91 | 0 | ▶ | if ( my $sig = $self->signature ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 92 | 0 | push @attributes, 'signer=<' . $sig->identity . '>'; | |||||||||||||
| 93 | } | ||||||||||||||
| 94 | |||||||||||||||
| 95 | 0 | ▶ | if ( $self->{headers_by_name}->{sender} ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 96 | 0 | my @list = Mail::Address->parse( $self->{headers_by_name}->{sender} ); | |||||||||||||
| 97 | 0 | ▶ | if ( $list[0] ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 98 | 0 | push @attributes, 'sender=<' . $list[0]->address . '>'; | |||||||||||||
| 99 | } | ||||||||||||||
| 100 | } | ||||||||||||||
| 101 | elsif ( $self->{headers_by_name}->{from} ) { | ||||||||||||||
| 102 | 0 | my @list = Mail::Address->parse( $self->{headers_by_name}->{from} ); | |||||||||||||
| 103 | 0 | ▶ | if ( $list[0] ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 104 | 0 | push @attributes, 'from=<' . $list[0]->address . '>'; | |||||||||||||
| 105 | } | ||||||||||||||
| 106 | } | ||||||||||||||
| 107 | |||||||||||||||
| 108 | 0 | return @attributes; | |||||||||||||
| 109 | } | ||||||||||||||
| 110 | |||||||||||||||
| 111 | 0 | ▶ | sub message_id { | ||||||||||||
|
Subroutine
message_id: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||
| 112 | 0 | my $self = shift; | |||||||||||||
| 113 | 0 | ▶ | croak 'wrong number of arguments' unless ( @_ == 0 ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 114 | |||||||||||||||
| 115 | 0 | ▶ | if ( my $message_id = $self->{headers_by_name}->{'message-id'} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 116 | 0 | ▶ | if ( $message_id =~ /^\s*<(.*)>\s*$/ ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 117 | 0 | return $1; | |||||||||||||
| 118 | } | ||||||||||||||
| 119 | } | ||||||||||||||
| 120 | 0 | return undef; | |||||||||||||
| 121 | } | ||||||||||||||
| 122 | |||||||||||||||
| 123 | 0 | ▶ | sub message_originator { | ||||||||||||
|
Subroutine
message_originator: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||
| 124 | 0 | my $self = shift; | |||||||||||||
| 125 | 0 | ▶ | croak 'wrong number of arguments' unless ( @_ == 0 ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 126 | |||||||||||||||
| 127 | 0 | ▶ | if ( $self->{headers_by_name}->{from} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 128 | 0 | my @list = Mail::Address->parse( $self->{headers_by_name}->{from} ); | |||||||||||||
| 129 | 0 | ▶ | return $list[0] if @list; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 130 | } | ||||||||||||||
| 131 | 0 | return Mail::Address->new; | |||||||||||||
| 132 | } | ||||||||||||||
| 133 | |||||||||||||||
| 134 | 0 | ▶ | sub message_sender { | ||||||||||||
|
Subroutine
message_sender: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||
| 135 | 0 | my $self = shift; | |||||||||||||
| 136 | 0 | ▶ | croak 'wrong number of arguments' unless ( @_ == 0 ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 137 | |||||||||||||||
| 138 | 0 | ▶ | if ( $self->{headers_by_name}->{sender} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 139 | 0 | my @list = Mail::Address->parse( $self->{headers_by_name}->{sender} ); | |||||||||||||
| 140 | 0 | ▶ | return $list[0] if @list; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 141 | } | ||||||||||||||
| 142 | 0 | ▶ | if ( $self->{headers_by_name}->{from} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 143 | 0 | my @list = Mail::Address->parse( $self->{headers_by_name}->{from} ); | |||||||||||||
| 144 | 0 | ▶ | return $list[0] if @list; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 145 | } | ||||||||||||||
| 146 | 0 | return Mail::Address->new; | |||||||||||||
| 147 | } | ||||||||||||||
| 148 | |||||||||||||||
| 149 | 291 | ▶ | sub result { | ||||||||||||
|
Subroutine
result: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||
| 150 | 291 | my $self = shift; | |||||||||||||
| 151 | 291 | ▶ | croak 'wrong number of arguments' unless ( @_ == 0 ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 152 | 291 | return $self->{result}; | |||||||||||||
| 153 | } | ||||||||||||||
| 154 | |||||||||||||||
| 155 | 113 | ▶ | sub result_detail { | ||||||||||||
|
Subroutine
result_detail: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||
| 156 | 113 | my $self = shift; | |||||||||||||
| 157 | 113 | ▶ | croak 'wrong number of arguments' unless ( @_ == 0 ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 158 | |||||||||||||||
| 159 | 113 | ▶ | if ( $self->{details} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 160 | 76 | return $self->{result} . ' (' . $self->{details} . ')'; | |||||||||||||
| 161 | } | ||||||||||||||
| 162 | 37 | return $self->{result}; | |||||||||||||
| 163 | } | ||||||||||||||
| 164 | |||||||||||||||
| 165 | 28 | ▶ | sub signature { | ||||||||||||
|
Subroutine
signature: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||
| 166 | 28 | my $self = shift; | |||||||||||||
| 167 | 28 | ▶ | croak 'wrong number of arguments' unless ( @_ == 0 ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 168 | 28 | return $self->{signature}; | |||||||||||||
| 169 | } | ||||||||||||||
| 170 | |||||||||||||||
| 171 | 18 | 1; | |||||||||||||
| 172 | |||||||||||||||
| 173 | __END__ | ||||||||||||||