1# Copyrights 2001-2021 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.02. 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 9package Mail::Message::Body::Nested; 10use vars '$VERSION'; 11$VERSION = '3.011'; 12 13use base 'Mail::Message::Body'; 14 15use strict; 16use warnings; 17 18use Mail::Message::Body::Lines; 19use Mail::Message::Part; 20 21use Carp; 22 23 24sub init($) 25{ my ($self, $args) = @_; 26 $args->{mime_type} ||= 'message/rfc822'; 27 28 $self->SUPER::init($args); 29 30 my $nested; 31 if(my $raw = $args->{nested}) 32 { $nested = Mail::Message::Part->coerce($raw, $self); 33 34 croak 'Data not convertible to a message (type is ', ref $raw,")\n" 35 unless defined $nested; 36 } 37 38 $self->{MMBN_nested} = $nested; 39 $self; 40} 41 42sub isNested() {1} 43 44sub isBinary() { shift->nested->body->isBinary } 45 46sub clone() 47{ my $self = shift; 48 49 ref($self)->new 50 ( $self->logSettings 51 , based_on => $self 52 , nested => $self->nested->clone 53 ); 54} 55 56sub nrLines() { shift->nested->nrLines } 57 58sub size() { shift->nested->size } 59 60sub string() 61{ my $nested = shift->nested; 62 defined $nested ? $nested->string : ''; 63} 64 65sub lines() 66{ my $nested = shift->nested; 67 defined $nested ? ($nested->lines) : (); 68} 69 70sub file() 71{ my $nested = shift->nested; 72 defined $nested ? $nested->file : undef; 73} 74 75sub print(;$) 76{ my $self = shift; 77 $self->nested->print(shift || select); 78} 79 80sub partNumberOf($) 81{ my ($self, $part) = @_; 82 $self->message->partNumber; 83} 84 85 86sub foreachLine($) 87{ my ($self, $code) = @_; 88 $self->log(ERROR => "You cannot use foreachLine on a nested"); 89 confess; 90} 91 92sub check() { shift->forNested( sub {$_[1]->check} ) } 93 94sub encode(@) 95{ my ($self, %args) = @_; 96 $self->forNested( sub {$_[1]->encode(%args)} ); 97} 98 99sub encoded() { shift->forNested( sub {$_[1]->encoded} ) } 100 101sub read($$$$) 102{ my ($self, $parser, $head, $bodytype) = @_; 103 104 my $nest = Mail::Message::Part->new(container => undef); 105 $nest->readFromParser($parser, $bodytype) 106 or return; 107 108 $nest->container($self); 109 $self->{MMBN_nested} = $nest; 110 $self; 111} 112 113sub fileLocation() 114{ my $nested = shift->nested; 115 116 ( ($nested->head->fileLocation)[0] 117 , ($nested->body->fileLocation)[1] 118 ); 119} 120 121sub endsOnNewline() { shift->nested->body->endsOnNewline } 122 123sub moveLocation($) 124{ my $self = shift; 125 my $nested = $self->nested; 126 my $dist = shift or return $self; # no move 127 128 $nested->head->moveLocation($dist); 129 $nested->body->moveLocation($dist); 130 $self; 131} 132 133 134sub nested() { shift->{MMBN_nested} } 135 136 137sub forNested($) 138{ my ($self, $code) = @_; 139 my $nested = $self->nested; 140 my $body = $nested->body; 141 142 my $new_body = $code->($self, $body) 143 or return; 144 145 return $self if $new_body == $body; 146 147 my $new_nested = Mail::Message::Part->new 148 ( head => $nested->head->clone 149 , container => undef 150 ); 151 152 $new_nested->body($new_body); 153 154 my $created = (ref $self)->new 155 ( based_on => $self 156 , nested => $new_nested 157 ); 158 159 $new_nested->container($created); 160 $created; 161} 162 163sub toplevel() { my $msg = shift->message; $msg ? $msg->toplevel : undef} 164 1651; 166