web系统获取邮箱邮件,获取qq邮件内容时内容区图片获取不到/解析不出来,163邮箱的内容区图片可以正常获取到,但163邮箱的附件名称乱码(汉字变为数字+字母)
获取代码:
public function GetAttach($mid,$path) // Get Atteced File from Mail
{
if(!$this->marubox)
return false;
$struckture = imap_fetchstructure($this->marubox,$mid);
$files=array();
if($struckture->parts)
{
foreach($struckture->parts as $key => $value)
{
$enc=$struckture->parts[$key]->encoding;
//取邮件附件
if($struckture->parts[$key]->ifdparameters)
{
//命名附件,转码
$name=$this->decode_mime($struckture->parts[$key]->dparameters[0]->value);
$extend =explode("." , $name);
$file['extension'] = $extend[count($extend)-1];
$file['pathname'] = $this->setPathName($key, $file['extension']);
$file['title'] = !empty($name) ? htmlspecialchars($name) : str_replace('.' . $file['extension'], '', $name);
$file['size'] = $struckture->parts[$key]->dparameters[1]->value;
// $file['tmpname'] = $struckture->parts[$key]->dparameters[0]->value;
if(@$struckture->parts[$key]->disposition=="ATTACHMENT")
{
$file['type'] = 1;
}
else
{
$file['type'] = 0;
}
$files[] = $file;
$message = imap_fetchbody($this->marubox,$mid,$key+1);
if ($enc == 0)
$message = imap_8bit($message);
if ($enc == 1)
$message = imap_8bit ($message);
if ($enc == 2)
$message = imap_binary ($message);
if ($enc == 3)//图片
$message = imap_base64 ($message);
if ($enc == 4)
$message = quoted_printable_decode($message);
if ($enc == 5)
$message = $message;
$fp=fopen($path.$file['pathname'],"w");
fwrite($fp,$message);
fclose($fp);
}
// 处理内容中包含图片的部分
if($struckture->parts[$key]->parts)
{
foreach($struckture->parts[$key]->parts as $keyb => $valueb)
{
$enc=$struckture->parts[$key]->parts[$keyb]->encoding;
if($struckture->parts[$key]->parts[$keyb]->ifdparameters)
{
//命名图片
$name=$this->decode_mime($struckture->parts[$key]->parts[$keyb]->dparameters[0]->value);
$extend =explode("." , $name);
$file['extension'] = $extend[count($extend)-1];
$file['pathname'] = $this->setPathName($key, $file['extension']);
$file['title'] = !empty($name) ? htmlspecialchars($name) : str_replace('.' . $file['extension'], '', $name);
$file['size'] = $struckture->parts[$key]->parts[$keyb]->dparameters[1]->value;
// $file['tmpname'] = $struckture->parts[$key]->dparameters[0]->value;
$file['type'] = 0;
$files[] = $file;
$partnro = ($key+1).".".($keyb+1);
$message = imap_fetchbody($this->marubox,$mid,$partnro);
if ($enc == 0)
$message = imap_8bit($message);
if ($enc == 1)
$message = imap_8bit ($message);
if ($enc == 2)
$message = imap_binary ($message);
if ($enc == 3)
$message = imap_base64 ($message);
if ($enc == 4)
$message = quoted_printable_decode($message);
if ($enc == 5)
$message = $message;
$fp=fopen($path.$file['pathname'],"w");
fwrite($fp,$message);
fclose($fp);
}
}
}
}
}