Thomaschaaf
Thomaschaaf

Reputation: 18196

Zend_Mail reading Mail

The documentation for sending mails with Zend_Mail is great but receiving mails is a pain right now. I currently want to get the plaintext part and the html part of the email. Right now I have writen a long function which goes through the parts and then looks at the headers and look at it whether it is quoated printable or base64 and I have to do da whole lot to just get the information. Am I maybe missing a function with which I can just get the plaintext and the html our of the mail?

Upvotes: 1

Views: 527

Answers (2)

Daniel Stejskal
Daniel Stejskal

Reputation: 63

Try to implement something like this:

/**
 * Returns the parts with plain text
 *
 * @param Zend_Mail_Message $message
 * @return array of Zend_Mail_Part
 */
public function findTextParts(Zend_Mail_Message $message){

    $result = array();

    foreach (new RecursiveIteratorIterator($message) as $part) {

        $token = strtok($part->contentType, ';');

        if ( $token == 'text/plain') {
            $result[] = $part;
        }

    }

    return $result;

}

Upvotes: 0

arikfr
arikfr

Reputation: 3351

AFAIK, MIME emails have no standard for the order of the different parts (HTML, plaintext, embeds). Therefore you do have to iterate over all parts and get the parts you need.

But because the structure of Zend_Mail is recursive iterating should be pretty easy. Maybe you can share your code with us so we can comment on it (if there's anything to comment)?

Upvotes: 4

Related Questions