作者 邓超

x

@@ -81,4 +81,12 @@ class Address { @@ -81,4 +81,12 @@ class Address {
81 return $this->raw; 81 return $this->raw;
82 } 82 }
83 83
  84 +
  85 + public function toArray():array {
  86 + return [
  87 + 'email' => $this->email,
  88 + 'name' => $this->name
  89 + ];
  90 + }
  91 +
84 } 92 }
@@ -113,7 +113,7 @@ class Header{ @@ -113,7 +113,7 @@ class Header{
113 * @author:dc 113 * @author:dc
114 * @time 2024/9/11 15:03 114 * @time 2024/9/11 15:03
115 */ 115 */
116 - public function getTo() { 116 + public function getTo(bool $isArray = false):array {
117 // 如果有这个字段,就用这个字段 to字段的邮箱可能被伪造 117 // 如果有这个字段,就用这个字段 to字段的邮箱可能被伪造
118 if(!empty($this->attributes['delivered-to'])){ 118 if(!empty($this->attributes['delivered-to'])){
119 $to = $this->attributes['delivered-to']; 119 $to = $this->attributes['delivered-to'];
@@ -121,20 +121,22 @@ class Header{ @@ -121,20 +121,22 @@ class Header{
121 $to = $this->attributes['to']??''; 121 $to = $this->attributes['to']??'';
122 } 122 }
123 123
124 - return $this->parseAddress($to); 124 + return $this->parseAddress($to,$isArray);
125 } 125 }
126 126
127 /** 127 /**
128 * 解析地址 128 * 解析地址
129 * @param string $address 129 * @param string $address
  130 + * @param false $isArray 是否返回数组
130 * @return array 131 * @return array
131 * @author:dc 132 * @author:dc
132 - * @time 2024/9/11 15:53 133 + * @time 2024/9/29 14:54
133 */ 134 */
134 - private function parseAddress(string $address){ 135 + private function parseAddress(string $address, $isArray = false){
135 $arr = []; 136 $arr = [];
136 - foreach (explode(',',$address) as $str){  
137 - $arr[] = Address::make($str); 137 + foreach (explode(',',$address) as $k=>$str){
  138 + $arr[$k] = Address::make($str);
  139 + if($isArray) $arr[$k] = $arr[$k]->toArray();
138 } 140 }
139 return $arr; 141 return $arr;
140 } 142 }
@@ -145,9 +147,9 @@ class Header{ @@ -145,9 +147,9 @@ class Header{
145 * @author:dc 147 * @author:dc
146 * @time 2024/9/11 15:53 148 * @time 2024/9/11 15:53
147 */ 149 */
148 - public function getCc() 150 + public function getCc(bool $isArray = false):array
149 { 151 {
150 - return $this->parseAddress($this->attributes['cc']??''); 152 + return $this->parseAddress($this->attributes['cc']??'',$isArray);
151 } 153 }
152 154
153 /** 155 /**
@@ -156,9 +158,9 @@ class Header{ @@ -156,9 +158,9 @@ class Header{
156 * @author:dc 158 * @author:dc
157 * @time 2024/9/11 15:54 159 * @time 2024/9/11 15:54
158 */ 160 */
159 - public function getBcc() 161 + public function getBcc(bool $isArray = false):array
160 { 162 {
161 - return $this->parseAddress($this->attributes['bcc']??''); 163 + return $this->parseAddress($this->attributes['bcc']??'',$isArray);
162 } 164 }
163 165
164 166