What I would do is find the first text/plain part in the message, munge that and use it as the sole body in the outgoing message. the reason for that is you can be almost certain that the mail will contain a text/plain part and by removing all other parts you don't have to worry about ppl seeing them. If you need to munge every single part you have your work cut out for you. You could theoretically have a alternative part which is sound, not to mention mixed inside alternative inside mixed. And I have seen text/rtf inside a multipart/alternative

As for a full strategy I'd probably go OO style and make a object for each mime type which has functions for each of the actions you need to perform eg $txt->replace_string('foo', 'bar'). Then container types would call the functions on whatever they contain. Any type you don't have a handler for gets dropped from the message when you parse it in. So now your munging is basically $body->replace_string('foo', 'bar') and that's all in one place which just works on all the different types you support.


In reply to Re: Advice for email munging by tedrek
in thread Advice for email munging by Limbic~Region

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.