@@ -408,6 +408,24 @@ private function decodeAddresses($values): array {
408408 "mailbox " => $ mailbox ,
409409 "host " => $ host ,
410410 ];
411+ }elseif (preg_match (
412+ '/^((?P<name>.+)<)(?P<email>[^<]+?)>$/ ' ,
413+ $ split_address ,
414+ $ matches
415+ )) {
416+ $ name = trim (rtrim ($ matches ["name " ]));
417+ if (str_starts_with ($ name , "\"" ) && str_ends_with ($ name , "\"" )) {
418+ $ name = substr ($ name , 1 , -1 );
419+ }elseif (str_starts_with ($ name , "' " ) && str_ends_with ($ name , "' " )) {
420+ $ name = substr ($ name , 1 , -1 );
421+ }
422+ $ email = trim (rtrim ($ matches ["email " ]));
423+ list ($ mailbox , $ host ) = array_pad (explode ("@ " , $ email ), 2 , null );
424+ $ addresses [] = (object )[
425+ "personal " => $ name ,
426+ "mailbox " => $ mailbox ,
427+ "host " => $ host ,
428+ ];
411429 }
412430 }
413431 }
@@ -438,7 +456,6 @@ private function parseAddresses($list): array {
438456
439457 if (is_array ($ list ) === false ) {
440458 if (is_string ($ list )) {
441- // $list = "<noreply@github.com>"
442459 if (preg_match (
443460 '/^(?:(?P<name>.+)\s)?(?(name)<|<?)(?P<email>[^\s]+?)(?(name)>|>?)$/ ' ,
444461 $ list ,
@@ -460,6 +477,32 @@ private function parseAddresses($list): array {
460477 "host " => $ host ,
461478 ]
462479 ];
480+ }elseif (preg_match (
481+ '/^((?P<name>.+)<)(?P<email>[^<]+?)>$/ ' ,
482+ $ list ,
483+ $ matches
484+ )) {
485+ $ name = trim (rtrim ($ matches ["name " ]));
486+ $ email = trim (rtrim ($ matches ["email " ]));
487+ if (str_starts_with ($ name , "\"" ) && str_ends_with ($ name , "\"" )) {
488+ $ name = substr ($ name , 1 , -1 );
489+ }elseif (str_starts_with ($ name , "' " ) && str_ends_with ($ name , "' " )) {
490+ $ name = substr ($ name , 1 , -1 );
491+ }
492+ list ($ mailbox , $ host ) = array_pad (explode ("@ " , $ email ), 2 , null );
493+ if ($ mailbox === "> " ) { // Fix trailing ">" in malformed mailboxes
494+ $ mailbox = "" ;
495+ }
496+ if ($ name === "" && $ mailbox === "" && $ host === "" ) {
497+ return $ addresses ;
498+ }
499+ $ list = [
500+ (object )[
501+ "personal " => $ name ,
502+ "mailbox " => $ mailbox ,
503+ "host " => $ host ,
504+ ]
505+ ];
463506 }else {
464507 return $ addresses ;
465508 }
@@ -501,14 +544,15 @@ private function parseAddresses($list): array {
501544
502545 if ($ address ->host == ".SYNTAX-ERROR. " ) {
503546 $ address ->host = "" ;
547+ }elseif ($ address ->host == "UNKNOWN " ) {
548+ $ address ->host = "" ;
504549 }
505550 if ($ address ->mailbox == "UNEXPECTED_DATA_AFTER_ADDRESS " ) {
506551 $ address ->mailbox = "" ;
552+ }elseif ($ address ->mailbox == "MISSING_MAILBOX_TERMINATOR " ) {
553+ $ address ->mailbox = "" ;
507554 }
508555
509- $ address ->mail = ($ address ->mailbox && $ address ->host ) ? $ address ->mailbox . '@ ' . $ address ->host : false ;
510- $ address ->full = ($ address ->personal ) ? $ address ->personal . ' < ' . $ address ->mail . '> ' : $ address ->mail ;
511-
512556 $ addresses [] = new Address ($ address );
513557 }
514558
0 commit comments