作者 邓超

x

... ... @@ -81,4 +81,12 @@ class Address {
return $this->raw;
}
public function toArray():array {
return [
'email' => $this->email,
'name' => $this->name
];
}
}
... ...
... ... @@ -113,7 +113,7 @@ class Header{
* @author:dc
* @time 2024/9/11 15:03
*/
public function getTo() {
public function getTo(bool $isArray = false):array {
// 如果有这个字段,就用这个字段 to字段的邮箱可能被伪造
if(!empty($this->attributes['delivered-to'])){
$to = $this->attributes['delivered-to'];
... ... @@ -121,20 +121,22 @@ class Header{
$to = $this->attributes['to']??'';
}
return $this->parseAddress($to);
return $this->parseAddress($to,$isArray);
}
/**
* 解析地址
* @param string $address
* @param false $isArray 是否返回数组
* @return array
* @author:dc
* @time 2024/9/11 15:53
* @time 2024/9/29 14:54
*/
private function parseAddress(string $address){
private function parseAddress(string $address, $isArray = false){
$arr = [];
foreach (explode(',',$address) as $str){
$arr[] = Address::make($str);
foreach (explode(',',$address) as $k=>$str){
$arr[$k] = Address::make($str);
if($isArray) $arr[$k] = $arr[$k]->toArray();
}
return $arr;
}
... ... @@ -145,9 +147,9 @@ class Header{
* @author:dc
* @time 2024/9/11 15:53
*/
public function getCc()
public function getCc(bool $isArray = false):array
{
return $this->parseAddress($this->attributes['cc']??'');
return $this->parseAddress($this->attributes['cc']??'',$isArray);
}
/**
... ... @@ -156,9 +158,9 @@ class Header{
* @author:dc
* @time 2024/9/11 15:54
*/
public function getBcc()
public function getBcc(bool $isArray = false):array
{
return $this->parseAddress($this->attributes['bcc']??'');
return $this->parseAddress($this->attributes['bcc']??'',$isArray);
}
... ...