OK!

Here's my Proof of Concept to edit specific MIME types in a MIME Message. This example will only tweak parts that are in text/plain. How to exactly edit the mime part was graciously given by rob_au, all that had to after that was to create a recursive subroutine that would then reconstruct everything tweaked!

#!/usr/bin/perl -w use strict; use MIME::Parser; use MIME::Entity; my $parser = new MIME::Parser; $parser->output_to_core(1); #so here's our test MIME thingy: my $test = MIME::Entity->build(Type => "multipart/alternative", From => 'me@myhost.com', To => 'you@yourhost.com', Subject => "Test Test Test"); $test->attach(Type => "text/plain", Data => "This is the plain text stuff" ); $test->attach(Type => "text/html", Data => "<h1>This is the HTML stuff</h1>" ); # Let's print the, "Before" print $test->as_string(); $test = tweak_plain_text($test); print "\n\nAnd After...\n\n\n"; print $test->as_string(); sub tweak_plain_text { my $entity = shift; my @parts = $entity->parts; if(@parts){ my $i; foreach $i (0 .. $#parts) { $parts[$i]= tweak_plain_text($parts[$i]); } $entity->sync_headers('Length' => 'COMPUTE', 'Nonstandard' => 'ERASE'); }else{ if($entity->head->mime_type eq 'text/plain'){ my $body = $entity->bodyhandle; my $content = $body->as_string; $content .= "\nThis has been tweaked!!!!\n"; my $io = $body->open('w'); $io->print( $content ); $io->close; $entity->sync_headers('Length' => 'COMPUTE', 'Nonstandard' => 'ERASE'); } return $entity; } my $content = $entity->as_string; return $entity; }

Thanks everyone for the help!

 

-justin simoni
!skazat!


In reply to Re^2: Modifying MIME messages with MIME-Tools by skazat
in thread Modifying MIME messages with MIME-Tools by skazat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.