How to serialize a Zend_Mail_Message?
-
28-06-2021 - |
Question
I have several Zend_Mail_Message
objects that I got from an IMAP query.
Now I want to serialize each message individually.
However, it seems that a simple:
serialize($message);
doesn't work because the message has attachments (multipart), and the parts don't get serialized.
So, how to serialize a complete Zend_Mail_Message
object, including parts (attachements)?
Solution
I figured it out. Basically Zend_Mail_Message has cache mechanism, so when you get a part from the message it doesn't ask the IMAP server again for that part.
So the key was to warm up the cache before serializing:
$i=0;
while ($part = $message->getPart($i) {
$i++;
}
$serialization=serialize($message); //now it saves the whole message.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow