Ok, I think I have sorted this out, and I felt I should post a follow-up in case anyone else every stumbles across what I found.

I am going to illustrate this with an example...

Lets say you want to use Email::MIME in an email list server and you need to walk the text parts of the email to add unsubscribe links that are distinct for each end recipient in the list. You need to somehow save the original state of the parts so that you do not keep adding unsubscribe links on to them... there should be one link that is distinct for each user...

You could do the following below to make an independent clone of the parts... this is necessary so that when you walk the MIME parts and add the unsubscribe links, you have an independent cloned structure (@orig_parts below) to revert back to.

@orig_parts = $email->subparts; $email->parts_set(\@orig_parts); # *** like a copy constructor; makes + @orig_parts independent

What I discovered before I added the parts_set above was that @orig_parts was getting updated every time I would subsequently walk the MIME parts and add the unsubscribe link. It was giving me fits. Apparently, there must be sort sort of back reference from the array produced by $email->subparts into the MIME structures for the email.

However, when you take the array and feed it back into $email->parts_set, the code rebuilds the email parts... it essentially works like a copy constructor, which makes the original array independent. It does not then get updated when you walk the MIME parts and make parts modifications.


In reply to Re: Need advice w/ Email::MIME by SteveTheTechie
in thread Need advice w/ Email::MIME by SteveTheTechie

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.