作者 邓超

1

@@ -91,7 +91,7 @@ class Body { @@ -91,7 +91,7 @@ class Body {
91 } 91 }
92 else{ 92 else{
93 // qq的是base64 93 // qq的是base64
94 - if(rtrim($body,'=') == rtrim(base64_encode(base64_decode($body)),'=')){ 94 + if(MailFun::isBase64($body)){
95 $this->setItem(['type'=>'text/plain','body'=>base64_decode($body)]); 95 $this->setItem(['type'=>'text/plain','body'=>base64_decode($body)]);
96 }else{ 96 }else{
97 $this->setItem(['type'=>'text/plain','body'=>$body]); 97 $this->setItem(['type'=>'text/plain','body'=>$body]);
@@ -330,15 +330,8 @@ class Mail { @@ -330,15 +330,8 @@ class Mail {
330 foreach ($body as $key=>$item){ 330 foreach ($body as $key=>$item){
331 if(!$description && in_array($item['type']??'',['text/html','text/plain'])){ 331 if(!$description && in_array($item['type']??'',['text/html','text/plain'])){
332 332
333 - // 是否是base64  
334 - $value = @base64_decode($item['body']);  
335 -  
336 - if(!$value){  
337 - $value = $item['body'];  
338 - }  
339 -  
340 if(!empty($item['charset'])){ 333 if(!empty($item['charset'])){
341 - $value = iconv($item['charset'],'utf-8',$value); 334 + $value = iconv($item['charset'],'utf-8',$item['body']);
342 } 335 }
343 $value=preg_replace("/<(script.*?)>(.*?)<(\/script.*?)>/si","",$value); //过滤script标签 336 $value=preg_replace("/<(script.*?)>(.*?)<(\/script.*?)>/si","",$value); //过滤script标签
344 $value=preg_replace("/<(\/?script.*?)>/si","",$value); //过滤script标签 337 $value=preg_replace("/<(\/?script.*?)>/si","",$value); //过滤script标签
@@ -349,6 +342,7 @@ class Mail { @@ -349,6 +342,7 @@ class Mail {
349 $value = strip_tags($value); 342 $value = strip_tags($value);
350 $value = str_replace(["\n",' ',"\\n","&nbsp;"],'',$value); 343 $value = str_replace(["\n",' ',"\\n","&nbsp;"],'',$value);
351 $description = mb_substr(trim($value),0,190); 344 $description = mb_substr(trim($value),0,190);
  345 +
352 } 346 }
353 347
354 if(!empty($body[$key]['body'])){ 348 if(!empty($body[$key]['body'])){
@@ -195,4 +195,16 @@ class MailFun { @@ -195,4 +195,16 @@ class MailFun {
195 return mb_convert_encoding($folder,'UTF7-IMAP','UTF-8'); 195 return mb_convert_encoding($folder,'UTF7-IMAP','UTF-8');
196 } 196 }
197 197
  198 + /**
  199 + * 是否是base64
  200 + * @param $str
  201 + * @return bool
  202 + * @author:dc
  203 + * @time 2023/4/3 10:24
  204 + */
  205 + public static function isBase64($str){
  206 + $oldStr = str_replace([' ',"\n","\r"],'',rtrim($str,'='));
  207 + return $oldStr == base64_encode(base64_decode($str));
  208 + }
  209 +
198 } 210 }