简体   繁体   English

提取邮件正文-有附件时

[英]Extracting body of the mail - when there is an attachment

I need to extract the body of a mail in php. 我需要在php中提取邮件正文。

Currently I am using mimemailparser "getmessagebody" function for retrieving body of the mail. 目前,我正在使用mimemailparser的“ getmessagebody”功能来检索邮件正文。

it works well when there is a mail without any other (.msg) file has an attachment, but incase if the mail contains an attachment which is also a mail in .msg format, it gets the body of the attachment and not the body of the current mail. 当邮件中没有任何其他(.msg)文件带有附件时,它会很好地工作,但是如果该邮件包含的附件​​也是.msg格式的邮件,则它将获取附件的主体,而不是附件的主体当前邮件。 using following function and code. 使用以下功能和代码。

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;
    }

code: 码:

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

Problem: getmessagebody retrieves body of the attached mail and not the original mail. 问题:getmessagebody检索附件邮件的正文,而不是原始邮件。 any solution pls? 有什么解决办法吗?

Found the answer to this question. 找到了这个问题的答案。 getmessagebody -> Actually it always returns the LAST matching part instead of the first (its possible to have a text/plain message and a text/plain attachment). getmessagebody->实际上,它总是返回LAST匹配部分而不是第一个(可能有文本/纯文本消息和文本/纯文本附件)。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM