Skip to content

Commit

Permalink
Merge pull request #145 from AdrienClairembault/fix/multiple-empty-co…
Browse files Browse the repository at this point in the history
…ntinuation-lines

Fix #25; Skip empty continuation lines
  • Loading branch information
Slamdunk authored Mar 15, 2021
2 parents ef83de6 + fc002f8 commit 9a2d989
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 6 additions & 3 deletions test/Storage/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9a2d989

Please sign in to comment.