作者 邓超

调整优化

... ... @@ -26,9 +26,10 @@ class Fun {
$from = 'iso-8859-8';
}
if ($from && in_array($from, mb_list_encodings())) {
try {
return mb_convert_encoding($str,$to,$from);
}
}catch (\Throwable $e){}
return mb_convert_encoding($str,$to);
}
... ...
... ... @@ -263,7 +263,10 @@ class Body {
$this->parseMimeHeaderChild($data,'Content-Disposition');
// 默认编码
if(!$data->Charset) $data->Charset = 'utf-8';
if(!$data->Charset)
{
$data->Charset = $this->header->get('charset') ? : 'utf-8';
}
// 处理content id中意外的字符串
$data->set('Content-ID',trim(str_replace(['"','<','>'],'',$data->get('Content-ID'))));
... ...
... ... @@ -3,6 +3,8 @@
namespace Lib\Imap\Parse;
use Lib\Imap\Fun;
/**
* 解析邮件
* @author:dc
... ... @@ -74,7 +76,23 @@ class Header{
}
// 头信息content-type
$contentType = $this->get('content-type');
if($contentType){
preg_match("/charset=\"?([a-z0-9-._]{2,})\"?/",$contentType,$charset);
if(!empty($charset[1])){
// 编码
$this->setAttribute('charset',$charset[1]);
}
}
// 编码
$charset = $this->get('charset');
foreach ($this->attributes as $name => $attribute){
if($charset){
$attribute = Fun::mb_convert_encoding($attribute,'UTF-8',$charset);
}
$attribute = trim($attribute);
$this->attributes[$name] = $attribute;
}
... ...