in reply to Need advice w/ Email::MIME
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.
|
|---|