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
|
use strict;
use warnings;
package Mail::Message::Field::Fast;
use vars '$VERSION';
$VERSION = '2.068';
use base 'Mail::Message::Field';
#------------------------------------------
#
# The DATA is stored as: [ NAME, FOLDED-BODY ]
# The body is kept in a folded fashion, where each line starts with
# a single blank.
sub new($;$@)
{ my $class = shift;
my ($name, $body) = $class->consume(@_==1 ? (shift) : (shift, shift));
return () unless defined $body;
my $self = bless [$name, $body], $class;
# Attributes
$self->comment(shift) if @_==1; # one attribute line
$self->attribute(shift, shift) while @_ > 1; # attribute pairs
$self;
}
#------------------------------------------
sub clone()
{ my $self = shift;
bless [ @$self ], ref $self;
}
#------------------------------------------
sub length()
{ my $self = shift;
length($self->[0]) + 1 + length($self->[1]);
}
#------------------------------------------
sub name() { lc shift->[0] }
#------------------------------------------
sub Name() { shift->[0] }
#------------------------------------------
sub folded()
{ my $self = shift;
return $self->[0].':'.$self->[1]
unless wantarray;
my @lines = $self->foldedBody;
my $first = $self->[0]. ':'. shift @lines;
($first, @lines);
}
#------------------------------------------
sub unfoldedBody($;@)
{ my $self = shift;
$self->[1] = $self->fold($self->[0], @_)
if @_;
$self->unfold($self->[1]);
}
#------------------------------------------
sub foldedBody($)
{ my ($self, $body) = @_;
if(@_==2) { $self->[1] = $body }
else { $body = $self->[1] }
wantarray ? (split m/^/, $body) : $body;
}
#------------------------------------------
# For performance reasons only
sub print(;$)
{ my $self = shift;
my $fh = shift || select;
if(ref $fh eq 'GLOB') { print $fh $self->[0].':'.$self->[1] }
else { $fh->print($self->[0].':'.$self->[1]) }
$self;
}
#------------------------------------------
1;
|