| 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::File; | ||||||||||||||||||||
| 10 | 31 | ▶ | use vars '$VERSION'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 31 | $VERSION = '3.012'; | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 31 | ▶ | use base 'Mail::Message::Body'; | ||||||||||||||||||
|
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::Box::Parser; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 31 | ▶ | use Mail::Message; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 31 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | 31 | ▶ | use File::Temp qw/tempfile/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | 31 | ▶ | use File::Copy qw/copy/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | sub _data_from_filename(@) | ||||||||||||||||||||
| 27 | 0 | ▶ | { my ($self, $filename) = @_; | ||||||||||||||||||
|
Subroutine
_data_from_filename: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 0 | local $_; | |||||||||||||||||||
| 30 | 0 | local (*IN, *OUT); | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 0 | ▶ | unless(open IN, '<:raw', $filename) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | 0 | { $self->log(ERROR => | |||||||||||||||||||
| 34 | "Unable to read file $filename for message body file: $!"); | ||||||||||||||||||||
| 35 | 0 | return; | |||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 0 | my $file = $self->tempFilename; | |||||||||||||||||||
| 39 | 0 | ▶ | unless(open OUT, '>:raw', $file) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | 0 | { $self->log(ERROR => "Cannot write to temporary body file $file: $!"); | |||||||||||||||||||
| 41 | 0 | return; | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 0 | my $nrlines = 0; | |||||||||||||||||||
| 45 | 0 | ▶ | while(<IN>) { print OUT; $nrlines++ } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 0 | close OUT; | |||||||||||||||||||
| 48 | 0 | close IN; | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 0 | $self->{MMBF_nrlines} = $nrlines; | |||||||||||||||||||
| 51 | 0 | $self; | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | sub _data_from_filehandle(@) | ||||||||||||||||||||
| 55 | 1 | ▶ | { my ($self, $fh) = @_; | ||||||||||||||||||
|
Subroutine
_data_from_filehandle: called CC=3 SCAR=11.1
| |||||||||||||||||||||
| 56 | 1 | my $file = $self->tempFilename; | |||||||||||||||||||
| 57 | 1 | my $nrlines = 0; | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 1 | local *OUT; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 1 | ▶ | unless(open OUT, '>:raw', $file) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | 0 | { $self->log(ERROR => "Cannot write to temporary body file $file: $!"); | |||||||||||||||||||
| 63 | 0 | return; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 1 | ▶ | while(my $l = $fh->getline) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 67 | 5 | { print OUT $l; | |||||||||||||||||||
| 68 | 5 | $nrlines++; | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | 1 | close OUT; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 1 | $self->{MMBF_nrlines} = $nrlines; | |||||||||||||||||||
| 73 | 1 | $self; | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | sub _data_from_glob(@) | ||||||||||||||||||||
| 77 | 0 | ▶ | { my ($self, $fh) = @_; | ||||||||||||||||||
|
Subroutine
_data_from_glob: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 78 | 0 | my $file = $self->tempFilename; | |||||||||||||||||||
| 79 | 0 | my $nrlines = 0; | |||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 0 | local $_; | |||||||||||||||||||
| 82 | 0 | local *OUT; | |||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 0 | ▶ | unless(open OUT, '>:raw', $file) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 85 | 0 | { $self->log(ERROR => "Cannot write to temporary body file $file: $!"); | |||||||||||||||||||
| 86 | 0 | return; | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 0 | ▶ | while(<$fh>) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 90 | 0 | { print OUT; | |||||||||||||||||||
| 91 | 0 | $nrlines++; | |||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | 0 | close OUT; | |||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 0 | $self->{MMBF_nrlines} = $nrlines; | |||||||||||||||||||
| 96 | 0 | $self; | |||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | sub _data_from_lines(@) | ||||||||||||||||||||
| 100 | 1 | ▶ | { my ($self, $lines) = @_; | ||||||||||||||||||
|
Subroutine
_data_from_lines: called CC=2 SCAR=7.2
| |||||||||||||||||||||
| 101 | 1 | my $file = $self->tempFilename; | |||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 1 | local *OUT; | |||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 1 | ▶ | unless(open OUT, '>:raw', $file) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 106 | 0 | { $self->log(ERROR => "Cannot write to $file: $!"); | |||||||||||||||||||
| 107 | 0 | return; | |||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 1 | print OUT @$lines; | |||||||||||||||||||
| 111 | 1 | close OUT; | |||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 1 | $self->{MMBF_nrlines} = @$lines; | |||||||||||||||||||
| 114 | 1 | $self; | |||||||||||||||||||
| 115 | } | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | sub clone() | ||||||||||||||||||||
| 118 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||
|
Subroutine
clone: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 119 | 0 | my $clone = ref($self)->new(based_on => $self); | |||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | 0 | ▶ | copy($self->tempFilename, $clone->tempFilename) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 122 | or return; | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | 0 | $clone->{MMBF_nrlines} = $self->{MMBF_nrlines}; | |||||||||||||||||||
| 125 | 0 | $clone->{MMBF_size} = $self->{MMBF_size}; | |||||||||||||||||||
| 126 | 0 | $self; | |||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | sub nrLines() | ||||||||||||||||||||
| 130 | 2 | ▶ | { my $self = shift; | ||||||||||||||||||
|
Subroutine
nrLines: called CC=4 SCAR=25.3
Pod
documented
| |||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | return $self->{MMBF_nrlines} | ||||||||||||||||||||
| 133 | 2 | ▶ | if defined $self->{MMBF_nrlines}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | 0 | my $file = $self->tempFilename; | |||||||||||||||||||
| 136 | 0 | my $nrlines = 0; | |||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | 0 | local $_; | |||||||||||||||||||
| 139 | 0 | local *IN; | |||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | 0 | ▶ | open IN, '<:raw', $file | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 142 | or die "Cannot read from $file: $!\n"; | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | 0 | ▶ | $nrlines++ while <IN>; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 145 | 0 | close IN; | |||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | 0 | $self->{MMBF_nrlines} = $nrlines; | |||||||||||||||||||
| 148 | } | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | #------------------------------------------ | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | sub size() | ||||||||||||||||||||
| 153 | 2 | ▶ | { my $self = shift; | ||||||||||||||||||
|
Subroutine
size: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | return $self->{MMBF_size} | ||||||||||||||||||||
| 156 | 2 | ▶ | if exists $self->{MMBF_size}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 157 | |||||||||||||||||||||
| 158 | 2 | my $size = eval { -s $self->tempFilename }; | |||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | 2 | ▶ | $size -= $self->nrLines | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 161 | if $Mail::Message::crlf_platform; # remove count for extra CR's | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | 2 | $self->{MMBF_size} = $size; | |||||||||||||||||||
| 164 | } | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | sub string() | ||||||||||||||||||||
| 167 | 3 | ▶ | { my $self = shift; | ||||||||||||||||||
|
Subroutine
string: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | 3 | my $file = $self->tempFilename; | |||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | 3 | local *IN; | |||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | 3 | ▶ | open IN, '<:raw', $file | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 174 | or die "Cannot read from $file: $!\n"; | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | 3 | my $return = join '', <IN>; | |||||||||||||||||||
| 177 | 3 | close IN; | |||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | 3 | $return; | |||||||||||||||||||
| 180 | } | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | sub lines() | ||||||||||||||||||||
| 183 | 3 | ▶ | { my $self = shift; | ||||||||||||||||||
|
Subroutine
lines: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | 3 | my $file = $self->tempFilename; | |||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | 3 | local *IN; | |||||||||||||||||||
| 188 | 3 | ▶ | open IN, '<:raw', $file | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 189 | or die "Cannot read from $file: $!\n"; | ||||||||||||||||||||
| 190 | |||||||||||||||||||||
| 191 | 3 | my @r = <IN>; | |||||||||||||||||||
| 192 | 3 | close IN; | |||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | 3 | $self->{MMBF_nrlines} = @r; | |||||||||||||||||||
| 195 | 3 | ▶ | wantarray ? @r: \@r; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 196 | } | ||||||||||||||||||||
| 197 | |||||||||||||||||||||
| 198 | sub file() | ||||||||||||||||||||
| 199 | 0 | ▶ | { open my $tmp, '<:raw', shift->tempFilename; | ||||||||||||||||||
|
Subroutine
file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 200 | 0 | $tmp; | |||||||||||||||||||
| 201 | } | ||||||||||||||||||||
| 202 | |||||||||||||||||||||
| 203 | sub print(;$) | ||||||||||||||||||||
| 204 | 2 | ▶ | { my $self = shift; | ||||||||||||||||||
|
Subroutine
print: called CC=6 SCAR=19.7
Pod
documented
| |||||||||||||||||||||
| 205 | 2 | ▶ | my $fh = shift || select; | ||||||||||||||||||
|
Condition33%1/3
shift() || select()
MC/DC0%0/2
shift() || select()
shift()
select()
Truth table33%1/3
A || B
A= shift()B= select()
| |||||||||||||||||||||
| 206 | 2 | my $file = $self->tempFilename; | |||||||||||||||||||
| 207 | |||||||||||||||||||||
| 208 | 2 | local $_; | |||||||||||||||||||
| 209 | 2 | local *IN; | |||||||||||||||||||
| 210 | |||||||||||||||||||||
| 211 | 2 | ▶ | open IN, '<:raw', $file | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 212 | or croak "Cannot read from $file: $!\n"; | ||||||||||||||||||||
| 213 | |||||||||||||||||||||
| 214 | 2 | ▶ | if(ref $fh eq 'GLOB') {print $fh $_ while <IN>} | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 215 | 2 | ▶ | else {$fh->print($_) while <IN>} | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 216 | 2 | close IN; | |||||||||||||||||||
| 217 | |||||||||||||||||||||
| 218 | 2 | $self; | |||||||||||||||||||
| 219 | } | ||||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | sub read($$;$@) | ||||||||||||||||||||
| 222 | 0 | ▶ | { my ($self, $parser, $head, $bodytype) = splice @_, 0, 4; | ||||||||||||||||||
|
Subroutine
read: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 223 | 0 | my $file = $self->tempFilename; | |||||||||||||||||||
| 224 | |||||||||||||||||||||
| 225 | 0 | local *OUT; | |||||||||||||||||||
| 226 | |||||||||||||||||||||
| 227 | 0 | ▶ | open OUT, '>:raw', $file | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 228 | or die "Cannot write to $file: $!.\n"; | ||||||||||||||||||||
| 229 | |||||||||||||||||||||
| 230 | 0 | (my $begin, my $end, $self->{MMBF_nrlines}) = $parser->bodyAsFile(\*OUT,@_); | |||||||||||||||||||
| 231 | 0 | close OUT; | |||||||||||||||||||
| 232 | |||||||||||||||||||||
| 233 | 0 | $self->fileLocation($begin, $end); | |||||||||||||||||||
| 234 | 0 | $self; | |||||||||||||||||||
| 235 | } | ||||||||||||||||||||
| 236 | |||||||||||||||||||||
| 237 | # on UNIX always true. Expensive to calculate on Windows: message size | ||||||||||||||||||||
| 238 | # may be off-by-one in rare cases. | ||||||||||||||||||||
| 239 | 0 | ▶ | sub endsOnNewline() { shift->size==0 } | ||||||||||||||||||
|
Subroutine
endsOnNewline: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 240 | |||||||||||||||||||||
| 241 | #------------------------------------------ | ||||||||||||||||||||
| 242 | |||||||||||||||||||||
| 243 | |||||||||||||||||||||
| 244 | sub tempFilename(;$) | ||||||||||||||||||||
| 245 | 15 | ▶ | { my $self = shift; | ||||||||||||||||||
|
Subroutine
tempFilename: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||
| 246 | |||||||||||||||||||||
| 247 | @_ ? ($self->{MMBF_filename} = shift) | ||||||||||||||||||||
| 248 | : $self->{MMBF_filename} ? $self->{MMBF_filename} | ||||||||||||||||||||
| 249 | 15 | ▶ | : ($self->{MMBF_filename} = (tempfile)[1]); | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 250 | } | ||||||||||||||||||||
| 251 | |||||||||||||||||||||
| 252 | #------------------------------------------ | ||||||||||||||||||||
| 253 | |||||||||||||||||||||
| 254 | |||||||||||||||||||||
| 255 | 2 | ▶ | sub DESTROY { unlink shift->tempFilename } | ||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 256 | |||||||||||||||||||||
| 257 | #------------------------------------------ | ||||||||||||||||||||
| 258 | |||||||||||||||||||||
| 259 | 31 | 1; | |||||||||||||||||||