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
|
# This code is part of Perl distribution Mail-Message version 4.02.
# The POD got stripped from this file by OODoc version 3.06.
# For contributors see file ChangeLog.
# This software is copyright (c) 2001-2026 by Mark Overmeer.
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
# SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
package Mail::Message::Body::Lines;{
our $VERSION = '4.02';
}
use parent 'Mail::Message::Body';
use strict;
use warnings;
use Log::Report 'mail-message', import => [ qw/__x fault/ ];
use Mail::Box::Parser ();
use IO::Lines ();
#--------------------
sub _data_from_filename(@)
{ my ($self, $filename) = @_;
open my $in, '<:raw', $filename
or fault __x"unable to read file {name} for message body lines", name => $filename;
$self->{MMBL_array} = [ $in->getlines ];
$in->close;
$self;
}
sub _data_from_filehandle(@)
{ my ($self, $fh) = @_;
$self->{MMBL_array} = ref $fh eq 'Mail::Box::FastScalar' ? $fh->getlines : [ $fh->getlines ];
$self;
}
sub _data_from_lines(@)
{ my ($self, $lines) = @_;
$lines = [ split /^/, $lines->[0] ] # body passed in one string.
if @$lines==1;
$self->{MMBL_array} = $lines;
$self;
}
sub clone()
{ my $self = shift;
(ref $self)->new(data => [ $self->lines ], based_on => $self);
}
sub nrLines() { scalar @{ $_[0]->{MMBL_array}} }
# Optimized to be computed only once.
sub size()
{ my $self = shift;
return $self->{MMBL_size} if exists $self->{MMBL_size};
my $size = 0;
$size += length $_ for @{$self->{MMBL_array}};
$self->{MMBL_size} = $size;
}
sub string() { join '', @{$_[0]->{MMBL_array}} }
sub lines() { wantarray ? @{$_[0]->{MMBL_array}} : $_[0]->{MMBL_array} }
sub file() { IO::Lines->new($_[0]->{MMBL_array}) }
sub print(;$)
{ my $self = shift;
(shift || select)->print(@{$self->{MMBL_array}});
$self;
}
sub endsOnNewline()
{ my $last = $_[0]->{MMBL_array}[-1];
!defined $last || $last =~ /[\r\n]$/;
}
sub read($$;$@)
{ my ($self, $parser, $head, $bodytype) = splice @_, 0, 4;
my ($begin, $end, $lines) = $parser->bodyAsList(@_);
$lines or return undef;
$self->fileLocation($begin, $end);
$self->{MMBL_array} = $lines;
$self;
}
1;
|