Re: rebuilding a message from a $Message->decoded

Gilles <[email protected]> Tue, 8 Feb 2005 01:26:40 +0100
Newsgroups gmane.comp.lang.perl.modules.mail-box
Message-ID <[email protected]>
> $Body=$Message->decoded;

Here "$Body" is an instance of the Mail::Message::Body class.

> make some regex changes to the $Body, for instance;
> 
>  my $text = qr(Content-Type:\s*text/plain.+?\n\n)is;
>  my $html = qr(Content-Type:\s*text/html.+?\n\n)is;
>  my $addr = "Original address as received:$From";
>  $Body =~ s/($html)/$1\n<p>$addr<br>\n\n/;
>  $Body =~ s/($text)/$1\n$addr\n\n/;

So, you should certainly not expect the above to work as if it
was just a string!

Look at the synopsis of "Mail::Message::Body" and you'll find a.o.

  my $text  = $body->string;

Then you can do your replacements to "$text".

Afterwards, you have to build a new "Mail::Message::Body" to be used
with "buildFromBody"...

> my $SendableMessage=Mail::Message->buildFromBody($Body) ;

Hence this is wrong.

But you can construct a message more simply:

  my $msg = Mail::Message->build( From => 'me',
                                  To   => 'you',
                                  data => $text ) ;

where $text *is* a string here.
More details in the doc for "Mail::Message::Construct::Build".


Gilles