如何使用imap扩展名获取原始的电子邮件数据? [英] How to get raw email data with the imap extension?

查看:836
本文介绍了如何使用imap扩展名获取原始的电子邮件数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种下载整个原始电子邮件数据(包括附件)的方法,类似于在Gmail中点击显示原始所获得的信息。

I'm looking for a way to download the whole raw email data (including attachment), similar to what you get by clicking "Show Original" in Gmail.

目前,我可以通过以下代码获取邮件正文的原始标题:

Currently, I can get the raw header and some parts of the mail body by this code:

$this->MailBox = imap_open($mailServer, $userName, $password, OP_SILENT);
...
$email->RawEmail = imap_fetchbody($this->MailBox, $msgNo, "0");
$email->RawEmail .= "\n".imap_fetchbody($this->MailBox, $msgNo, "1");

另外我知道更改imap_fetchbody的第三个参数可能会返回编码的附件。猜猜我需要一个循环,以获得原始电子邮件的一部分,但是什么是停止循环的条件?

Also I know that changing the 3rd parameter of imap_fetchbody might return the encoded attachment. Guess I need a loop here to get the raw email part by part, but what's the condition to stop the loop?

有没有一个简单的方法来获取整个电子邮件一次?

Is there an easy way to get the whole email at once?

任何帮助将不胜感激。

推荐答案

如果你要获取全部,您需要获取

If you want to fetch all, you need to fetch

  • The headers imap_fetchheader.
  • Obtain the number of bodies the message has imap_fetchstructure.
  • Each mine-headers a body has imap_fetchmime.
  • Each body it has imap_fetchbody.

由于mime-message可以有多个主体,因此您需要处理每个一个又一个。要减少对服务器的负载,请使用 <$ c $ FT_PREFETCHTEXT 选项C> imap_fetchheader 。一些示例关于 imap_fetchstructure 在另一个答案中的代码,显示处理imap连接并通过封装迭代消息的一部分。

As mime-message can have multiple bodies, you need to process each part after the other. To reduce load to the server use the FT_PREFETCHTEXT option for imap_fetchheader. Some example code about imap_fetchstructure in another answer that shows handling the imap connection and iterating over parts of a message already through encapsulation.

这篇关于如何使用imap扩展名获取原始的电子邮件数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆