0

我需要在 php 中提取邮件的正文。

目前我正在使用 mimemailparser "getmessagebody" 函数来检索邮件正文。

它在没有任何其他 (.msg) 文件的邮件有附件时运行良好,但如果邮件包含的附件​​也是 .msg 格式的邮件,它会获取附件的正文而不是正文当前邮件。使用以下函数和代码。

public function getMessageBody($type = 'text') {
        $body = false;
        $mime_types = array(
            'text'=> 'text/plain',
            'html'=> 'text/html'
        );
        if (in_array($type, array_keys($mime_types))) {
            foreach($this->parts as $part) {
                if ($this->getPartContentType($part) == $mime_types[$type]) {
                    $headers = $this->getPartHeaders($part);
                    $body = $this->decode($this->getPartBody($part), array_key_exists('content-transfer-encoding', $headers) ? $headers['content-transfer-encoding'] : '');
                }
            }
        } else {
            throw new Exception('Invalid type specified for MimeMailParser::getMessageBody. "type" can either be text or html.');
        }
        return $body;
    }

代码:

$this->parsed->setText($this->mail);
$this->message = $this->parsed->getMessageBody('text');

问题:getmessagebody 检索附加邮件的正文,而不是原始邮件。请问有什么解决办法吗?

4

1 回答 1

0

找到了这个问题的答案。getmessagebody -> 实际上它总是返回最后一个匹配部分而不是第一个(它可能有一个文本/纯文本消息和一个文本/纯文本附件)。

http://code.google.com/p/php-mime-mail-parser/issues/attachmentText?id=10&aid=100004000&name=getMessageBody.txt&token=vCOlNmTnFSlEGmUs31i5tY_KkoQ%3A1388629941070

于 2014-01-02T07:07:50.370 回答