| 1 | # This code is part of Perl distribution Mail-Message version 4.05. | ||||||||||||||||||||||||||||
| 2 | # The POD got stripped from this file by OODoc version 3.06. | ||||||||||||||||||||||||||||
| 3 | # For contributors see file ChangeLog. | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # This software is copyright (c) 2001-2026 by Mark Overmeer. | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 8 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 9 | # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | package Mail::Message::Field::Structured;{ | ||||||||||||||||||||||||||||
| 13 | 28 | our $VERSION = '4.05'; | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 28 | ▶ | use parent 'Mail::Message::Field::Full'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 28 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 28 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 28 | ▶ | use Log::Report 'mail-message', import => [ qw// ]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 28 | ▶ | use Mail::Message::Field::Attribute (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 28 | ▶ | use Storable qw/dclone/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | #-------------------- | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | sub init($) | ||||||||||||||||||||||||||||
| 29 | 158 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=5 SCAR=19.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 158 | $self->{MMFS_attrs} = {}; | |||||||||||||||||||||||||||
| 31 | 158 | $self->{MMFS_datum} = $args->{datum}; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 158 | $self->SUPER::init($args); | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 158 | ▶ | 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'}
| |||||||||||||||||||||||||||||
| 36 | 158 | ▶ | $attr = [ %$attr ] if ref $attr eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 158 | ▶ | while(@$attr) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 0 | { my $name = shift @$attr; | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | if(ref $name) { $self->attribute($name) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | else { $self->attribute($name, shift @$attr) } | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 158 | $self; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 195 | ▶ | sub clone() { dclone(shift) } | ||||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | #-------------------- | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | sub attribute($;$) | ||||||||||||||||||||||||||||
| 52 | 320 | ▶ | { my ($self, $attr) = (shift, shift); | ||||||||||||||||||||||||||
|
Subroutine
attribute: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | 320 | my $name; | |||||||||||||||||||||||||||
| 54 | 320 | ▶ | if(ref $attr) { $name = $attr->name } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 55 | 200 | elsif( !@_ ) { return $self->{MMFS_attrs}{lc $attr} } | |||||||||||||||||||||||||||
| 56 | else | ||||||||||||||||||||||||||||
| 57 | 43 | { $name = $attr; | |||||||||||||||||||||||||||
| 58 | 43 | $attr = Mail::Message::Field::Attribute->new($name, @_); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 120 | delete $self->{MMFF_body}; | |||||||||||||||||||||||||||
| 62 | 120 | $self->{MMFS_attrs}{lc $name} = $attr; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 2 | ▶ | sub attributes() { values %{$_[0]->{MMFS_attrs}} } | ||||||||||||||||||||||||||
|
Subroutine
attributes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 7 | ▶ | sub beautify() { delete $_[0]->{MMFF_body} } | ||||||||||||||||||||||||||
|
Subroutine
beautify: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub attrPairs() { map +($_->name, $_->value), $_[0]->attributes } | ||||||||||||||||||||||||||
|
Subroutine
attrPairs: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | #-------------------- | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | sub parse($) | ||||||||||||||||||||||||||||
| 75 | 93 | ▶ | { my ($self, $string) = @_; | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 93 | for($string) | |||||||||||||||||||||||||||
| 78 | { # remove FWS, even within quoted strings | ||||||||||||||||||||||||||||
| 79 | 93 | s/\r?\n(\s)/$1/gs; | |||||||||||||||||||||||||||
| 80 | 93 | s/\r?\n/ /gs; | |||||||||||||||||||||||||||
| 81 | 93 | s/\s+$//; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 93 | my $datum = ''; | |||||||||||||||||||||||||||
| 85 | 93 | ▶ | 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 ";"
| |||||||||||||||||||||||||||||
| 86 | 105 | { (undef, $string) = $self->consumeComment($string); | |||||||||||||||||||||||||||
| 87 | 105 | ▶ | $datum .= $1 if $string =~ s/^([^;(]+)//; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | 93 | $self->{MMFS_datum} = $datum; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 93 | my $found = ''; | |||||||||||||||||||||||||||
| 92 | 93 | ▶ | while($string =~ m/\S/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 157 | { my $len = length $string; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 157 | ▶ | 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
| |||||||||||||||||||||||||||||
| 96 | 5 | { my ($name) = $found =~ m/^([^*]+)\*/; | |||||||||||||||||||||||||||
| 97 | 5 | ▶ | if($name && (my $cont = $self->attribute($name))) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$name and my $cont = $self->attribute($name)
MC/DC0%0/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)
| |||||||||||||||||||||||||||||
| 98 | 1 | { $cont->addComponent($found); # continuation | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | else | ||||||||||||||||||||||||||||
| 101 | 4 | { my $attr = Mail::Message::Field::Attribute->new($found); | |||||||||||||||||||||||||||
| 102 | 4 | $self->attribute($attr); | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | 5 | $found = ''; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 157 | (undef, $string) = $self->consumeComment($string); | |||||||||||||||||||||||||||
| 108 | 157 | $string =~ s/^\n//; | |||||||||||||||||||||||||||
| 109 | 157 | (my $text, $string) = $self->consumePhrase($string); | |||||||||||||||||||||||||||
| 110 | 157 | ▶ | $found .= $text if defined $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 157 | ▶ | if(length($string) == $len) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | { # nothing consumed, remove character to avoid endless loop | ||||||||||||||||||||||||||||
| 114 | 0 | $string =~ s/^\s*\S//; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 93 | ▶ | if(length $found) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 75 | { my ($name) = $found =~ m/^([^*]+)\*/; | |||||||||||||||||||||||||||
| 120 | 75 | ▶ | if($name && (my $cont = $self->attribute($name))) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$name and my $cont = $self->attribute($name)
MC/DC0%0/2
$name and my $cont = $self->attribute($name)
$name
my $cont = $self->attribute($name)
Truth table33%1/3
A and B
A= $nameB= my $cont = $self->attribute($name)
| |||||||||||||||||||||||||||||
| 121 | 2 | { $cont->addComponent($found); # continuation | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | else | ||||||||||||||||||||||||||||
| 124 | 73 | { my $attr = Mail::Message::Field::Attribute->new($found); | |||||||||||||||||||||||||||
| 125 | 73 | $self->attribute($attr); | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 93 | 1; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | sub produceBody() | ||||||||||||||||||||||||||||
| 133 | 49 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
produceBody: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 134 | 49 | my $attrs = $self->{MMFS_attrs}; | |||||||||||||||||||||||||||
| 135 | 49 | my $datum = $self->{MMFS_datum}; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | join '; ', ($datum // ''), | ||||||||||||||||||||||||||||
| 138 | 49 | ▶ | map $_->string, @{$attrs}{sort keys %$attrs}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$datum // ""
MC/DC100%1/1
$datum // ""
$datum
Truth table100%2/2
A
A= $datum
| |||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | sub datum(@) | ||||||||||||||||||||||||||||
| 143 | 2 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
datum: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 144 | 2 | ▶ | @_ or return $self->{MMFS_datum}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 1 | delete $self->{MMFF_body}; | |||||||||||||||||||||||||||
| 146 | 1 | $self->{MMFS_datum} = shift; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 28 | 1; | |||||||||||||||||||||||||||