diff --git a/src/Headers.php b/src/Headers.php index 107fa97e..dc4e0afd 100644 --- a/src/Headers.php +++ b/src/Headers.php @@ -83,14 +83,17 @@ public static function fromString($string, $EOL = self::EOL) for ($i = 0; $i < $total; $i += 1) { $line = $lines[$i]; - // 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 ($line === "") { + // Empty line indicates end of headers + // EXCEPT if there are more lines, in which case, there's a possible error condition $emptyLine += 1; if ($emptyLine > 2) { throw new Exception\RuntimeException('Malformed header detected'); } continue; + } elseif (preg_match('/^\s*$/', $line)) { + // skip empty continuation line + continue; } if ($emptyLine > 1) { diff --git a/test/Storage/MessageTest.php b/test/Storage/MessageTest.php index 73aa3be5..c0ba8b8c 100644 --- a/test/Storage/MessageTest.php +++ b/test/Storage/MessageTest.php @@ -156,16 +156,19 @@ public function testAllowWhitespaceInEmptySingleLineHeader(): void ); } - public function testNotAllowWhitespaceInEmptyMultiLineHeader(): void + public function testAllowWhitespaceInEmptyMultiLineHeader(): void { $src = "From: user@example.com\nTo: userpal@example.net\n" . "Subject: This is your reminder\n \n \n" . " about the football game tonight\n" . "Date: Wed, 20 Oct 2010 20:53:35 -0400\n\n" . "Don't forget to meet us for the tailgate party!\n"; - - $this->expectException(MailException\RuntimeException::class); $message = new Message(['raw' => $src]); + + $this->assertEquals( + 'This is your reminder about the football game tonight', + $message->getHeader('subject', 'string') + ); } public function testContentTypeDecode(): void