Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend_Mail and =0D=0A=3D=3D=3D=3D=3D

Tags:

I'm writing a help desk pipe handler to pipe incoming e-mails as helpdesk ticket replies. Some e-mails are coming in perfectly fine, others are coming in as a jumble of the text and =3D's all munged into one giant string. Does anyone have an idea on how to decode that into plain text.

For reference, this is my mail parser function:

public function parseEmailMessage(Zend_Mail_Message $msg)
{
    if ($msg->isMultiPart()) {
        $arrAttachments = array();
        $body = '';
        // Multipart Mime Message
        foreach (new RecursiveIteratorIterator($msg) as $part) {
            try {

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

                // Parse file name
                preg_match('/name="(?<filename>[a-zA-Z0-9.\-_]+)"/is', $part->contentType, $attachmentName);

                // Append plaintext results to $body
                // All other content parts will be treated as attachments
                switch ($mimeType) {
                    case 'text/plain':
                        $body .= trim($part->getContent()) . "\n";
                        break;
                    case 'text/html':
                        $body .= trim(strip_tags($part->getContent));
                        break;
                    default:
                        $arrAttachments[] = array(
                            'attachment_mime' => $mimeType,
                            'attachment_name' => $this->filterFileName($attachmentName['filename']),
                            'base64data' => trim($part->getContent())
                        );
                }

            } catch (Zend_Mail_Exception $e) {
                // ignore
            }
        }

        return array($body, $arrAttachments);
    } else {
        // Plain text message
        return array(trim($msg->getContent()), array());
    }
}
like image 258
Mark Avatar asked Nov 26 '09 00:11

Mark


1 Answers

I'll take a guess that somehow the content type is not correctly specified and Zend doesn't know how to decode it. I know I've seen this before, but I can't remember where or how it was 'solved'.

It looks like quoted-printable being treated like plain text.

like image 92
Tim Lytle Avatar answered Oct 11 '22 23:10

Tim Lytle