正在显示
3 个修改的文件
包含
25 行增加
和
3 行删除
| @@ -26,9 +26,10 @@ class Fun { | @@ -26,9 +26,10 @@ class Fun { | ||
| 26 | $from = 'iso-8859-8'; | 26 | $from = 'iso-8859-8'; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | - if ($from && in_array($from, mb_list_encodings())) { | 29 | + |
| 30 | + try { | ||
| 30 | return mb_convert_encoding($str,$to,$from); | 31 | return mb_convert_encoding($str,$to,$from); |
| 31 | - } | 32 | + }catch (\Throwable $e){} |
| 32 | 33 | ||
| 33 | return mb_convert_encoding($str,$to); | 34 | return mb_convert_encoding($str,$to); |
| 34 | } | 35 | } |
| @@ -263,7 +263,10 @@ class Body { | @@ -263,7 +263,10 @@ class Body { | ||
| 263 | $this->parseMimeHeaderChild($data,'Content-Disposition'); | 263 | $this->parseMimeHeaderChild($data,'Content-Disposition'); |
| 264 | 264 | ||
| 265 | // 默认编码 | 265 | // 默认编码 |
| 266 | - if(!$data->Charset) $data->Charset = 'utf-8'; | 266 | + if(!$data->Charset) |
| 267 | + { | ||
| 268 | + $data->Charset = $this->header->get('charset') ? : 'utf-8'; | ||
| 269 | + } | ||
| 267 | // 处理content id中意外的字符串 | 270 | // 处理content id中意外的字符串 |
| 268 | $data->set('Content-ID',trim(str_replace(['"','<','>'],'',$data->get('Content-ID')))); | 271 | $data->set('Content-ID',trim(str_replace(['"','<','>'],'',$data->get('Content-ID')))); |
| 269 | 272 |
| @@ -3,6 +3,8 @@ | @@ -3,6 +3,8 @@ | ||
| 3 | namespace Lib\Imap\Parse; | 3 | namespace Lib\Imap\Parse; |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | +use Lib\Imap\Fun; | ||
| 7 | + | ||
| 6 | /** | 8 | /** |
| 7 | * 解析邮件 | 9 | * 解析邮件 |
| 8 | * @author:dc | 10 | * @author:dc |
| @@ -74,7 +76,23 @@ class Header{ | @@ -74,7 +76,23 @@ class Header{ | ||
| 74 | 76 | ||
| 75 | } | 77 | } |
| 76 | 78 | ||
| 79 | + // 头信息content-type | ||
| 80 | + $contentType = $this->get('content-type'); | ||
| 81 | + if($contentType){ | ||
| 82 | + preg_match("/charset=\"?([a-z0-9-._]{2,})\"?/",$contentType,$charset); | ||
| 83 | + if(!empty($charset[1])){ | ||
| 84 | + // 编码 | ||
| 85 | + $this->setAttribute('charset',$charset[1]); | ||
| 86 | + } | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + // 编码 | ||
| 90 | + $charset = $this->get('charset'); | ||
| 91 | + | ||
| 77 | foreach ($this->attributes as $name => $attribute){ | 92 | foreach ($this->attributes as $name => $attribute){ |
| 93 | + if($charset){ | ||
| 94 | + $attribute = Fun::mb_convert_encoding($attribute,'UTF-8',$charset); | ||
| 95 | + } | ||
| 78 | $attribute = trim($attribute); | 96 | $attribute = trim($attribute); |
| 79 | $this->attributes[$name] = $attribute; | 97 | $this->attributes[$name] = $attribute; |
| 80 | } | 98 | } |
-
请 注册 或 登录 后发表评论