| 1 | # Copyrights 2001-2022 by [Mark Overmeer <markov@cpan.org>]. | ||||||||||||||||||||||||||||
| 2 | # For other contributors see ChangeLog. | ||||||||||||||||||||||||||||
| 3 | # See the manual pages for details on the licensing terms. | ||||||||||||||||||||||||||||
| 4 | # Pod stripped from pm file by OODoc 2.03. | ||||||||||||||||||||||||||||
| 5 | # This code is part of distribution Mail-Message. Meta-POD processed with | ||||||||||||||||||||||||||||
| 6 | # OODoc into POD and HTML manual-pages. See README.md | ||||||||||||||||||||||||||||
| 7 | # Copyright Mark Overmeer. Licensed under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | package Mail::Message::Field::Structured; | ||||||||||||||||||||||||||||
| 10 | 23 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 23 | $VERSION = '3.012'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 23 | ▶ | use base 'Mail::Message::Field::Full'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 23 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 23 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 23 | ▶ | use Mail::Message::Field::Attribute; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 23 | ▶ | use Storable 'dclone'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | sub init($) | ||||||||||||||||||||||||||||
| 23 | 111 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=5 SCAR=19.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 111 | $self->{MMFS_attrs} = {}; | |||||||||||||||||||||||||||
| 25 | 111 | $self->{MMFS_datum} = $args->{datum}; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 111 | $self->SUPER::init($args); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 111 | ▶ | my $attr = $args->{attributes} || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'attributes'} || []
MC/DC0%0/1
$args->{'attributes'} || []
$args->{'attributes'}
Truth table50%1/2
A
A= $args->{'attributes'}
| |||||||||||||||||||||||||||||
| 30 | 111 | ▶ | $attr = [ %$attr ] if ref $attr eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 111 | ▶ | while(@$attr) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | { my $name = shift @$attr; | |||||||||||||||||||||||||||
| 34 | 0 | ▶ | if(ref $name) { $self->attribute($name) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | else { $self->attribute($name, shift @$attr) } | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 111 | $self; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 181 | ▶ | sub clone() { dclone(shift) } | ||||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | #------------------------------------------ | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | sub attribute($;$) | ||||||||||||||||||||||||||||
| 47 | 298 | ▶ | { my ($self, $attr) = (shift, shift); | ||||||||||||||||||||||||||
|
Subroutine
attribute: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 298 | my $name; | |||||||||||||||||||||||||||
| 49 | 298 | ▶ | if(ref $attr) { $name = $attr->name } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 50 | 186 | elsif( !@_ ) { return $self->{MMFS_attrs}{lc $attr} } | |||||||||||||||||||||||||||
| 51 | else | ||||||||||||||||||||||||||||
| 52 | 40 | { $name = $attr; | |||||||||||||||||||||||||||
| 53 | 40 | $attr = Mail::Message::Field::Attribute->new($name, @_); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 112 | delete $self->{MMFF_body}; | |||||||||||||||||||||||||||
| 57 | 112 | $self->{MMFS_attrs}{lc $name} = $attr; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 2 | ▶ | sub attributes() { values %{shift->{MMFS_attrs}} } | ||||||||||||||||||||||||||
|
Subroutine
attributes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 7 | ▶ | sub beautify() { delete shift->{MMFF_body} } | ||||||||||||||||||||||||||
|
Subroutine
beautify: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub attrPairs() { map +($_->name, $_->value), shift->attributes } | ||||||||||||||||||||||||||
|
Subroutine
attrPairs: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | #------------------------- | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | sub parse($) | ||||||||||||||||||||||||||||
| 71 | 78 | ▶ | { my ($self, $string) = @_; | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # remove FWS, even within quoted strings | ||||||||||||||||||||||||||||
| 74 | 78 | $string =~ s/\r?\n\s?/ /gs; | |||||||||||||||||||||||||||
| 75 | 78 | $string =~ s/ +$//; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 78 | my $datum = ''; | |||||||||||||||||||||||||||
| 78 | 78 | ▶ | while(length $string && substr($string, 0, 1) ne ';') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $string and substr($string, 0, 1) ne ";"
MC/DC100%2/2
length $string and substr($string, 0, 1) ne ";"
length $string
substr($string, 0, 1) ne ";"
Truth table100%3/3
A and B
A= length $stringB= substr($string, 0, 1) ne ";"
| |||||||||||||||||||||||||||||
| 79 | 80 | { (undef, $string) = $self->consumeComment($string); | |||||||||||||||||||||||||||
| 80 | 80 | ▶ | $datum .= $1 if $string =~ s/^([^;(]+)//; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 78 | $self->{MMFS_datum} = $datum; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 78 | my $found = ''; | |||||||||||||||||||||||||||
| 85 | 78 | ▶ | while($string =~ m/\S/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 147 | { my $len = length $string; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 147 | ▶ | if($string =~ s/^\s*\;\s*// && length $found) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$string =~ s/^\s*\;\s*// and length $found
MC/DC100%2/2
$string =~ s/^\s*\;\s*// and length $found
$string =~ s/^\s*\;\s*//
length $found
Truth table100%3/3
A and B
A= $string =~ s/^\s*\;\s*//B= length $found
| |||||||||||||||||||||||||||||
| 89 | 5 | { my ($name) = $found =~ m/^([^*]+)\*/; | |||||||||||||||||||||||||||
| 90 | 5 | ▶ | if($name && (my $cont = $self->attribute($name))) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$name and my $cont = $self->attribute($name)
MC/DC100%2/2
$name and my $cont = $self->attribute($name)
$name
my $cont = $self->attribute($name)
Truth table100%3/3
A and B
A= $nameB= my $cont = $self->attribute($name)
| |||||||||||||||||||||||||||||
| 91 | 1 | { $cont->addComponent($found); # continuation | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | else | ||||||||||||||||||||||||||||
| 94 | 4 | { my $attr = Mail::Message::Field::Attribute->new($found); | |||||||||||||||||||||||||||
| 95 | 4 | $self->attribute($attr); | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 5 | $found = ''; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 147 | (undef, $string) = $self->consumeComment($string); | |||||||||||||||||||||||||||
| 101 | 147 | $string =~ s/^\n//; | |||||||||||||||||||||||||||
| 102 | 147 | (my $text, $string) = $self->consumePhrase($string); | |||||||||||||||||||||||||||
| 103 | 147 | ▶ | $found .= $text if defined $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 147 | ▶ | if(length($string) == $len) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | { # nothing consumed, remove character to avoid endless loop | ||||||||||||||||||||||||||||
| 107 | 0 | $string =~ s/^\s*\S//; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 78 | ▶ | if(length $found) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 70 | { my ($name) = $found =~ m/^([^*]+)\*/; | |||||||||||||||||||||||||||
| 113 | 70 | ▶ | if($name && (my $cont = $self->attribute($name))) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$name and my $cont = $self->attribute($name)
MC/DC50%1/2
$name and my $cont = $self->attribute($name)
$name
my $cont = $self->attribute($name)
Truth table66%2/3
A and B
A= $nameB= my $cont = $self->attribute($name)
| |||||||||||||||||||||||||||||
| 114 | 2 | { $cont->addComponent($found); # continuation | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | else | ||||||||||||||||||||||||||||
| 117 | 68 | { my $attr = Mail::Message::Field::Attribute->new($found); | |||||||||||||||||||||||||||
| 118 | 68 | $self->attribute($attr); | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 78 | 1; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | sub produceBody() | ||||||||||||||||||||||||||||
| 126 | 46 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
produceBody: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 127 | 46 | my $attrs = $self->{MMFS_attrs}; | |||||||||||||||||||||||||||
| 128 | 46 | my $datum = $self->{MMFS_datum}; | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | join '; ' | ||||||||||||||||||||||||||||
| 131 | , (defined $datum ? $datum : '') | ||||||||||||||||||||||||||||
| 132 | 46 | ▶ | , map {$_->string} @{$attrs}{sort keys %$attrs}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | sub datum(@) | ||||||||||||||||||||||||||||
| 137 | 2 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
datum: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 138 | 2 | ▶ | @_ or return $self->{MMFS_datum}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 1 | delete $self->{MMFF_body}; | |||||||||||||||||||||||||||
| 140 | 1 | $self->{MMFS_datum} = shift; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 23 | 1; | |||||||||||||||||||||||||||