作者 邓超

x

... ... @@ -34,12 +34,24 @@ class Body {
/**
* 邮件的header
* @var array
*/
private $header = [];
/**
* Body constructor.
* @param string $body
* @param string $fileSavePath
*/
public function __construct(string $body, string $fileSavePath='/')
public function __construct(string $body, string $fileSavePath='/',$header=[])
{
if($header){
$this->header = $header;
}
$this->body = $body = trim($body);
$this->fileSavePath = $fileSavePath;
... ... @@ -89,7 +101,23 @@ class Body {
else{
// qq的是base64
if(MailFun::isBase64($body)){
// 可能是图片邮件体,什么都没有
if(!empty($this->header['Content-Type'])){
$ct = explode(";",$this->header['Content-Type']);
// 图片,以后有其他,需要添加
if(in_array($ct[0],['image/png','image/jpg','image/jpeg','image/gif'])){
$isImage = 1;
}
}
if(!empty($isImage)){
$this->setItem(['type'=>'text/plain','body'=>"<img src=\"data:".($ct[0]??'image/png').";base64,".$body."\" />"]);
}else{
$this->setItem(['type'=>'text/plain','body'=>base64_decode($body)]);
}
}else{
$this->setItem(['type'=>'text/plain','body'=>$body]);
}
... ...
... ... @@ -737,8 +737,9 @@ class Imap {
$result = $this->fetch($data,'body',$is_uid);
foreach ($result as $key=>$item){
if (!empty($item['RFC822.TEXT'])){
$header = $this->fetchHeader($item['UID'],1);
// 解析
$result[$key]['RFC822.TEXT'] = (new Body($item['RFC822.TEXT'],$saveFilePath))->getItem();
$result[$key]['RFC822.TEXT'] = (new Body($item['RFC822.TEXT'],$saveFilePath,$header['HEADER.FIELDS']??[]))->getItem();
}
}
... ...