我制作了一个程序来使用 php 从 gmail 下载电子邮件并保存到 html 文件。一切正常的文件,它的连接,下载邮件,下载附件,下载嵌入式邮件,它还保存到 html 文件,一切正常,但只有一些邮件像:
示例 1:
--_008_8BDE32B1FDB5C947B54F92503EC9934F015611E6glmrsvrmail1gil_ Content-Type: multipart/alternative; boundary="_000_8BDE32B1FDB5C947B54F92503EC9934F015611E6glmrsvrmail1gil_" --_000_8BDE32B1FDB5C947B54F92503EC9934F015611E6glmrsvrmail1gil_ Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 RGVhciBSb3NlLA0KDQpHcmVldGluZ3MgZnJvbSBHaWxpIExhbmthbmZ1c2hp IE1hbGRpdmVzIQ0KDQpXZSBhcmUgZGVsaWdodGVkIHRvIGNvbmZpcm0geW91
示例 2: 在 Gmail 中,它以彩色和 HTML 显示,但在这里它将所有文本集中在一起,但没有 html 和颜色
示例 3:
N§’çè®êßjËZžÌ®(î²ÜžÛh’z0†Œ&¹ÈpŠY\¢Ëf{‰à†+
示例 4:
------_=_NextPart_002_01CE2076.4A2A4F64 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: base64 RGVhciBSb3NlLA0KDQogDQoNClRoaXMgaXMgbXkgb2ZmaWNlIGVtYWlsIGFkZHJlc3MuIEVuY2xv c2VkIGRvY3VtZW50cyBhcyByZXF1aXJlZC4gQWxzbyBlbmNsb3NlZCBteSBjb25maXJtZWQgdGlj a2V0IGZvciB5b3VyIGZ1cnRoZXIgYWN0aW9ucywgcmVxdWVzdCB5b3UgdG8gYXJyYW5nZSBhaXJw
我正在使用以下方式下载邮件,请它只用于一些邮件注意:我对附件没有问题..
function read_all_parts($mbox,$uid)
{
global $mime,$ret_info,$enc;
$mime = array("text","multipart","message","application","audio","image","video","other","unknow");
$enc = array("7BIT","8BIT","BINARY","BASE64","QUOTED-PRINTABLE","OTHER","base64");
$struct = imap_fetchstructure($mbox, $uid );
$ret_info = array();
$ret_info = $this->scan($struct->parts,0);
return $ret_info;
}
$structure = imap_fetchstructure($mbox, $message_id);
$mailDivided= $mailObj->read_all_parts($mbox,$message_id);
if(count($mailDivided)!=0){
/* ////////////////////////////////////////////////////////////////////// */
$plainText = 1;
foreach ($mailDivided as $key=>$parts) {
if($parts['pid']=='1.2' && $parts['encoding']=='QUOTED-PRINTABLE'):
$plainText = '1.2'; # which means this is contains html text
endif;
if($parts['pid']=='1.2' && $parts['encoding']=='7BIT'):
$plainText = '1.2'; # which means this is contains html text
endif;
if($parts['pid']=='1.2' && $parts['encoding']=='8BIT'):
$plainText = '1.2'; # which means this is contains html text
endif;
if($parts['pid']=='1.1.2' && $parts['encoding']=='QUOTED-PRINTABLE'):
$plainText = '1.1.2'; # which means this is contains html text
endif;
if($parts['pid']=='2' && $parts['encoding']=='QUOTED-PRINTABLE'):
$plainText = '2'; # which means this is contains html text
endif;
}
/* ////////////////////////////////////////////////////////////////////// */
$mymail = imap_fetchbody($mbox,$message_id,$plainText);
if(imap_base64($mymail)){
print "This is imap_base64 <br>";
$mymailBody = imap_base64($mymail);
$mymailBody = nl2br($mymailBody);
}else if (imap_qprint($mymail)){
print "This is imap_qprint <br>";
$mymailBody = imap_qprint($mymail);
}else{
if ($plainTex==1){
print "This is nl2br <br>";
$mymailBody = nl2br($mymail);
}else{
print "This is quoted_printable_decode <br>";
$mymailBody = quoted_printable_decode($mymail);
}
}
/* ////////////////////////////////////////////////////////////////////// */
}else{
print "This is encodingMailbody <br>";
$mymail = imap_fetchbody($mbox,$message_id,'1');
$mymailBody = $mailObj->encodingMailbody($mymail,$structure->encoding);
$mymailBody = nl2br($mymailBody);
}
我一直在检查和尝试所有可能的事情,没有任何帮助。