diff --git a/src/Header/AbstractAddressList.php b/src/Header/AbstractAddressList.php index 0676ff8e..f53d7def 100644 --- a/src/Header/AbstractAddressList.php +++ b/src/Header/AbstractAddressList.php @@ -87,6 +87,7 @@ function ($value) use (&$wasEncoded) { }, $values ); + $addresses = array_filter($addresses); $header = new static(); @@ -145,11 +146,11 @@ public function getFieldValue($format = HeaderInterface::FORMAT_RAW) $name = HeaderWrap::mimeEncodeValue($name, $encoding); } - if (preg_match('/^(.*)\<(.+)@([^@]+)\>(.*)$/', $value, $matches)) { + if (preg_match('/^(.*)\<(.+)@([^@]+)\>(.*)$/', $email, $matches)) { $localPart = $matches[2]; $hostname = $this->idnToAscii($matches[3]); $email = sprintf('%s@%s', $localPart, $hostname); - } elseif (preg_match('/^(.+)@([^@]+)$/', $value, $matches)) { + } elseif (preg_match('/^(.+)@([^@]+)$/', $email, $matches)) { $localPart = $matches[1]; $hostname = $this->idnToAscii($matches[2]); $email = sprintf('%s@%s', $localPart, $hostname); diff --git a/src/Headers.php b/src/Headers.php index b8058b97..773b5f2c 100644 --- a/src/Headers.php +++ b/src/Headers.php @@ -71,23 +71,26 @@ public static function fromString($string, $EOL = self::EOL) // iterate the header lines, some might be continuations $lines = explode($EOL, $string); $total = count($lines); + for ($i = 0; $i < $total; $i += 1) { $line = $lines[$i]; + $isEmptyLine = preg_match('/^\s*$/', $line); // Empty line indicates end of headers - // EXCEPT if there are more lines, in which case, there's a possible error condition - if (preg_match('/^\s*$/', $line)) { + if ($isEmptyLine) { $emptyLine += 1; - if ($emptyLine > 2) { - throw new Exception\RuntimeException('Malformed header detected'); - } continue; } - if ($emptyLine > 1) { + // if some data follow by empty lines then indicate malform headers + if ($emptyLine > 1 && !$isEmptyLine) { throw new Exception\RuntimeException('Malformed header detected'); } + if (!$isEmptyLine) { + $emptyLine = 0; + } + // check if a header name is present if (preg_match('/^[\x21-\x39\x3B-\x7E]+:.*$/', $line)) { if ($currentLine) {