当有内容处置时,如何提取邮件的正文


How to extract body of the mail, when there is content disposition?

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

标头 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

标题 2:

   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"格式。

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

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

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

查看类中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'] : '');
  }
}