作者 邓超

解析

@@ -133,11 +133,7 @@ class Header{ @@ -133,11 +133,7 @@ class Header{
133 */ 133 */
134 public function getTo(bool $isArray = false):array { 134 public function getTo(bool $isArray = false):array {
135 // 如果有这个字段,就用这个字段 to字段的邮箱可能被伪造 135 // 如果有这个字段,就用这个字段 to字段的邮箱可能被伪造
136 - if(!empty($this->attributes['delivered-to'])){  
137 - $to = $this->attributes['delivered-to'];  
138 - }else{  
139 - $to = $this->attributes['to']??'';  
140 - } 136 + $to = $this->attributes['to']??$this->attributes['delivered-to'];
141 137
142 return $this->parseAddress($to,$isArray); 138 return $this->parseAddress($to,$isArray);
143 } 139 }
@@ -152,14 +148,25 @@ class Header{ @@ -152,14 +148,25 @@ class Header{
152 */ 148 */
153 private function parseAddress(string $address, $isArray = false){ 149 private function parseAddress(string $address, $isArray = false){
154 $arr = []; 150 $arr = [];
  151 + $address = trim($address);
155 if($address){ 152 if($address){
156 - foreach (explode(',',$address) as $k=>$str){ 153 + $address = explode(',',$address);
  154 + $s = '';
  155 + foreach ($address as $k=>$str){
  156 + // 是否是邮箱
  157 + if (!(str_contains($str, '@') && str_contains($str,'.'))){
  158 + $s .= $str.',';
  159 + continue;
  160 + }
  161 + $str = $s.$str;
  162 + $s = '';
  163 +
157 $arr[$k] = Address::make($str); 164 $arr[$k] = Address::make($str);
158 if($isArray) $arr[$k] = $arr[$k]->toArray(); 165 if($isArray) $arr[$k] = $arr[$k]->toArray();
159 } 166 }
160 } 167 }
161 168
162 - return $arr; 169 + return array_values($arr);
163 } 170 }
164 171
165 /** 172 /**