作者 邓超

x

@@ -48,7 +48,8 @@ class Address { @@ -48,7 +48,8 @@ class Address {
48 $this->name = trim(str_replace([$email,'"','<','>','&gt;','&lt;'],'',$this->raw)); 48 $this->name = trim(str_replace([$email,'"','<','>','&gt;','&lt;'],'',$this->raw));
49 } 49 }
50 if($this->name){ 50 if($this->name){
51 - $this->name = DeCode::decode($this->name); 51 +// $this->name = DeCode::decode($this->name);
  52 + $this->name = Header::mime_decode($this->name);
52 }else{ 53 }else{
53 $this->name = explode('@',$this->email)[0]??''; 54 $this->name = explode('@',$this->email)[0]??'';
54 } 55 }
@@ -180,12 +180,7 @@ class Header{ @@ -180,12 +180,7 @@ class Header{
180 * @time 2024/9/11 15:22 180 * @time 2024/9/11 15:22
181 */ 181 */
182 public function getSubject():string { 182 public function getSubject():string {
183 - $subject = explode("\n",$this->attributes['subject']??'');  
184 - foreach ($subject as $ak=>$str){  
185 - $subject[$ak] = DeCode::decode($str);  
186 - }  
187 -  
188 - return implode("\n",$subject); 183 + return static::mime_decode($this->attributes['subject']??'');
189 } 184 }
190 185
191 186
@@ -264,4 +259,26 @@ class Header{ @@ -264,4 +259,26 @@ class Header{
264 return $this->raw_header; 259 return $this->raw_header;
265 } 260 }
266 261
  262 + /**
  263 + * 解析加密字符
  264 + * @param string $str
  265 + * @return string
  266 + * @author:dc
  267 + * @time 2024/9/29 14:21
  268 + */
  269 + public static function mime_decode(string $str):string {
  270 + $str = trim($str);
  271 + if(preg_match("/^=\?([a-z0-9-]{3,})\?[bq]\?/i",$str,$code)){
  272 + // 解码 这个函数好像已经转码了,
  273 + $str = mb_decode_mimeheader($str);
  274 +
  275 + return $str;
  276 + // 转字符编码
  277 +// return mb_convert_encoding($str,'utf-8',$code[1]);
  278 + }
  279 +
  280 + return $str;
  281 + }
  282 +
  283 +
267 } 284 }