in reply to Re: Modifying MIME messages with MIME-Tools
in thread Modifying MIME messages with MIME-Tools

Rob,

Thanks for given me that to go on! I think I've cracked it! I did have to tweak your code to the following to make it work with my setup:

# The variable $entity contains a MIME::Entity object returned from +MIME::Parser # and from this object, a MIME::Body object is retrieved for content + manipulation. my $body = $entity->bodyhandle; my $content = $body->as_string; # The content of the MIME component can now be modified as you see f +it $content =~ s/foo/bar/g; # The updated content must now be written back into the MIME message + component - # This is performed through manipulation of the MIME::Body object. my $io = $body->open('w'); $io->print( $content ) $io->close; # At this point, you may need to re-synchronise the headers of the M +IME::Entity # object - This method will add or update a Content-Length header wi +thin the # MIME component. $entity->sync_headers( 'Length' => 'COMPUTE', 'Nonstandard' => 'ERASE' );

basically, the line that says,

my $body = $entity->body; Needed to be:

my $body = $entity->bodyhandle;

 

-justin simoni
!skazat!