作者 邓超

解析邮件 编码问题

@@ -77,6 +77,14 @@ class Address { @@ -77,6 +77,14 @@ class Address {
77 * @time 2024/9/11 11:43 77 * @time 2024/9/11 11:43
78 */ 78 */
79 private function pregEmail(string $str):string { 79 private function pregEmail(string $str):string {
  80 + $str = trim($str);
  81 + if(substr($str,-1) == '>'){
  82 + $email = substr($str,strrpos($str,'<'));
  83 + if($email){
  84 + return trim(str_replace(['<','>'],'',$email));
  85 + }
  86 + }
  87 +
80 preg_match_all('/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/',$str,$email); 88 preg_match_all('/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/',$str,$email);
81 if(!empty($email[0])){ 89 if(!empty($email[0])){
82 $email = end($email[0]); 90 $email = end($email[0]);
@@ -79,7 +79,7 @@ class Header{ @@ -79,7 +79,7 @@ class Header{
79 // 头信息content-type 79 // 头信息content-type
80 $contentType = $this->get('content-type'); 80 $contentType = $this->get('content-type');
81 if($contentType){ 81 if($contentType){
82 - preg_match("/charset=\"?([a-z0-9-._]{2,})\"?/",$contentType,$charset); 82 + preg_match("/charset=\"?([a-z0-9-._]{2,})\"?/i",$contentType,$charset);
83 if(!empty($charset[1])){ 83 if(!empty($charset[1])){
84 // 编码 84 // 编码
85 $this->setAttribute('charset',$charset[1]); 85 $this->setAttribute('charset',$charset[1]);