SteveTheTechie has asked for the wisdom of the Perl Monks concerning the following question:
I am transitioning from Email::Simple to Email::MIME since I need to manipulate the parts of multi-part emails, and I want to get rid of the hacky code I was using for this with Email::Simple.
I am doing email list expansions in a email list server, and emails to some lists get an unsubscribe link inserted at the bottom of the text (text/plain & text/html) parts.
I have the walk_parts code set up to do the unsubscribe link inserts, and all is good with that.
Where I am running into problems is with resetting the email body parts to the original on each pass to a recipient in the list. I manipulate the headers on each pass but I really do not want to reparse the original email, just reset the body parts. I have to do this so that the unsubscribe links are distinct and I do not append multiple unsubscribe links.
For Email::Simple, I would just do
$orig_body = $email->body;and then reset the body later with
$email->body_set($orig_body);However, this does not seem to work with Email::MIME, even though it is derived from Email::Simple. I have tried the following (thinking I needed to reset the parts):
@orig_parts = $email->subparts;and then to reset
$email->parts_set(\@orig_parts);However, resetting the parts to the original parts does not seem to always work consistently. Per my test log, I have seen a case where I did the parts reset, then dumped the $email->as_string only to see that the reset did not really occur.
It did occur to me that maybe I need to do something with body_raw, but frankly I am a bit uncertain as to the best approach to reset the email body back to the original without reparsing everything and having to redo all the headers. (major pain)
Anyone have any ideas on how to reset the body parts? (Much thanks in advance.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need advice w/ Email::MIME
by SteveTheTechie (Novice) on Jun 16, 2015 at 22:31 UTC |