From c9fd2281c388977b2822745cbe2f73ebbaff6748 Mon Sep 17 00:00:00 2001 From: Alex Kolomiiets Date: Tue, 24 Jan 2017 20:45:20 +0200 Subject: [PATCH] fix cc header parse --- .../Message/Zend/AbstractMessageProvider.php | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/Infrastructure/Message/Zend/AbstractMessageProvider.php b/Infrastructure/Message/Zend/AbstractMessageProvider.php index eeae98a..64f6003 100644 --- a/Infrastructure/Message/Zend/AbstractMessageProvider.php +++ b/Infrastructure/Message/Zend/AbstractMessageProvider.php @@ -57,21 +57,7 @@ protected function processMessageId($headers) public function processFrom($headers) { try { - $from = $headers->toArray()['From']; - - preg_match('/^((?P.*?)<(?P[^>]+)>|(?P.+))/', $from, $matches); - - if (array_key_exists('email', $matches)) { - $email = explode(',', $matches['email'])[0]; - $name = explode('@', $email)[0]; - } else { - $name = $matches['name']; - $email = $matches['namedEmail']; - } - - if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { - throw new \RuntimeException(sprintf('This %s email address is considered invalid.'), $email); - } + list($name, $email) = $this->parseFrom($headers); return new MessageSender($email, $name); } catch (\RuntimeException $e) { @@ -80,6 +66,31 @@ public function processFrom($headers) } } + /** + * @param \Zend\Mail\Headers $headers + * @return array + */ + protected function parseFrom($headers) + { + $from = $headers->toArray()['From']; + + preg_match('/^((?P.*?)<(?P[^>]+)>|(?P.+))/', $from, $matches); + + if (array_key_exists('email', $matches)) { + $email = explode(',', $matches['email'])[0]; + $name = explode('@', $email)[0]; + } else { + $name = $matches['name']; + $email = $matches['namedEmail']; + } + + if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { + throw new \RuntimeException(sprintf('This %s email address is considered invalid.'), $email); + } + + return [$name, $email]; + } + /** * @param \Zend\Mail\Headers $headers * @return string @@ -102,7 +113,7 @@ public function processTo($headers) */ public function processRecipients($headers) { - $processAddressTypes = ['to', 'cc', 'from']; + $processAddressTypes = ['to', 'cc']; $recipients = []; foreach ($processAddressTypes as $type) { @@ -118,6 +129,9 @@ public function processRecipients($headers) } } + list($name, $email) = $this->parseFrom($headers); + $recipients[] = new MessageRecipient($email, $name); + return $recipients; }