Message/Construct/Build.pm

filter: Statementstmt 70.9% 66 / 93 Branchbran 40.0% 32 / 80 Conditioncond 25.0% 3 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 55.3% 114 / 206 SCAR 55.0
CC
46
Cov
55%
build
401.0
buildFromBody
9.7
BEGIN
1.0
CRAP 244.1
« Message/Head/SpamGroup.pm ↑ Summary Message/Construct/Reply.pm »
1 # Copyrights 2001-2023 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;
10 7 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 $VERSION = '3.013';
12  
13  
14 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 7 ▶use Mail::Message::Head::Complete ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 7 ▶use Mail::Message::Body::Lines ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 7 ▶use Mail::Message::Body::Multipart ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20 7 ▶use Mail::Message::Body::Nested ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21 7 ▶use Mail::Message::Field ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 7 ▶use Mail::Address ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25  
26 sub build(@)
27 2 ▶{ my $class = shift;
Subroutine build: called CC=38 SCAR=59.9
Pod documented
28  
29 2 ▶ if($class->isa('Mail::Box::Message'))
Branch: 1 branch
BranchTrueFalseTotal
if ($class->isa("Mail::Box::Message")) 0 2 2
30 0 { $class->log(ERROR
31 => "Only build() Mail::Message's; they are not in a folder yet");
32 0 return undef;
33 }
34  
35 my @parts
36 2 ▶ = ! ref $_[0] ? ()
Branch: 3 branches
BranchTrueFalseTotal
!ref($_[0]) ? : 2 0 2
$_[0]->isa('Mail::Message') ? : 0 0 0
$_[0]->isa('Mail::Message::Body') ? : 0 0 0
37 : $_[0]->isa('Mail::Message') ? shift
38 : $_[0]->isa('Mail::Message::Body') ? shift
39 : ();
40  
41 2 my ($head, @headerlines);
42 2 my ($type, $transfenc, $dispose, $descr, $cid);
43 2 ▶ while(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 9 2 11
44 9 { my $key = shift;
45 9 ▶ if(ref $key && $key->isa('Mail::Message::Field'))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $key and $key->isa("Mail::Message::Field")) 0 9 9
Condition33%1/3
ref $key and $key->isa("Mail::Message::Field")
!ll&&!rl&&r
900
MC/DC0%0/2
ref $key and $key->isa("Mail::Message::Field")
ref $key $key->isa("Mail::Message::Field")
Truth table33%1/3
A and B
A= ref $keyB= $key->isa("Mail::Message::Field")
ABresult
0X0
100
111
46 0 { my $name = $key->name;
47 0 ▶ if($name eq 'content-type') { $type = $key }
Branch: 5 branches
BranchTrueFalseTotal
if ($name eq 'content-type') { } 0 0 0
elsif ($name eq 'content-transfer-encoding') { } 0 0 0
elsif ($name eq 'content-disposition') { } 0 0 0
elsif ($name eq 'content-description') { } 0 0 0
elsif ($name eq 'content-id') { } 0 0 0
48 0 elsif($name eq 'content-transfer-encoding') { $transfenc = $key }
49 0 elsif($name eq 'content-disposition') { $dispose = $key }
50 0 elsif($name eq 'content-description') { $descr = $key }
51 0 elsif($name eq 'content-id') { $cid = $key }
52 0 else { push @headerlines, $key }
53 0 next;
54 }
55  
56 9 my $value = shift;
57 9 ▶ next unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 9 9
58  
59 9 my @data;
60  
61 9 ▶ if($key eq 'head')
Branch: 6 branches
BranchTrueFalseTotal
if ($key eq 'head') { } 0 9 9
elsif ($key eq 'data') { } 3 6 9
elsif ($key eq 'file' or $key eq 'files') { } 0 6 6
elsif ($key eq 'attach') { } 0 6 6
elsif ($key =~ /^content\-(type|transfer\-encoding|disposition|description|id)$/i) { } 0 6 6
elsif ($key =~ /^[A-Z]/) { } 6 0 6
62 0 { $head = $value }
63 elsif($key eq 'data')
64 3 { @data = Mail::Message::Body->new(data => $value) }
65 ▶ elsif($key eq 'file' || $key eq 'files')
Condition33%1/3
$key eq "file" or $key eq "files"
l!l&&r!l&&!r
006
MC/DC0%0/2
$key eq "file" or $key eq "files"
$key eq "file" $key eq "files"
Truth table33%1/3
A or B
A= $key eq "file"B= $key eq "files"
ABresult
1X1
011
000
66 0 ▶ { @data = map Mail::Message::Body->new(file => $_)
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 0 0 0
67 , ref $value eq 'ARRAY' ? @$value : $value;
68 }
69 elsif($key eq 'attach')
70 0 ▶ { foreach my $c (ref $value eq 'ARRAY' ? @$value : $value)
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 0 0 0
71 0 ▶ { defined $c or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $c or next 0 0 0
72 0 ▶ push @data, ref $c && $c->isa('Mail::Message')
Branch: 1 branch
BranchTrueFalseTotal
ref $c && $c->isa('Mail::Message') ? : 0 0 0
Condition0%0/3
ref $c and $c->isa("Mail::Message")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $c and $c->isa("Mail::Message")
ref $c $c->isa("Mail::Message")
Truth table0%0/3
A and B
A= ref $cB= $c->isa("Mail::Message")
ABresult
0X0
100
111
73 ? Mail::Message::Body::Nested->new(nested => $c)
74 : $c;
75 }
76 }
77 elsif($key =~
78 m/^content\-(type|transfer\-encoding|disposition|description|id)$/i )
79 0 { my $k = lc $1;
80 0 my $field = Mail::Message::Field->new($key, $value);
81 0 ▶ if($k eq 'type') { $type = $field }
Branch: 4 branches
BranchTrueFalseTotal
if ($k eq 'type') { } 0 0 0
elsif ($k eq 'disposition') { } 0 0 0
elsif ($k eq 'description') { } 0 0 0
elsif ($k eq 'id') { } 0 0 0
82 0 elsif($k eq 'disposition') { $dispose = $field }
83 0 elsif($k eq 'description') { $descr = $field }
84 0 elsif($k eq 'id') { $cid = $field }
85 0 else { $transfenc = $field }
86 }
87 elsif($key =~ m/^[A-Z]/)
88 6 { push @headerlines, $key, $value }
89 else
90 0 { $class->log(WARNING => "Skipped unknown key '$key' in build");
91 }
92  
93 9 push @parts, grep defined, @data;
94 }
95  
96 2 ▶ my $body
Branch: 2 branches
BranchTrueFalseTotal
@parts == 0 ? : 0 2 2
@parts == 1 ? : 1 1 2
97 = @parts==0 ? Mail::Message::Body::Lines->new()
98 : @parts==1 ? $parts[0]
99 : Mail::Message::Body::Multipart->new(parts => \@parts);
100  
101 # Setting the type explicitly, only after the body object is finalized
102 2 ▶ $body->type($type) if defined $type;
Branch: 1 branch
BranchTrueFalseTotal
if defined $type 0 2 2
103 2 ▶ $body->disposition($dispose) if defined $dispose;
Branch: 1 branch
BranchTrueFalseTotal
if defined $dispose 0 2 2
104 2 ▶ $body->description($descr) if defined $descr;
Branch: 1 branch
BranchTrueFalseTotal
if defined $descr 0 2 2
105 2 ▶ $body->contentId($cid) if defined $cid;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cid 0 2 2
106 2 ▶ $body->transferEncoding($transfenc) if defined $transfenc;
Branch: 1 branch
BranchTrueFalseTotal
if defined $transfenc 0 2 2
107  
108 2 $class->buildFromBody($body, $head, @headerlines);
109 }
110  
111 #------------------------------------------
112  
113  
114 sub buildFromBody(@)
115 23 ▶{ my ($class, $body) = (shift, shift);
Subroutine buildFromBody: called CC=9 SCAR=22.7
Pod documented
116 23 my @log = $body->logSettings;
117  
118 23 my $head;
119 23 ▶ if(ref $_[0] && $_[0]->isa('Mail::Message::Head')) { $head = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] and $_[0]->isa('Mail::Message::Head')) { } 0 23 23
Condition33%1/3
ref $_[0] and $_[0]->isa("Mail::Message::Head")
!ll&&!rl&&r
2300
MC/DC0%0/2
ref $_[0] and $_[0]->isa("Mail::Message::Head")
ref $_[0] $_[0]->isa("Mail::Message::Head")
Truth table33%1/3
A and B
A= ref $_[0]B= $_[0]->isa("Mail::Message::Head")
ABresult
0X0
100
111
120 else
121 23 ▶ { shift unless defined $_[0]; # undef as head
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 2 21 23
122 23 $head = Mail::Message::Head::Complete->new(@log);
123 }
124  
125 23 ▶ while(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 80 23 103
126 80 ▶ { if(ref $_[0]) {$head->add(shift)}
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 80 80
127 80 else {$head->add(shift, shift)}
128 }
129  
130 23 my $message = $class->new
131 ( head => $head
132 , @log
133 );
134  
135 23 $message->body($body);
136  
137 # be sure the message-id is actually stored in the header.
138 23 ▶ $head->add('Message-Id' => '<'.$message->messageId.'>')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $head->get("message-id") 18 5 23
139 unless defined $head->get('message-id');
140  
141 23 ▶ $head->add(Date => Mail::Message::Field->toDate)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $head->get("Date") 16 7 23
142 unless defined $head->get('Date');
143  
144 23 ▶ $head->add('MIME-Version' => '1.0') # required by rfc2045
Branch: 1 branch
BranchTrueFalseTotal
unless defined $head->get("MIME-Version") 23 0 23
145 unless defined $head->get('MIME-Version');
146  
147 23 $message;
148 }
149  
150 #------------------------------------------
151  
152  
153 7 1;
« Message/Head/SpamGroup.pm ↑ Summary Message/Construct/Reply.pm »