正在显示
1 个修改的文件
包含
71 行增加
和
15 行删除
| @@ -134,13 +134,15 @@ class Body { | @@ -134,13 +134,15 @@ class Body { | ||
| 134 | { | 134 | { |
| 135 | 135 | ||
| 136 | foreach ($this->item as $k=>$item){ | 136 | foreach ($this->item as $k=>$item){ |
| 137 | - //是否有 =E2=81=B6=E2=81=B6=E2=81=B9=C2=B3=C2=B9=C2=B2=C2=BA=C2=B3=C2=BAS 一样的字符 | ||
| 138 | - if($item['type']=='text/plain' && preg_match("/(=[A-Z0-9]{2,}){2,}/",$item['body'])){ | ||
| 139 | - // 进行解码 | ||
| 140 | - $item['body'] = quoted_printable_decode($item['body']); | ||
| 141 | - } | 137 | + if(isset($item['type'])){ |
| 138 | + //是否有 =E2=81=B6=E2=81=B6=E2=81=B9=C2=B3=C2=B9=C2=B2=C2=BA=C2=B3=C2=BAS 一样的字符 | ||
| 139 | + if($item['type']=='text/plain' && preg_match("/(=[A-Z0-9]{2,}){2,}/",$item['body'])){ | ||
| 140 | + // 进行解码 | ||
| 141 | + $item['body'] = quoted_printable_decode($item['body']); | ||
| 142 | + } | ||
| 142 | 143 | ||
| 143 | - $this->item[$k] = $item; | 144 | + $this->item[$k] = $item; |
| 145 | + } | ||
| 144 | } | 146 | } |
| 145 | 147 | ||
| 146 | return $this->item; | 148 | return $this->item; |
| @@ -200,9 +202,9 @@ class Body { | @@ -200,9 +202,9 @@ class Body { | ||
| 200 | if(!$item) { continue; } | 202 | if(!$item) { continue; } |
| 201 | 203 | ||
| 202 | // 邮件体包含邮件体 | 204 | // 邮件体包含邮件体 |
| 203 | - if(preg_match("/boundary=\"(.*)\"/Ui",$item,$bm)){ | 205 | + if(preg_match('/boundary="?(.*)("|\r)/i',$item,$bm)){ |
| 204 | 206 | ||
| 205 | - if (strpos($item,$bm[1].'--')!==false){ | 207 | + if (str_contains($item, trim($bm[1]).'--')){ |
| 206 | $data = (new self('--'.$bm[1]."\r\n".$item,$this->fileSavePath))->getItem(); | 208 | $data = (new self('--'.$bm[1]."\r\n".$item,$this->fileSavePath))->getItem(); |
| 207 | // $this->setItem($data); | 209 | // $this->setItem($data); |
| 208 | // 合并邮件体 | 210 | // 合并邮件体 |
| @@ -379,7 +381,9 @@ class Body { | @@ -379,7 +381,9 @@ class Body { | ||
| 379 | 381 | ||
| 380 | 382 | ||
| 381 | // content id | 383 | // content id |
| 382 | - preg_match("/Content-ID:[\s].*<[\w\W]{1,}>/i",$item['body'],$result); | 384 | +// preg_match("/Content-ID:[\s].*<[\w\W]{1,}>/i",$item['body'],$result); |
| 385 | + | ||
| 386 | + $result[0] = $this->getTag($item['body'],'Content-ID:'); | ||
| 383 | if (!empty($result[0])){ | 387 | if (!empty($result[0])){ |
| 384 | $data['content-id'] = explode('<',$result[0]); | 388 | $data['content-id'] = explode('<',$result[0]); |
| 385 | $data['content-id'] = $data['content-id'][1]; | 389 | $data['content-id'] = $data['content-id'][1]; |
| @@ -426,6 +430,39 @@ class Body { | @@ -426,6 +430,39 @@ class Body { | ||
| 426 | } | 430 | } |
| 427 | 431 | ||
| 428 | /** | 432 | /** |
| 433 | + * 获取某个tag | ||
| 434 | + * @param $content | ||
| 435 | + * @param $tag | ||
| 436 | + * @return string | ||
| 437 | + * @author:dc | ||
| 438 | + * @time 2023/10/30 22:45 | ||
| 439 | + */ | ||
| 440 | + public function getTag($content,$tag){ | ||
| 441 | + $items = explode("\n",$content); | ||
| 442 | + $ctstr = ''; | ||
| 443 | + foreach ($items as $str){ | ||
| 444 | + if($ctstr){ | ||
| 445 | + | ||
| 446 | + if(empty(trim($str))){ | ||
| 447 | + break; | ||
| 448 | + } | ||
| 449 | + if(str_starts_with($str, "\t")||str_starts_with($str, " ")){ | ||
| 450 | + $ctstr .= $str."\n"; | ||
| 451 | + }else{ | ||
| 452 | + break; | ||
| 453 | + } | ||
| 454 | + } | ||
| 455 | + | ||
| 456 | + if(str_starts_with(strtolower($str), strtolower($tag))){ | ||
| 457 | + $ctstr .= $str."\n"; | ||
| 458 | + } | ||
| 459 | + | ||
| 460 | + } | ||
| 461 | + | ||
| 462 | + return trim($ctstr); | ||
| 463 | + } | ||
| 464 | + | ||
| 465 | + /** | ||
| 429 | * 删除tag | 466 | * 删除tag |
| 430 | * @param $body | 467 | * @param $body |
| 431 | * @param $tag | 468 | * @param $tag |
| @@ -434,10 +471,11 @@ class Body { | @@ -434,10 +471,11 @@ class Body { | ||
| 434 | * @time 2022/8/12 10:34 | 471 | * @time 2022/8/12 10:34 |
| 435 | */ | 472 | */ |
| 436 | private function body_remove_tag($body,$tag){ | 473 | private function body_remove_tag($body,$tag){ |
| 437 | - preg_match("/{$tag}\r?[\w\W].*/i",$body,$result); | ||
| 438 | - if(!empty($result[0])) { | ||
| 439 | - $body = str_replace($result, '', $body); | ||
| 440 | - } | 474 | + $str = $this->getTag($body,$tag); |
| 475 | +// preg_match("/{$tag}\r?[\w\W].*/i",$body,$result); | ||
| 476 | +// if(!empty($result[0])) { | ||
| 477 | + $body = str_replace($str, '', $body); | ||
| 478 | +// } | ||
| 441 | return $body; | 479 | return $body; |
| 442 | } | 480 | } |
| 443 | 481 | ||
| @@ -470,9 +508,27 @@ class Body { | @@ -470,9 +508,27 @@ class Body { | ||
| 470 | * @time 2022/8/12 10:26 | 508 | * @time 2022/8/12 10:26 |
| 471 | */ | 509 | */ |
| 472 | private function preg_match_type($item){ | 510 | private function preg_match_type($item){ |
| 473 | - // 匹配内容 type | ||
| 474 | - preg_match("/Content-Type:[\w\W].*/i",$item,$result); | 511 | + $items = explode("\n",$item); |
| 512 | + $ctstr = ''; | ||
| 513 | + foreach ($items as $str){ | ||
| 514 | + if($ctstr){ | ||
| 515 | + | ||
| 516 | + if(str_starts_with($str, "\t")){ | ||
| 517 | + $ctstr .= $str."\n"; | ||
| 518 | + }else{ | ||
| 519 | + break; | ||
| 520 | + } | ||
| 521 | + } | ||
| 522 | + | ||
| 523 | + if(str_starts_with($str, 'Content-Type:')){ | ||
| 524 | + $ctstr .= $str."\n"; | ||
| 525 | + } | ||
| 475 | 526 | ||
| 527 | + } | ||
| 528 | + | ||
| 529 | + // 匹配内容 type | ||
| 530 | +// preg_match("/Content-Type:[\w\W].*/i",$item,$result); | ||
| 531 | + $result[0] = $ctstr; | ||
| 476 | if(!empty($result[0])){ | 532 | if(!empty($result[0])){ |
| 477 | $ret['origin'] = trim($result[0]); | 533 | $ret['origin'] = trim($result[0]); |
| 478 | // type | 534 | // type |
-
请 注册 或 登录 后发表评论