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