作者 邓超

x

@@ -34,12 +34,24 @@ class Body { @@ -34,12 +34,24 @@ class Body {
34 34
35 35
36 /** 36 /**
  37 + * 邮件的header
  38 + * @var array
  39 + */
  40 + private $header = [];
  41 +
  42 +
  43 + /**
37 * Body constructor. 44 * Body constructor.
38 * @param string $body 45 * @param string $body
39 * @param string $fileSavePath 46 * @param string $fileSavePath
40 */ 47 */
41 - public function __construct(string $body, string $fileSavePath='/') 48 + public function __construct(string $body, string $fileSavePath='/',$header=[])
42 { 49 {
  50 +
  51 + if($header){
  52 + $this->header = $header;
  53 + }
  54 +
43 $this->body = $body = trim($body); 55 $this->body = $body = trim($body);
44 56
45 $this->fileSavePath = $fileSavePath; 57 $this->fileSavePath = $fileSavePath;
@@ -89,7 +101,23 @@ class Body { @@ -89,7 +101,23 @@ class Body {
89 else{ 101 else{
90 // qq的是base64 102 // qq的是base64
91 if(MailFun::isBase64($body)){ 103 if(MailFun::isBase64($body)){
  104 +
  105 + // 可能是图片邮件体,什么都没有
  106 + if(!empty($this->header['Content-Type'])){
  107 + $ct = explode(";",$this->header['Content-Type']);
  108 + // 图片,以后有其他,需要添加
  109 + if(in_array($ct[0],['image/png','image/jpg','image/jpeg','image/gif'])){
  110 + $isImage = 1;
  111 + }
  112 + }
  113 +
  114 + if(!empty($isImage)){
  115 + $this->setItem(['type'=>'text/plain','body'=>"<img src=\"data:".($ct[0]??'image/png').";base64,".$body."\" />"]);
  116 + }else{
92 $this->setItem(['type'=>'text/plain','body'=>base64_decode($body)]); 117 $this->setItem(['type'=>'text/plain','body'=>base64_decode($body)]);
  118 + }
  119 +
  120 +
93 }else{ 121 }else{
94 $this->setItem(['type'=>'text/plain','body'=>$body]); 122 $this->setItem(['type'=>'text/plain','body'=>$body]);
95 } 123 }
@@ -737,8 +737,9 @@ class Imap { @@ -737,8 +737,9 @@ class Imap {
737 $result = $this->fetch($data,'body',$is_uid); 737 $result = $this->fetch($data,'body',$is_uid);
738 foreach ($result as $key=>$item){ 738 foreach ($result as $key=>$item){
739 if (!empty($item['RFC822.TEXT'])){ 739 if (!empty($item['RFC822.TEXT'])){
  740 + $header = $this->fetchHeader($item['UID'],1);
740 // 解析 741 // 解析
741 - $result[$key]['RFC822.TEXT'] = (new Body($item['RFC822.TEXT'],$saveFilePath))->getItem(); 742 + $result[$key]['RFC822.TEXT'] = (new Body($item['RFC822.TEXT'],$saveFilePath,$header['HEADER.FIELDS']??[]))->getItem();
742 } 743 }
743 } 744 }
744 745