| 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::Body::File;{ | ||||||||||||||||||||||||||||
| 13 | 37 | our $VERSION = '4.05'; | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 37 | ▶ | use parent 'Mail::Message::Body'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 37 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 37 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 37 | ▶ | use Log::Report 'mail-message', import => [ qw/__x fault/ ]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 37 | ▶ | use File::Temp qw/tempfile/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 37 | ▶ | use File::Copy qw/copy/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 37 | ▶ | use Fcntl qw/SEEK_END/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 37 | ▶ | use Mail::Box::Parser (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 37 | ▶ | use Mail::Message (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | #-------------------- | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub _data_from_filename(@) | ||||||||||||||||||||||||||||
| 33 | 0 | ▶ | { my ($self, $filename) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_data_from_filename: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | open my $in, '<:raw', $filename | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | or fault __x"unable to read file {name} for message body file", name => $filename; | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | my $file = $self->tempFilename; | |||||||||||||||||||||||||||
| 39 | 0 | ▶ | open my $out, '>:raw', $file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | or fault __x"cannot write to temporary body file {name}", name => $file; | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | my $nrlines = 0; | |||||||||||||||||||||||||||
| 43 | 0 | local $_; | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | while(<$in>) { $out->print($_); $nrlines++ } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | $self->{MMBF_nrlines} = $nrlines; | |||||||||||||||||||||||||||
| 46 | 0 | $self; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | sub _data_from_filehandle(@) | ||||||||||||||||||||||||||||
| 50 | 1 | ▶ | { my ($self, $fh) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_data_from_filehandle: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 51 | 1 | my $file = $self->tempFilename; | |||||||||||||||||||||||||||
| 52 | 1 | my $nrlines = 0; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | ▶ | open my $out, '>:raw', $file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | or fault __x"cannot write to temporary body file {name}", name => $file; | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 1 | local $_; | |||||||||||||||||||||||||||
| 58 | 1 | ▶ | while(<$fh>) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 5 | { $out->print($_); | |||||||||||||||||||||||||||
| 60 | 5 | $nrlines++; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | $self->{MMBF_nrlines} = $nrlines; | |||||||||||||||||||||||||||
| 64 | 1 | $self; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | sub _data_from_lines(@) | ||||||||||||||||||||||||||||
| 68 | 1 | ▶ | { my ($self, $lines) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_data_from_lines: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 69 | 1 | my $file = $self->tempFilename; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 1 | ▶ | open my $out, '>:raw', $file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | or fault __x"cannot write body to file {name}", name => $file; | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 1 | $out->print(@$lines); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 1 | $self->{MMBF_nrlines} = @$lines; | |||||||||||||||||||||||||||
| 77 | 1 | $self; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | sub clone() | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 0 | my $clone = ref($self)->new(based_on => $self); | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | copy $self->tempFilename, $clone->tempFilename | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | or return; | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | $clone->{MMBF_nrlines} = $self->{MMBF_nrlines}; | |||||||||||||||||||||||||||
| 88 | 0 | $clone->{MMBF_size} = $self->{MMBF_size}; | |||||||||||||||||||||||||||
| 89 | 0 | $self; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | sub nrLines() | ||||||||||||||||||||||||||||
| 94 | 2 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
nrLines: called CC=4 SCAR=24.6
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 2 | ▶ | return $self->{MMBF_nrlines} if defined $self->{MMBF_nrlines}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | my $file = $self->tempFilename; | |||||||||||||||||||||||||||
| 98 | 0 | my $nrlines = 0; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | open my $in, '<:raw', $file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | or fault __x"cannot read from file {name}", name => $file; | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | local $_; | |||||||||||||||||||||||||||
| 104 | 0 | ▶ | $nrlines++ while <$in>; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | $self->{MMBF_nrlines} = $nrlines; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | sub size() | ||||||||||||||||||||||||||||
| 110 | 2 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
size: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | return $self->{MMBF_size} | ||||||||||||||||||||||||||||
| 113 | 2 | ▶ | if exists $self->{MMBF_size}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 2 | my $size = eval { -s $self->tempFilename }; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 2 | ▶ | $size -= $self->nrLines | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | if $Mail::Message::crlf_platform; # remove count for extra CR's | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 2 | $self->{MMBF_size} = $size; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | sub string() | ||||||||||||||||||||||||||||
| 125 | 3 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
string: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | 3 | my $file = $self->tempFilename; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 3 | ▶ | open my $in, '<:raw', $file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | or fault __x"cannot read from file {name}", name => $file; | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 3 | join '', $in->getlines; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | sub lines() | ||||||||||||||||||||||||||||
| 136 | 3 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
lines: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 137 | 3 | my $file = $self->tempFilename; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 3 | ▶ | open my $in, '<:raw', $file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | or fault __x"cannot read from file {name}", name => $file; | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 3 | my $r = $self->{MMBF_nrlines} = [ $in->getlines ]; | |||||||||||||||||||||||||||
| 143 | 3 | ▶ | wantarray ? @$r: $r; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | sub file() | ||||||||||||||||||||||||||||
| 147 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 148 | 0 | open my($tmp), '<:raw', $self->tempFilename; | |||||||||||||||||||||||||||
| 149 | 0 | $tmp; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | sub print(;$) | ||||||||||||||||||||||||||||
| 154 | 2 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
print: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||
| 155 | 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()
| |||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 2 | my $file = $self->tempFilename; | |||||||||||||||||||||||||||
| 158 | 2 | ▶ | open my $in, '<:raw', $file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | or fault __x"cannot read from file {name}", name => $file; | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 2 | ▶ | $fh->print($_) while <$in>; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | 2 | $in->close; | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 2 | $self; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | sub endsOnNewline() | ||||||||||||||||||||||||||||
| 169 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
endsOnNewline: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | my $file = $self->tempFilename; | |||||||||||||||||||||||||||
| 172 | 0 | ▶ | open my $in, '<:raw', $file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | or fault __x"cannot read from file {name}", name => $file; | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 0 | $in->seek(-1, SEEK_END); | |||||||||||||||||||||||||||
| 176 | 0 | $in->read(my $char, 1); | |||||||||||||||||||||||||||
| 177 | 0 | ▶ | $char eq "\n" || $char eq "\r"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | sub read($$;$@) | ||||||||||||||||||||||||||||
| 182 | 0 | ▶ | { my ($self, $parser, $head, $bodytype) = splice @_, 0, 4; | ||||||||||||||||||||||||||
|
Subroutine
read: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 183 | 0 | my $file = $self->tempFilename; | |||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 0 | ▶ | open my $out, '>:raw', $file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | or fault __x"cannot write to file {name}", name => $file; | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 0 | (my $begin, my $end, $self->{MMBF_nrlines}) = $parser->bodyAsFile($out, @_); | |||||||||||||||||||||||||||
| 189 | 0 | $out->close; | |||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | $self->fileLocation($begin, $end); | |||||||||||||||||||||||||||
| 192 | 0 | $self; | |||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | #-------------------- | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | sub tempFilename(;$) | ||||||||||||||||||||||||||||
| 198 | 15 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
tempFilename: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||
| 199 | 15 | ▶ | @_ ? ($self->{MMBF_filename} = shift) : ($self->{MMBF_filename} //= (tempfile)[1]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"MMBF_filename"} //= (tempfile())[1]
MC/DC0%0/2
$self->{"MMBF_filename"} //= (tempfile())[1]
$self->{"MMBF_filename"}
(tempfile())[1]
Truth table66%2/3
A //= B
A= $self->{"MMBF_filename"}B= (tempfile())[1]
| |||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | #-------------------- | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 2 | ▶ | sub DESTROY { unlink $_[0]->tempFilename } | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 37 | 1; | |||||||||||||||||||||||||||