当有内容配置时,如何提取邮件正文?

时间:2013-09-25 05:08:07

标签: php email cakephp email-parsing

如果有内容处理,如何提取邮件正文?

头1

Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: yes
X-MS-TNEF-Correlator:
x-originating-ip: [x.x.x.x]
Content-Type: application/pkcs7-mime; smime-type=signed-data;
    name="smime.p7m"
Content-Disposition: attachment; filename="smime.p7m"
Content-Transfer-Encoding: base64
MIME-Version: 1.0

HEADER2:

   Accept-Language: en-US
    Content-Language: en-US
    X-MS-Has-Attach:
    X-MS-TNEF-Correlator:
    x-originating-ip: [x.x.x.x]
    Content-Type: multipart/alternative;
        boundary="_000_A61C9CD725DF1C4FA94C13EC538A38BEEaz18ex3004_"
    MIME-Version: 1.0

当我签收邮件并发送时,邮件的标题格式为“header1”,当我发送邮件时没有签名,邮件的标题格式为“header2”..

我目前正使用" getMessageBody()" method文件中的mimemailparser.class.php来提取邮件正文..

在签名邮件上,我无法检索邮件的正文,它使用"getmessagebody()" method返回空主体,但在未签名的邮件上,它能够检索邮件的正文..

在检查签名和未签名的邮件标题时,有区别,如何在签名邮件(header1)上提取邮件正文?

1 个答案:

答案 0 :(得分:0)

查看类中的方法getMessageBody(),代码的以下部分:

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'] : '');
    break;
  }
}

类将MIME消息拆分成部分,并且可能存在这样的情况,当主体被分成几个部分,但代码只解码第一部分(在您的情况下它可能是空的)。 尝试修改此代码:

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'] : '');
  }
}