| 1 | package Mail::DKIM::KeyValueList; | ||||||||||||||||||||||||||||||||
| 2 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 20 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 20 | our $VERSION = '1.20261116'; # VERSION | |||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Represents a Key/Value list | ||||||||||||||||||||||||||||||||
| 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 | 20 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 17 | 2 | my $class = shift; | |||||||||||||||||||||||||||||||
| 18 | 2 | my %args = @_; | |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 2 | my $self = bless \%args, $class; | |||||||||||||||||||||||||||||||
| 21 | 2 | return $self; | |||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 1695 | ▶ | sub parse { | ||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 25 | 1695 | my $self_or_class = shift; | |||||||||||||||||||||||||||||||
| 26 | 1695 | ▶ | croak 'wrong number of arguments' unless ( @_ == 1 ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 27 | 1695 | my ($string) = @_; | |||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 1695 | ▶ | my $self = ref($self_or_class) ? $self_or_class : $self_or_class->new; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 1695 | $self->{tags} = []; | |||||||||||||||||||||||||||||||
| 32 | 1695 | $self->{tags_by_name} = {}; | |||||||||||||||||||||||||||||||
| 33 | 1695 | foreach my $raw_tag ( split /;/, $string, -1 ) { | |||||||||||||||||||||||||||||||
| 34 | 11426 | my $tag = { raw => $raw_tag }; | |||||||||||||||||||||||||||||||
| 35 | 11426 | push @{ $self->{tags} }, $tag; | |||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | # strip preceding and trailing whitespace (not s/^\s+|\s*$//g, | ||||||||||||||||||||||||||||||||
| 38 | # which is quadratic in a whitespace run inside the tag) | ||||||||||||||||||||||||||||||||
| 39 | 11426 | $raw_tag =~ s/^\s+//; | |||||||||||||||||||||||||||||||
| 40 | 11426 | $raw_tag =~ s/\s+\z//; | |||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 11426 | ▶ | next if ( $raw_tag eq '' ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | # split at the first "=" (not split(/\s*=\s*/, ...), which is | ||||||||||||||||||||||||||||||||
| 45 | # quadratic in a whitespace run in the tag name) | ||||||||||||||||||||||||||||||||
| 46 | 11399 | my $i = index( $raw_tag, '=' ); | |||||||||||||||||||||||||||||||
| 47 | 11399 | ▶ | unless ( $i >= 0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 48 | 10 | die "syntax error\n"; | |||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||
| 50 | 11389 | my $tagname = substr( $raw_tag, 0, $i ); | |||||||||||||||||||||||||||||||
| 51 | 11389 | my $value = substr( $raw_tag, $i + 1 ); | |||||||||||||||||||||||||||||||
| 52 | 11389 | $tagname =~ s/\s+\z//; | |||||||||||||||||||||||||||||||
| 53 | 11389 | $value =~ s/^\s+//; | |||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 11389 | $tag->{name} = $tagname; | |||||||||||||||||||||||||||||||
| 56 | 11389 | $tag->{value} = $value; | |||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | 11389 | $self->{tags_by_name}->{$tagname} = $tag; | |||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 1685 | return $self; | |||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 544 | ▶ | sub clone { | ||||||||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 65 | 544 | my $self = shift; | |||||||||||||||||||||||||||||||
| 66 | 544 | my $str = $self->as_string; | |||||||||||||||||||||||||||||||
| 67 | 544 | return ref($self)->parse($str); | |||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 31577 | ▶ | sub get_tag { | ||||||||||||||||||||||||||||||
|
Subroutine
get_tag: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 71 | 31577 | my $self = shift; | |||||||||||||||||||||||||||||||
| 72 | 31577 | my ($tagname) = @_; | |||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | 31577 | ▶ | if ( $self->{tags_by_name}->{$tagname} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 75 | 21106 | return $self->{tags_by_name}->{$tagname}->{value}; | |||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||
| 77 | 10471 | return undef; | |||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 8591 | ▶ | sub set_tag { | ||||||||||||||||||||||||||||||
|
Subroutine
set_tag: called CC=7 SCAR=20.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 81 | 8591 | my $self = shift; | |||||||||||||||||||||||||||||||
| 82 | 8591 | my ( $tagname, $value ) = @_; | |||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | 8591 | ▶ | if ( $tagname =~ /[;=\015\012\t ]/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 85 | 0 | croak 'invalid tag name'; | |||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 8591 | ▶ | if ( defined $value ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 89 | 3755 | ▶ | if ( $value =~ /;/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 90 | 0 | croak 'invalid tag value'; | |||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||
| 92 | 3755 | ▶ | if ( $value =~ /\015\012[^\t ]/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 93 | 0 | croak 'invalid tag value'; | |||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | 3755 | ▶ | if ( $self->{tags_by_name}->{$tagname} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 97 | 488 | $self->{tags_by_name}->{$tagname}->{value} = $value; | |||||||||||||||||||||||||||||||
| 98 | my ( $rawname, $rawvalue ) = | ||||||||||||||||||||||||||||||||
| 99 | 488 | split( /=/, $self->{tags_by_name}->{$tagname}->{raw}, 2 ); | |||||||||||||||||||||||||||||||
| 100 | 488 | $self->{tags_by_name}->{$tagname}->{raw} = "$rawname=$value"; | |||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||
| 102 | else { | ||||||||||||||||||||||||||||||||
| 103 | 3267 | my $tag = { | |||||||||||||||||||||||||||||||
| 104 | name => $tagname, | ||||||||||||||||||||||||||||||||
| 105 | value => $value, | ||||||||||||||||||||||||||||||||
| 106 | raw => " $tagname=$value" | ||||||||||||||||||||||||||||||||
| 107 | }; | ||||||||||||||||||||||||||||||||
| 108 | 3267 | push @{ $self->{tags} }, $tag; | |||||||||||||||||||||||||||||||
| 109 | 3267 | $self->{tags_by_name}->{$tagname} = $tag; | |||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||
| 112 | else { | ||||||||||||||||||||||||||||||||
| 113 | 4836 | ▶ | if ( $self->{tags_by_name}->{$tagname} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 114 | 0 | delete $self->{tags_by_name}->{$tagname}; | |||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||
| 116 | 4836 | @{ $self->{tags} } = grep { $_->{name} ne $tagname } @{ $self->{tags} }; | |||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | 1189 | ▶ | sub as_string { | ||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 121 | 1189 | my $self = shift; | |||||||||||||||||||||||||||||||
| 122 | 1189 | ▶ | if ($Mail::DKIM::SORTTAGS) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 123 | 96 | return join( ';', sort map { $_->{raw} } @{ $self->{tags} } ); | |||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||
| 125 | 1093 | return join( ';', map { $_->{raw} } @{ $self->{tags} } ); | |||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||
| 128 | # Start - length of the signature's prefix | ||||||||||||||||||||||||||||||||
| 129 | # Margin - how far to the right the text can go | ||||||||||||||||||||||||||||||||
| 130 | # Insert - characters to insert when wrapping a line | ||||||||||||||||||||||||||||||||
| 131 | # Tags - special processing for tags | ||||||||||||||||||||||||||||||||
| 132 | # Default - how to handle unspecified tags | ||||||||||||||||||||||||||||||||
| 133 | # PreserveNames - if set, the name= part of the tag will be preserved | ||||||||||||||||||||||||||||||||
| 134 | 137 | ▶ | sub wrap { | ||||||||||||||||||||||||||||||
|
Subroutine
wrap: called CC=13 SCAR=25.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 135 | 137 | my $self = shift; | |||||||||||||||||||||||||||||||
| 136 | 137 | my %args = @_; | |||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||
| 138 | 137 | my $TEXTWRAP_CLASS = 'Mail::DKIM::TextWrap'; | |||||||||||||||||||||||||||||||
| 139 | 137 | ▶ | return unless ( UNIVERSAL::can( $TEXTWRAP_CLASS, 'new' ) ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | 3 | my $result = ''; | |||||||||||||||||||||||||||||||
| 142 | my $wrap = $TEXTWRAP_CLASS->new( | ||||||||||||||||||||||||||||||||
| 143 | Output => \$result, | ||||||||||||||||||||||||||||||||
| 144 | Separator => $args{Insert} || "\015\012\t", | ||||||||||||||||||||||||||||||||
| 145 | Margin => $args{Margin} || 72, | ||||||||||||||||||||||||||||||||
| 146 | 3 | ▶ | cur => $args{Start} || 0, | ||||||||||||||||||||||||||||||
|
Condition50%3/6
$args{'Insert'} || "\r\n\t"
$args{'Margin'} || 72
$args{'Start'} || 0
MC/DC0%0/1
$args{'Insert'} || "\r\n\t"
$args{'Insert'}
MC/DC0%0/1
$args{'Margin'} || 72
$args{'Margin'}
MC/DC0%0/1
$args{'Start'} || 0
$args{'Start'}
Truth table50%1/2
A
A= $args{'Insert'}
Truth table50%1/2
A
A= $args{'Margin'}
Truth table50%1/2
A
A= $args{'Start'}
| |||||||||||||||||||||||||||||||||
| 147 | ); | ||||||||||||||||||||||||||||||||
| 148 | 3 | my $did_first; | |||||||||||||||||||||||||||||||
| 149 | 3 | foreach my $tag ( @{ $self->{tags} } ) { | |||||||||||||||||||||||||||||||
| 150 | 20 | my $tagname = $tag->{name}; | |||||||||||||||||||||||||||||||
| 151 | 20 | ▶ | my $tagtype = $args{Tags}->{$tagname} || $args{Default} || ''; | ||||||||||||||||||||||||||||||
|
Condition100%5/5
$args{'Tags'}{$tagname} || $args{'Default'} || ''
$args{"Tags"}{$tagname} or $args{"Default"}
MC/DC100%2/2
$args{'Tags'}{$tagname} || $args{'Default'} || ''
$args{"Tags"}{$tagname}
$args{"Default"}
Truth table100%3/3
A or B
A= $args{"Tags"}{$tagname}B= $args{"Default"}
| |||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | 20 | $wrap->{Break} = undef; | |||||||||||||||||||||||||||||||
| 154 | 20 | $wrap->{BreakBefore} = undef; | |||||||||||||||||||||||||||||||
| 155 | 20 | ▶ | $did_first ? $wrap->add(';') : ( $did_first = 1 ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||
| 157 | 20 | my ( $raw_name, $raw_value ) = split( /=/, $tag->{raw}, 2 ); | |||||||||||||||||||||||||||||||
| 158 | 20 | ▶ | unless ( $args{PreserveNames} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 159 | 6 | $wrap->flush; #allow a break before the tag name | |||||||||||||||||||||||||||||||
| 160 | 6 | $raw_name =~ s/^\s*/ /; | |||||||||||||||||||||||||||||||
| 161 | 6 | $raw_name =~ s/\s+$//; | |||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||
| 163 | 20 | $wrap->add( $raw_name . '=' ); | |||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||
| 165 | 20 | ▶ | if ( $tagtype eq 'b64' ) { | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 166 | 3 | $raw_value =~ s/\s+//gs; #removes all whitespace | |||||||||||||||||||||||||||||||
| 167 | 3 | $wrap->flush; | |||||||||||||||||||||||||||||||
| 168 | 3 | $wrap->{Break} = qr/./; | |||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||
| 170 | elsif ( $tagtype eq 'list' ) { | ||||||||||||||||||||||||||||||||
| 171 | 1 | $raw_value =~ s/\s+/ /gs; #reduces any whitespace to single space | |||||||||||||||||||||||||||||||
| 172 | 1 | $raw_value =~ s/^\s|\s$//g; #trims preceding/trailing spaces | |||||||||||||||||||||||||||||||
| 173 | 1 | $raw_value =~ s/\s*:\s*/:/g; | |||||||||||||||||||||||||||||||
| 174 | 1 | $wrap->flush; | |||||||||||||||||||||||||||||||
| 175 | 1 | $wrap->{Break} = qr/[\s]/; | |||||||||||||||||||||||||||||||
| 176 | 1 | $wrap->{BreakBefore} = qr/[:]/; | |||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||
| 178 | elsif ( $tagtype eq '' ) { | ||||||||||||||||||||||||||||||||
| 179 | 4 | $raw_value =~ s/\s+/ /gs; #reduces any whitespace to single space | |||||||||||||||||||||||||||||||
| 180 | 4 | $raw_value =~ s/^\s|\s$//g; #trims preceding/trailing spaces | |||||||||||||||||||||||||||||||
| 181 | 4 | $wrap->flush; | |||||||||||||||||||||||||||||||
| 182 | 4 | $wrap->{Break} = qr/\s/; | |||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||
| 184 | 20 | $wrap->add($raw_value); | |||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | 3 | $wrap->finish; | |||||||||||||||||||||||||||||||
| 188 | 3 | parse( $self, $result ); | |||||||||||||||||||||||||||||||
| 189 | 3 | return; | |||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||
| 192 | 20 | 1; | |||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||
| 194 | __END__ | ||||||||||||||||||||||||||||||||