我正在编写一个帮助台管道处理程序,用于将传入的电子邮件作为服务台工单回复。有些电子邮件完全没问题,另一些则是乱七八糟的文本和=3D都被塞进了一个巨大的字符串。有没有人知道怎么把它解码成纯文本。
作为参考,下面是我的邮件解析器函数:
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());
}
}发布于 2009-11-26 09:19:10
我猜想,不知何故,内容类型没有正确指定,Zend不知道如何解码它。我知道我以前见过这种情况,但我不记得它是在哪里或如何“解决”的。
它看起来像是被当作纯文本处理的可打印的引号。
https://stackoverflow.com/questions/1800970
复制相似问题