Message/Body.pm

filter: Statementstmt 74.6% 168 / 225 Branchbran 62.6% 94 / 150 Conditioncond 59.3% 35 / 59 MC/DCmcdc 50.0% 18 / 36 Subroutinesub 63.6% 35 / 55 Podpod 94.1% 32 / 34 totaltotal 68.3% 382 / 559 CC 102 SCAR 39.9
CC
102
Cov
68%
eol
210.0
init
117.3
write
20.0
CRAP 54.3
« Message/Field/Date.pm ↑ Summary Message/Replace/MailInternet.pm »
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::Body;
10 31 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 31 $VERSION = '3.012';
12  
13 31 ▶use base 'Mail::Reporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 31 ▶use Mail::Message::Field;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 31 ▶use Mail::Message::Body::Lines;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 31 ▶use Mail::Message::Body::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 31 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 31 ▶use Scalar::Util qw/weaken refaddr/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 31 ▶use File::Basename qw/basename/;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 31 ▶use MIME::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 31 my $mime_types = MIME::Types->new;
28 31 my $mime_plain = $mime_types->type('text/plain');
29  
30  
31 use overload
32 427 ▶ bool => sub {1} # $body->print if $body
Subroutine __ANON__: called CC=1 SCAR=0.0
33 , '""' => 'string_unless_carp'
34 , '@{}' => 'lines'
35 11 ▶ , '==' => sub {ref $_[1] && refaddr $_[0] == refaddr $_[1]}
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] and builtin::refaddr($_[0]) == builtin::refaddr($_[1]) 11 0 11
36 31 ▶ , '!=' => sub {ref $_[1] && refaddr $_[0] != refaddr $_[1]};
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] and builtin::refaddr($_[0]) != builtin::refaddr($_[1]) 43 0 43
37  
38 #------------------------------------------
39  
40  
41 31 my $body_count = 0; # to be able to compare bodies for equivalence.
42  
43 sub new(@)
44 220 ▶{ my $class = shift;
Subroutine new: called CC=3 SCAR=11.0
Pod documented
45  
46 220 ▶ return $class->SUPER::new(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless $class eq __PACKAGE__ 204 16 220
47 unless $class eq __PACKAGE__;
48  
49 16 my %args = @_;
50  
51 exists $args{file}
52 16 ▶ ? Mail::Message::Body::File->new(@_)
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'file'} ? : 0 16 16
53 : Mail::Message::Body::Lines->new(@_);
54 }
55  
56 # All body implementations shall implement all of the following!!
57  
58 0 ▶sub _data_from_filename(@) {shift->notImplemented}
Subroutine _data_from_filename: not called CC=1 SCAR=6.9
59 0 ▶sub _data_from_filehandle(@) {shift->notImplemented}
Subroutine _data_from_filehandle: not called CC=1 SCAR=6.9
60 0 ▶sub _data_from_glob(@) {shift->notImplemented}
Subroutine _data_from_glob: not called CC=1 SCAR=6.9
61 0 ▶sub _data_from_lines(@) {shift->notImplemented}
Subroutine _data_from_lines: not called CC=1 SCAR=6.9
62  
63 sub init($)
64 204 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=44 SCAR=47.6
Pod undocumented
65  
66 204 $self->SUPER::init($args);
67  
68 204 ▶ $self->{MMB_modified} = $args->{modified} || 0;
Condition50%1/2
$args->{'modified'} || 0
l!l
0204
MC/DC0%0/1
$args->{'modified'} || 0
$args->{'modified'}
Truth table50%1/2
A
A= $args->{'modified'}
Aresult
11
00
69  
70 204 my $filename = $args->{filename};
71 204 my $mime = $args->{mime_type};
72  
73 204 ▶ if(defined(my $file = $args->{file}))
Branch: 3 branches
BranchTrueFalseTotal
if (defined(my $file = $args->{'file'})) { } 3 201 204
elsif (defined(my $data = $args->{'data'})) { } 143 58 201
elsif (not $self->isMultipart || $self->isNested) { } 13 45 58
74 {
75 3 ▶ if(!ref $file)
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $file) { } 0 3 3
elsif (ref $file eq 'GLOB') { } 0 3 3
elsif ($file->isa('IO::Handle')) { } 3 0 3
76 0 ▶ { $self->_data_from_filename($file) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->_data_from_filename($file) or return 0 0 0
77 0 ▶ $filename ||= $file;
Condition0%0/3
$filename ||= $file
l!l&&r!l&&!r
000
MC/DC0%0/2
$filename ||= $file
$filename $file
Truth table0%0/3
A ||= B
A= $filenameB= $file
ABresult
1X1
011
000
78 0 ▶ $mime ||= $mime_types->mimeTypeOf($filename)
Branch: 1 branch
BranchTrueFalseTotal
-T $file ? : 0 0 0
Condition0%0/6
$mime ||= $mime_types->mimeTypeOf($filename) || (-T $file ? "text/plain" : "application/octet-stream")
l!l&&r!l&&!r
000
$mime_types->mimeTypeOf($filename) || (-T $file ? 'text/plain' : 'application/octet-stream')
l!l&&r!l&&!r
000
MC/DC0%0/3
$mime ||= $mime_types->mimeTypeOf($filename) || (-T $file ? "text/plain" : "application/octet-stream")
$mime $mime_types->mimeTypeOf($filename) (-T $file ? 'text/plain' : 'application/octet-stream')
Truth table0%0/4
A ||= B || C
A= $mimeB= $mime_types->mimeTypeOf($filename)C= (-T $file ? 'text/plain' : 'application/octet-stream')
ABCresult
1XX1
01X1
0011
0000
79 || (-T $file ? 'text/plain' : 'application/octet-stream');
80 }
81 elsif(ref $file eq 'GLOB')
82 0 ▶ { $self->_data_from_glob($file) or return }
Branch: 1 branch
BranchTrueFalseTotal
$self->_data_from_glob($file) or return 0 0 0
83 elsif($file->isa('IO::Handle'))
84 3 ▶ { $self->_data_from_filehandle($file) or return }
Branch: 1 branch
BranchTrueFalseTotal
$self->_data_from_filehandle($file) or return 0 3 3
85 else
86 0 { croak "message body: illegal datatype `".ref($file)."' for file option" }
87 }
88 elsif(defined(my $data = $args->{data}))
89 {
90 143 ▶ if(!ref $data)
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $data) { } 82 61 143
elsif (ref $data eq 'ARRAY') { } 61 0 61
91 82 { my @lines = split /^/, $data;
92 82 $self->_data_from_lines(\@lines)
93 }
94 elsif(ref $data eq 'ARRAY')
95 61 ▶ { $self->_data_from_lines($data) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->_data_from_lines($data) or return 0 61 61
96 }
97 else
98 0 { croak "message body: illegal datatype `".ref($data)."' for data option" }
99 }
100 ▶ elsif(! $self->isMultipart && ! $self->isNested)
Condition100%3/3
$self->isMultipart || $self->isNested
l!l&&r!l&&!r
341113
MC/DC100%2/2
$self->isMultipart || $self->isNested
$self->isMultipart $self->isNested
Truth table100%3/3
A || B
A= $self->isMultipartB= $self->isNested
ABresult
1X1
011
000
101 { # Neither 'file' nor 'data', so empty body.
102 13 ▶ $self->_data_from_lines( [] ) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->_data_from_lines([]) or return 0 13 13
103 }
104  
105 # Set the content info
106  
107 my ($transfer, $disp, $charset, $descr, $cid) = @$args{
108 204 qw/transfer_encoding disposition charset description content_id/ };
109  
110 204 ▶ if(defined $filename)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $filename) 0 204 204
111 0 ▶ { $disp //= Mail::Message::Field->new
Branch: 1 branch
BranchTrueFalseTotal
-T $filename ? : 0 0 0
Condition0%0/3
$disp //= "Mail::Message::Field"->new("Content-Disposition", -T $filename ? "inline" : "attachment", "filename", basename($filename))
l!l&&r!l&&!r
000
MC/DC0%0/2
$disp //= "Mail::Message::Field"->new("Content-Disposition", -T $filename ? "inline" : "attachment", "filename", basename($filename))
$disp "Mail::Message::Field"->new("Content-Disposition", -T $filename ? "inline" : "attachment", "filename", basename($filename))
Truth table0%0/3
A //= B
A= $dispB= "Mail::Message::Field"->new("Content-Disposition", -T $filename ? "inline" : "attachment", "filename", basename($filename))
ABresult
1X1
011
000
112 ( 'Content-Disposition' => (-T $filename ? 'inline' : 'attachment')
113 , filename => basename($filename)
114 );
115 0 ▶ $mime //= $mime_types->mimeTypeOf($filename);
Condition0%0/3
$mime //= $mime_types->mimeTypeOf($filename)
l!l&&r!l&&!r
000
MC/DC0%0/2
$mime //= $mime_types->mimeTypeOf($filename)
$mime $mime_types->mimeTypeOf($filename)
Truth table0%0/3
A //= B
A= $mimeB= $mime_types->mimeTypeOf($filename)
ABresult
1X1
011
000
116 }
117  
118 204 ▶ if(ref $mime && $mime->isa('MIME::Type'))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $mime and $mime->isa("MIME::Type")) 0 204 204
Condition66%2/3
ref $mime and $mime->isa("MIME::Type")
!ll&&!rl&&r
143610
MC/DC0%0/2
ref $mime and $mime->isa("MIME::Type")
ref $mime $mime->isa("MIME::Type")
Truth table66%2/3
A and B
A= ref $mimeB= $mime->isa("MIME::Type")
ABresult
0X0
100
111
119 0 { $mime = $mime->type;
120 }
121  
122 204 ▶ if(defined(my $based = $args->{based_on}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $based = $args->{'based_on'})) { } 122 82 204
123 122 ▶ { $mime = $based->type unless defined $mime;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mime 42 80 122
124 122 ▶ $transfer = $based->transferEncoding unless defined $transfer;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $transfer 109 13 122
125 122 ▶ $disp = $based->disposition unless defined $disp;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $disp 122 0 122
126 122 ▶ $descr = $based->description unless defined $descr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $descr 122 0 122
127 122 ▶ $cid = $based->contentId unless defined $cid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cid 122 0 122
128  
129 $self->{MMB_checked}
130 122 ▶ = defined $args->{checked} ? $args->{checked} : $based->checked;
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{'checked'} ? : 43 79 122
131 }
132 else
133 82 { $transfer = $args->{transfer_encoding};
134 82 ▶ $self->{MMB_checked} = $args->{checked} || 0;
Condition100%2/2
$args->{'checked'} || 0
l!l
379
MC/DC100%1/1
$args->{'checked'} || 0
$args->{'checked'}
Truth table100%2/2
A
A= $args->{'checked'}
Aresult
11
00
135 }
136  
137 204 ▶ $mime ||= 'text/plain';
Condition100%2/2
$mime ||= "text/plain"
l!l
16242
MC/DC100%1/1
$mime ||= "text/plain"
$mime
Truth table100%2/2
A
A= $mime
Aresult
11
00
138 204 $mime = $self->type($mime);
139 204 ▶ $mime->attribute(charset => ($charset || 'PERL'))
Branch: 1 branch
BranchTrueFalseTotal
if $mime =~ m[^text/]i and not $mime->attribute("charset") 74 130 204
Condition100%5/5
$mime =~ m[^text/]i and not $mime->attribute("charset")
!ll&&!rl&&r
537774
$charset || 'PERL'
l!l
1262
MC/DC100%2/2
$mime =~ m[^text/]i and not $mime->attribute("charset")
$mime =~ m[^text/]i not $mime->attribute("charset")
MC/DC100%1/1
$charset || 'PERL'
$charset
Truth table100%3/3
A and not(B)
A= $mime =~ m[^text/]iB= not $mime->attribute("charset")
ABresult
0X0
100
111
Truth table100%2/2
A
A= $charset
Aresult
11
00
140 if $mime =~ m!^text/!i && !$mime->attribute('charset');
141  
142 204 ▶ $self->transferEncoding($transfer) if defined $transfer;
Branch: 1 branch
BranchTrueFalseTotal
if defined $transfer 130 74 204
143 204 ▶ $self->disposition($disp) if defined $disp;
Branch: 1 branch
BranchTrueFalseTotal
if defined $disp 122 82 204
144 204 ▶ $self->description($descr) if defined $descr;
Branch: 1 branch
BranchTrueFalseTotal
if defined $descr 122 82 204
145 204 ▶ $self->contentId($cid) if defined $cid;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cid 122 82 204
146 204 $self->type($mime);
147  
148 204 ▶ $self->{MMB_eol} = $args->{eol} || 'NATIVE';
Condition50%1/2
$args->{'eol'} || 'NATIVE'
l!l
0204
MC/DC0%0/1
$args->{'eol'} || 'NATIVE'
$args->{'eol'}
Truth table50%1/2
A
A= $args->{'eol'}
Aresult
11
00
149  
150 # Set message where the body belongs to.
151  
152 $self->message($args->{message})
153 204 ▶ if defined $args->{message};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"message"} 12 192 204
154  
155 204 $self->{MMB_seqnr} = $body_count++;
156 204 $self;
157 }
158  
159  
160  
161 0 ▶sub clone() {shift->notImplemented}
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
162  
163 #------------------------------------------
164  
165  
166 sub decoded(@)
167 24 ▶{ my $self = shift;
Subroutine decoded: called CC=1 SCAR=0.0
Pod documented
168 24 $self->encode(charset => 'PERL', transfer_encoding => 'none', @_);
169 }
170  
171  
172 sub eol(;$)
173 0 ▶{ my $self = shift;
Subroutine eol: not called CC=14 SCAR=53.5
Pod documented
174 0 ▶ return $self->{MMB_eol} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
175  
176 0 my $eol = shift;
177 0 ▶ if($eol eq 'NATIVE')
Branch: 1 branch
BranchTrueFalseTotal
if ($eol eq "NATIVE") 0 0 0
178 0 ▶ { $eol = $^O =~ m/^win/i ? 'CRLF'
Branch: 2 branches
BranchTrueFalseTotal
$^O =~ /^win/i ? : 0 0 0
$^O =~ /^mac/i ? : 0 0 0
179 : $^O =~ m/^mac/i ? 'CR'
180 : 'LF';
181 }
182  
183 0 ▶ return $self if $eol eq $self->{MMB_eol} && $self->checked;
Branch: 1 branch
BranchTrueFalseTotal
if $eol eq $self->{"MMB_eol"} and $self->checked 0 0 0
Condition0%0/3
$eol eq $self->{"MMB_eol"} and $self->checked
!ll&&!rl&&r
000
MC/DC0%0/2
$eol eq $self->{"MMB_eol"} and $self->checked
$eol eq $self->{"MMB_eol"} $self->checked
Truth table0%0/3
A and B
A= $eol eq $self->{"MMB_eol"}B= $self->checked
ABresult
0X0
100
111
184 0 my $lines = $self->lines;
185 0 ▶ if(@$lines)
Branch: 1 branch
BranchTrueFalseTotal
if (@$lines) 0 0 0
186 { # sometimes texts lack \n on last line
187 0 $lines->[-1] .= "\n";
188
189  
190 0 ▶ if($eol eq 'CR') {s/[\015\012]+$/\015/ for @$lines}
Branch: 3 branches
BranchTrueFalseTotal
if ($eol eq 'CR') { } 0 0 0
elsif ($eol eq 'LF') { } 0 0 0
elsif ($eol eq 'CRLF') { } 0 0 0
191 0 elsif($eol eq 'LF') {s/[\015\012]+$/\012/ for @$lines}
192 0 elsif($eol eq 'CRLF') {s/[\015\012]+$/\015\012/ for @$lines}
193 else
194 0 { $self->log(WARNING => "Unknown line terminator $eol ignored");
195 0 return $self->eol('NATIVE');
196 }
197 }
198  
199 0 (ref $self)->new(based_on => $self, eol => $eol, data => $lines);
200 }
201  
202 #------------------------------------------
203  
204  
205 sub message(;$)
206 128 ▶{ my $self = shift;
Subroutine message: called CC=3 SCAR=11.0
Pod documented
207 128 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 121 7 128
208 121 ▶ { if($self->{MMB_message} = shift)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"MMB_message"} = shift()) 121 0 121
209 121 { weaken $self->{MMB_message};
210 }
211 }
212 128 $self->{MMB_message};
213 }
214  
215  
216 sub isDelayed() {0}
217  
218  
219 sub isMultipart() {0}
220  
221  
222 sub isNested() {0}
223  
224  
225 sub partNumberOf($)
226 0 ▶{ shift->log(ERROR => 'part number needs multi-part or nested');
Subroutine partNumberOf: not called CC=1 SCAR=6.9
Pod documented
227 0 'ERROR';
228 }
229  
230 #------------------------------------------
231  
232  
233 sub type(;$)
234 913 ▶{ my $self = shift;
Subroutine type: called CC=5 SCAR=16.1
Pod documented
235 913 ▶ return $self->{MMB_type} if !@_ && defined $self->{MMB_type};
Branch: 1 branch
BranchTrueFalseTotal
if not @_ and defined $self->{"MMB_type"} 488 425 913
Condition66%2/3
not @_ and defined $self->{"MMB_type"}
!ll&&!rl&&r
4250488
MC/DC50%1/2
not @_ and defined $self->{"MMB_type"}
not @_ defined $self->{"MMB_type"}
Truth table66%2/3
not(A) and B
A= not @_B= defined $self->{"MMB_type"}
ABresult
0X0
100
111
236  
237 425 delete $self->{MMB_mime};
238 425 ▶ my $type = defined $_[0] ? shift : 'text/plain';
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 419 6 425
239  
240 425 ▶ $self->{MMB_type} = ref $type ? $type->clone
Branch: 1 branch
BranchTrueFalseTotal
ref $type ? : 318 107 425
241 : Mail::Message::Field->new('Content-Type' => $type);
242 }
243  
244  
245 sub mimeType()
246 50 ▶{ my $self = shift;
Subroutine mimeType: called CC=5 SCAR=17.0
Pod documented
247 50 ▶ return $self->{MMB_mime} if exists $self->{MMB_mime};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"MMB_mime"} 20 30 50
248  
249 30 my $field = $self->{MMB_type};
250 30 ▶ my $body = defined $field ? $field->body : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $field ? : 30 0 30
251  
252 30 ▶ return $self->{MMB_mime} = $mime_plain
Branch: 1 branch
BranchTrueFalseTotal
unless length $body 0 30 30
253 unless length $body;
254  
255 $self->{MMB_mime}
256 30 ▶ = $mime_types->type($body) || MIME::Type->new(type => $body);
Condition33%1/3
$mime_types->type($body) || 'MIME::Type'->new('type', $body)
l!l&&r!l&&!r
3000
MC/DC0%0/2
$mime_types->type($body) || 'MIME::Type'->new('type', $body)
$mime_types->type($body) 'MIME::Type'->new('type', $body)
Truth table33%1/3
A || B
A= $mime_types->type($body)B= 'MIME::Type'->new('type', $body)
ABresult
1X1
011
000
257 }
258  
259  
260 62 ▶sub charset() { shift->type->attribute('charset') }
Subroutine charset: called CC=1 SCAR=0.0
Pod documented
261  
262  
263 sub transferEncoding(;$)
264 510 ▶{ my $self = shift;
Subroutine transferEncoding: called CC=5 SCAR=16.1
Pod documented
265 510 ▶ return $self->{MMB_transfer} if !@_ && defined $self->{MMB_transfer};
Branch: 1 branch
BranchTrueFalseTotal
if not @_ and defined $self->{"MMB_transfer"} 277 233 510
Condition100%3/3
not @_ and defined $self->{"MMB_transfer"}
!ll&&!rl&&r
18548277
MC/DC100%2/2
not @_ and defined $self->{"MMB_transfer"}
not @_ defined $self->{"MMB_transfer"}
Truth table100%3/3
not(A) and B
A= not @_B= defined $self->{"MMB_transfer"}
ABresult
0X0
100
111
266  
267 233 ▶ my $set = defined $_[0] ? shift : 'none';
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 177 56 233
268 233 ▶ $self->{MMB_transfer} = ref $set ? $set->clone
Branch: 1 branch
BranchTrueFalseTotal
ref $set ? : 118 115 233
269 : Mail::Message::Field->new('Content-Transfer-Encoding' => $set);
270 }
271  
272  
273 sub description(;$)
274 347 ▶{ my $self = shift;
Subroutine description: called CC=5 SCAR=16.1
Pod documented
275 347 ▶ return $self->{MMB_description} if !@_ && $self->{MMB_description};
Branch: 1 branch
BranchTrueFalseTotal
if not @_ and $self->{"MMB_description"} 156 191 347
Condition100%3/3
not @_ and $self->{"MMB_description"}
!ll&&!rl&&r
13952156
MC/DC100%2/2
not @_ and $self->{"MMB_description"}
not @_ $self->{"MMB_description"}
Truth table100%3/3
not(A) and B
A= not @_B= $self->{"MMB_description"}
ABresult
0X0
100
111
276  
277 191 ▶ my $disp = defined $_[0] ? shift : 'none';
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 126 65 191
278 191 ▶ $self->{MMB_description} = ref $disp ? $disp->clone
Branch: 1 branch
BranchTrueFalseTotal
ref $disp ? : 126 65 191
279 : Mail::Message::Field->new('Content-Description' => $disp);
280 }
281  
282  
283 sub disposition(;$)
284 349 ▶{ my $self = shift;
Subroutine disposition: called CC=5 SCAR=16.1
Pod documented
285 349 ▶ return $self->{MMB_disposition} if !@_ && $self->{MMB_disposition};
Branch: 1 branch
BranchTrueFalseTotal
if not @_ and $self->{"MMB_disposition"} 158 191 349
Condition100%3/3
not @_ and $self->{"MMB_disposition"}
!ll&&!rl&&r
13952158
MC/DC100%2/2
not @_ and $self->{"MMB_disposition"}
not @_ $self->{"MMB_disposition"}
Truth table100%3/3
not(A) and B
A= not @_B= $self->{"MMB_disposition"}
ABresult
0X0
100
111
286  
287 191 ▶ my $disp = defined $_[0] ? shift : 'none';
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 122 69 191
288  
289 191 ▶ $self->{MMB_disposition} = ref $disp ? $disp->clone
Branch: 1 branch
BranchTrueFalseTotal
ref $disp ? : 122 69 191
290 : Mail::Message::Field->new('Content-Disposition' => $disp);
291 }
292  
293  
294 sub contentId(;$)
295 347 ▶{ my $self = shift;
Subroutine contentId: called CC=5 SCAR=16.1
Pod documented
296 347 ▶ return $self->{MMB_id} if !@_ && $self->{MMB_id};
Branch: 1 branch
BranchTrueFalseTotal
if not @_ and $self->{"MMB_id"} 156 191 347
Condition100%3/3
not @_ and $self->{"MMB_id"}
!ll&&!rl&&r
13952156
MC/DC100%2/2
not @_ and $self->{"MMB_id"}
not @_ $self->{"MMB_id"}
Truth table100%3/3
not(A) and B
A= not @_B= $self->{"MMB_id"}
ABresult
0X0
100
111
297  
298 191 ▶ my $cid = defined $_[0] ? shift : 'none';
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 122 69 191
299 191 ▶ $self->{MMB_id} = ref $cid ? $cid->clone
Branch: 1 branch
BranchTrueFalseTotal
ref $cid ? : 122 69 191
300 : Mail::Message::Field->new('Content-ID' => $cid);
301 }
302  
303  
304 sub checked(;$)
305 101 ▶{ my $self = shift;
Subroutine checked: called CC=2 SCAR=7.2
Pod documented
306 101 ▶ @_ ? ($self->{MMB_checked} = shift) : $self->{MMB_checked};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 101 101
307 }
308  
309  
310 0 ▶sub nrLines(@) {shift->notImplemented}
Subroutine nrLines: not called CC=1 SCAR=6.9
Pod documented
311  
312  
313 0 ▶sub size(@) {shift->notImplemented}
Subroutine size: not called CC=1 SCAR=6.9
Pod documented
314  
315 #------------------------------------------
316  
317  
318 0 ▶sub string() {shift->notImplemented}
Subroutine string: not called CC=1 SCAR=6.9
Pod documented
319  
320 sub string_unless_carp()
321 21 ▶{ my $self = shift;
Subroutine string_unless_carp: called CC=2 SCAR=9.2
Pod undocumented
322 21 ▶ return $self->string unless (caller)[0] eq 'Carp';
Branch: 1 branch
BranchTrueFalseTotal
unless (caller)[0] eq "Carp" 21 0 21
323  
324 0 (my $class = ref $self) =~ s/^Mail::Message/MM/;
325 0 "$class object";
326 }
327  
328  
329 0 ▶sub lines() {shift->notImplemented}
Subroutine lines: not called CC=1 SCAR=6.9
Pod documented
330  
331  
332 0 ▶sub file(;$) {shift->notImplemented}
Subroutine file: not called CC=1 SCAR=6.9
Pod documented
333  
334  
335 0 ▶sub print(;$) {shift->notImplemented}
Subroutine print: not called CC=1 SCAR=6.9
Pod documented
336  
337  
338 0 ▶sub printEscapedFrom($) {shift->notImplemented}
Subroutine printEscapedFrom: not called CC=1 SCAR=6.9
Pod documented
339  
340  
341 sub write(@)
342 0 ▶{ my ($self, %args) = @_;
Subroutine write: not called CC=4 SCAR=30.0
Pod documented
343 0 my $filename = $args{filename};
344 0 ▶ die "No filename for write() body" unless defined $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $filename 0 0 0
345  
346 0 ▶ open OUT, '>', $filename or return;
Branch: 1 branch
BranchTrueFalseTotal
open OUT, ">", $filename or return 0 0 0
347 0 $self->print(\*OUT);
348 0 ▶ close OUT or return undef;
Branch: 1 branch
BranchTrueFalseTotal
close OUT or return undef 0 0 0
349 0 $self;
350 }
351  
352  
353 0 ▶sub endsOnNewline() {shift->notImplemented}
Subroutine endsOnNewline: not called CC=1 SCAR=6.9
Pod documented
354  
355  
356 0 ▶sub stripTrailingNewline() {shift->notImplemented}
Subroutine stripTrailingNewline: not called CC=1 SCAR=6.9
Pod documented
357  
358 #------------------------------------------
359  
360  
361 0 ▶sub read(@) {shift->notImplemented}
Subroutine read: not called CC=1 SCAR=6.9
Pod documented
362  
363  
364 sub contentInfoTo($)
365 86 ▶{ my ($self, $head) = @_;
Subroutine contentInfoTo: called CC=3 SCAR=11.1
Pod documented
366 86 ▶ return unless defined $head;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $head 0 86 86
367  
368 86 my $lines = $self->nrLines;
369 86 my $size = $self->size;
370 86 ▶ $size += $lines if $Mail::Message::crlf_platform;
Branch: 1 branch
BranchTrueFalseTotal
if $Mail::Message::crlf_platform 0 86 86
371  
372 86 $head->set($self->type);
373 86 $head->set($self->transferEncoding);
374 86 $head->set($self->disposition);
375 86 $head->set($self->description);
376 86 $head->set($self->contentId);
377 86 $self;
378 }
379  
380  
381 sub contentInfoFrom($)
382 17 ▶{ my ($self, $head) = @_;
Subroutine contentInfoFrom: called CC=4 SCAR=13.9
Pod documented
383  
384 17 $self->type($head->get('Content-Type', 0));
385  
386 my ($te, $disp, $desc, $cid)
387 17 ▶ = map { my $x = $head->get("Content-$_") || '';
Condition100%2/2
$head->get("Content-$_") || ''
l!l
1355
MC/DC100%1/1
$head->get("Content-$_") || ''
$head->get("Content-$_")
Truth table100%2/2
A
A= $head->get("Content-$_")
Aresult
11
00
388 68 s/^\s+//,s/\s+$// for $x;
389 68 ▶ length $x ? $x : undef
Branch: 1 branch
BranchTrueFalseTotal
length $x ? : 13 55 68
390 } qw/Transfer-Encoding Disposition Description ID/;
391  
392 17 $self->transferEncoding($te);
393 17 $self->disposition($disp);
394 17 $self->description($desc);
395 17 $self->contentId($cid);
396  
397 17 delete $self->{MMB_mime};
398 17 $self;
399  
400 }
401  
402  
403 sub modified(;$)
404 10 ▶{ my $self = shift;
Subroutine modified: called CC=2 SCAR=7.1
Pod documented
405 10 ▶ return $self->isModified unless @_; # compat 2.036
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 10 10
406 10 $self->{MMB_modified} = shift;
407 }
408  
409  
410 0 ▶sub isModified() { shift->{MMB_modified} }
Subroutine isModified: not called CC=1 SCAR=6.9
Pod documented
411  
412  
413 sub fileLocation(;@)
414 17 ▶{ my $self = shift;
Subroutine fileLocation: called CC=2 SCAR=6.9
Pod documented
415 17 ▶ return @$self{ qw/MMB_begin MMB_end/ } unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 2 15 17
416 15 @$self{ qw/MMB_begin MMB_end/ } = @_;
417 }
418  
419  
420 sub moveLocation($)
421 0 ▶{ my ($self, $dist) = @_;
Subroutine moveLocation: not called CC=1 SCAR=6.9
Pod documented
422 0 $self->{MMB_begin} -= $dist;
423 0 $self->{MMB_end} -= $dist;
424 0 $self;
425 }
426  
427  
428 2 ▶sub load() {shift}
Subroutine load: called CC=1 SCAR=0.0
Pod documented
429  
430 #------------------------------------------
431  
432  
433 31 my @in_encode = qw/check encode encoded eol isBinary isText unify
434 dispositionFilename/;
435 31 my %in_module = map { ($_ => 'encode') } @in_encode;
436  
437 sub AUTOLOAD(@)
438 14 ▶{ my $self = shift;
Subroutine AUTOLOAD: called CC=4 SCAR=13.9
439 14 our $AUTOLOAD;
440 14 (my $call = $AUTOLOAD) =~ s/.*\:\://g;
441  
442 14 ▶ my $mod = $in_module{$call} || 'construct';
Condition100%2/2
$in_module{$call} || 'construct'
l!l
113
MC/DC100%1/1
$in_module{$call} || 'construct'
$in_module{$call}
Truth table100%2/2
A
A= $in_module{$call}
Aresult
11
00
443 14 ▶ if($mod eq 'encode'){ require Mail::Message::Body::Encode }
Branch: 1 branch
BranchTrueFalseTotal
if ($mod eq 'encode') { } 11 3 14
444 3 else { require Mail::Message::Body::Construct }
445  
446 31 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
447 14 ▶ return $self->$call(@_) if $self->can($call); # now loaded
Branch: 1 branch
BranchTrueFalseTotal
if $self->can($call) 14 0 14
448  
449 # AUTOLOAD inheritance is a pain
450 0 confess "Method $call() is not defined for a ", ref $self;
451 }
452  
453 #------------------------------------------
454  
455  
456 31 1;
« Message/Field/Date.pm ↑ Summary Message/Replace/MailInternet.pm »