DKIM/Common.pm

filter: Statementstmt 57.7% 56 / 97 Branchbran 16.6% 8 / 48 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 72.2% 13 / 18 Podpod 0.0% 0 / 13 totaltotal 44.6% 80 / 179 CC 28 SCAR 29.6
CC
28
Cov
45%
message_attributes
56.0
message_sender
42.0
message_id
20.0
CRAP 19.3
« DKIM/AuthorDomainPolicy.pm ↑ Summary DKIM/ARC/Verifier.pm »
1 package Mail::DKIM::Common;
2 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 our $VERSION = '1.20261105'; # 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 17 ▶use Mail::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 17 ▶use base 'Mail::DKIM::MessageParser';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 17 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 342 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
20 342 my $class = shift;
21 342 return $class->new_object(@_);
22 }
23  
24 405945 ▶sub add_header {
Subroutine add_header: called CC=4 SCAR=13.9
Pod undocumented
25 405945 my $self = shift;
26 405945 my ($line) = @_;
27  
28 405945 ▶ foreach my $algorithm ( @{ $self->{header_algorithms} || [] } ) {
Condition100%2/2
$self->{'header_algorithms'} || []
l!l
114405831
MC/DC100%1/1
$self->{'header_algorithms'} || []
$self->{'header_algorithms'}
Truth table100%2/2
A
A= $self->{'header_algorithms'}
Aresult
11
00
29 124 $algorithm->add_header($line);
30 }
31  
32 # not /^([^:]+?)\s*:/, which is quadratic in a whitespace run
33 405945 ▶ if ( $line =~ /^([^:]*[^\s:])\s*:(.*)/s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^([^:]*[^\s:])\s*:(.*)/s) 405942 3 405945
34 405942 my $field_name = lc $1;
35 405942 my $contents = $2;
36 405942 $self->handle_header( $field_name, $contents, $line );
37 }
38 405945 push @{ $self->{headers} }, $line;
39 }
40  
41 332 ▶sub add_body {
Subroutine add_body: called CC=3 SCAR=11.4
Pod undocumented
42 332 my $self = shift;
43 332 ▶ if ( $self->{algorithm} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"algorithm"}) 0 332 332
44 0 $self->{algorithm}->add_body(@_);
45 }
46 332 foreach my $algorithm ( @{ $self->{algorithms} } ) {
47 602 $algorithm->add_body(@_);
48 }
49 }
50  
51 405939 ▶sub handle_header {
Subroutine handle_header: called CC=1 SCAR=0.0
Pod undocumented
52 405939 my $self = shift;
53 405939 my ( $field_name, $contents, $line ) = @_;
54  
55 405939 push @{ $self->{header_field_names} }, $field_name;
56  
57 # TODO - detect multiple occurrences of From: or Sender:
58 # header and reject them
59  
60 405939 $self->{headers_by_name}->{$field_name} = $contents;
61 }
62  
63 343 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
64 343 my $self = shift;
65 343 $self->SUPER::init(@_);
66  
67 #initialize variables
68 343 $self->{headers} = [];
69 343 $self->{headers_by_name} = {};
70 343 $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
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
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
BranchTrueFalseTotal
if (my $message_id = $self->message_id) 0 0 0
88 0 push @attributes, "message-id=<$message_id>";
89 }
90  
91 0 ▶ if ( my $sig = $self->signature ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sig = $self->signature) 0 0 0
92 0 push @attributes, 'signer=<' . $sig->identity . '>';
93 }
94  
95 0 ▶ if ( $self->{headers_by_name}->{sender} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'headers_by_name'}{'sender'}) { } 0 0 0
elsif ($self->{'headers_by_name'}{'from'}) { } 0 0 0
96 0 my @list = Mail::Address->parse( $self->{headers_by_name}->{sender} );
97 0 ▶ if ( $list[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list[0]) 0 0 0
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
BranchTrueFalseTotal
if ($list[0]) 0 0 0
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
BranchTrueFalseTotal
unless @_ == 0 0 0 0
114  
115 0 ▶ if ( my $message_id = $self->{headers_by_name}->{'message-id'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $message_id = $self->{"headers_by_name"}{"message-id"}) 0 0 0
116 0 ▶ if ( $message_id =~ /^\s*<(.*)>\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($message_id =~ /^\s*<(.*)>\s*$/) 0 0 0
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
BranchTrueFalseTotal
unless @_ == 0 0 0 0
126  
127 0 ▶ if ( $self->{headers_by_name}->{from} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"headers_by_name"}{"from"}) 0 0 0
128 0 my @list = Mail::Address->parse( $self->{headers_by_name}->{from} );
129 0 ▶ return $list[0] if @list;
Branch: 1 branch
BranchTrueFalseTotal
if @list 0 0 0
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
BranchTrueFalseTotal
unless @_ == 0 0 0 0
137  
138 0 ▶ if ( $self->{headers_by_name}->{sender} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"headers_by_name"}{"sender"}) 0 0 0
139 0 my @list = Mail::Address->parse( $self->{headers_by_name}->{sender} );
140 0 ▶ return $list[0] if @list;
Branch: 1 branch
BranchTrueFalseTotal
if @list 0 0 0
141 }
142 0 ▶ if ( $self->{headers_by_name}->{from} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"headers_by_name"}{"from"}) 0 0 0
143 0 my @list = Mail::Address->parse( $self->{headers_by_name}->{from} );
144 0 ▶ return $list[0] if @list;
Branch: 1 branch
BranchTrueFalseTotal
if @list 0 0 0
145 }
146 0 return Mail::Address->new;
147 }
148  
149 281 ▶sub result {
Subroutine result: called CC=2 SCAR=7.1
Pod undocumented
150 281 my $self = shift;
151 281 ▶ croak 'wrong number of arguments' unless ( @_ == 0 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 0 0 281 281
152 281 return $self->{result};
153 }
154  
155 107 ▶sub result_detail {
Subroutine result_detail: called CC=3 SCAR=11.0
Pod undocumented
156 107 my $self = shift;
157 107 ▶ croak 'wrong number of arguments' unless ( @_ == 0 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 0 0 107 107
158  
159 107 ▶ if ( $self->{details} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"details"}) 70 37 107
160 70 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
BranchTrueFalseTotal
unless @_ == 0 0 28 28
168 28 return $self->{signature};
169 }
170  
171 17 1;
172  
173 __END__
« DKIM/AuthorDomainPolicy.pm ↑ Summary DKIM/ARC/Verifier.pm »