作者 邓超

1

... ... @@ -579,11 +579,16 @@ class Imap {
preg_match('/\("charset" "([a-z0-9\-]{3,})"\)/iU',$result[$key]['BODYSTRUCTURE'],$charset);
// 编码
if(!empty($charset[1])){
// $encode = mb_detect_encoding($str, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));
$result[$key]['HEADER.FIELDS']['Subject'] = mb_convert_encoding($result[$key]['HEADER.FIELDS']['Subject'], 'UTF-8', $charset[1]);
$result[$key]['HEADER.FIELDS']['From'] = mb_convert_encoding($result[$key]['HEADER.FIELDS']['From'], 'UTF-8', $charset[1]);
$result[$key]['HEADER.FIELDS']['To'] = mb_convert_encoding($result[$key]['HEADER.FIELDS']['To'], 'UTF-8', $charset[1]);
$charset = [$charset[1]];
}else{
$charset = [];
}
$result[$key]['HEADER.FIELDS']['Subject'] = MailFun::mb_coding($result[$key]['HEADER.FIELDS']['Subject'],$charset);
$result[$key]['HEADER.FIELDS']['From'] = MailFun::mb_coding($result[$key]['HEADER.FIELDS']['From'],$charset);
$result[$key]['HEADER.FIELDS']['To'] = MailFun::mb_coding($result[$key]['HEADER.FIELDS']['To'],$charset);
}
return $result;
... ...
... ... @@ -200,8 +200,6 @@ class Mail {
}
try {
$file_header = $result['BODYSTRUCTURE'];
// 没有收件人
if(!empty($header['To'])){
$header['To'] = MailFun::toOrFrom($header['To']);
... ... @@ -233,7 +231,7 @@ class Mail {
'folder_id' => $folder_id,
'email_id' => $email_id,
'uuid' => md5($email_id.$folder_id.$result['UID']),
'is_file' => MailFun::isFile($file_header[$key]['BODYSTRUCTURE']??'') //是否附件
'is_file' => MailFun::isFile($result['BODYSTRUCTURE']??'') //是否附件
];
}catch (\Throwable $e){
logs(
... ...
... ... @@ -25,7 +25,20 @@ class MailFun {
return \json_encode($data,$option);
}
/**
* @param $str
* @param string $encode
* @return string
* @author:dc
* @time 2023/3/27 13:55
*/
public static function mb_coding(string $str,array $appcode=[]){
$encode = mb_detect_encoding($str, array_merge(array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'),$appcode));
if($encode){
return mb_convert_encoding($str, 'UTF-8', $encode);
}
return $str;
}
/**
... ... @@ -42,8 +55,8 @@ class MailFun {
// }
// }
// return 0;
$json = is_array($BODYSTRUCTURE) ? json_encode($BODYSTRUCTURE) : $BODYSTRUCTURE;
return strpos($json,'"attachment"')!==false;
$json = is_array($BODYSTRUCTURE) ? implode(' ',$BODYSTRUCTURE) : $BODYSTRUCTURE;
return str_contains(mb_strtolower($json), '"attachment"');
}
... ...