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,$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);
}
}
}
}
}
//move mail to taskMailBox
$this->move_mails($mid,$this->marubox);
return $files;
}
function getBody($mid,&$path,$imageList) // Get Message Body
{
if(!$this->marubox)
return false;
$body = $this->get_part($this->marubox,"TEXT/HTML");
if ($body == "")
$body = $this->get_part($this->marubox,"TEXT/PLAIN");
if ($body == "") {
return "";
}
//处理图片
$body=$this->embed_images($body,$path,$imageList);
return $body;
}
function embed_images(&$body,$imageList)
{
// get all img tags
preg_match_all('/<img.*?>/',$body,$matches);
if (!isset($matches[0])) return;
foreach ($matches[0] as $img)
{
// replace image web path with local path
preg_match('/src="(.*?)"/',$img,$m);
if (!isset($m[1])) continue;
$arr = parse_url($m[1]);
if (!isset($arr['scheme']) || !isset($arr['path']))continue;
// if (!isset($arr['host']) || !isset($arr['path']))continue;
if ($arr['scheme']!="http")
{
$filename=explode("@",$arr['path']);
$body = str_replace($img,'',$body);
}
}
return $body;
}
function deleteMails($mid) // Delete That Mail
{
if(!$this->marubox)
return false;
imap_delete($this->marubox,$mid);
}
function close_mailbox() //Close Mail Box
{
if(!$this->marubox)
return false;
imap_close($this->marubox,CL_EXPUNGE);
} (编辑:厦门网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|