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