Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
arukompas committed Aug 25, 2023
1 parent 85bb0db commit 94d5da9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,19 @@ protected function parse()
continue;
}

if (isset($this->boundary) && $line === '--'.$this->boundary.'--') {
if (isset($this->boundary) && str_ends_with($line, '--'.$this->boundary.'--')) {
$line = str_replace('--'.$this->boundary.'--', '', $line);
$currentBody .= $line;
// We've reached the end of the message
break;
}

if (isset($this->boundary) && $line === '--'.$this->boundary) {
if (isset($this->boundary) && str_ends_with($line, '--'.$this->boundary)) {
$line = str_replace('--'.$this->boundary, '', $line);

if ($collectingBody) {
// We've reached the end of a part, add it and reset the variables
$this->addPart($currentBody, $currentBodyHeaders);
$this->addPart($currentBody . $line, $currentBodyHeaders);
}

$collectingBody = true;
Expand Down
44 changes: 44 additions & 0 deletions tests/Unit/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,47 @@
</html>
EOF);
});

it('catches boundaries on the same line', function () {
$messageString = <<<EOF
From: [email protected]
To: [email protected]
Subject: This is an email with common headers
Date: Thu, 24 Aug 2023 21:15:01 PST
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="b552as-tfy"
--b552as-tfy
Content-Type: text/html; charset="utf-8"
<html>
<head>
<title>This is an HTML email</title>
</head>
<body>
<h1>This is the HTML version of the email</h1>
</body>
</html>--b552as-tfy
Content-Type: text/plain; name=test.txt
Content-Transfer-Encoding: base64
Content-Disposition: attachment; name=test.txt;
filename="test.txt"; name="test.txt"
VGhpcyBpcyBhIHRlc3Qgc3RyaW5n--b552as-tfy--
EOF;

$message = Message::fromString($messageString);

expect($message->getParts())->toHaveCount(2)
->and($message->getParts()[0]->getContent())->toBe(<<<EOF
<html>
<head>
<title>This is an HTML email</title>
</head>
<body>
<h1>This is the HTML version of the email</h1>
</body>
</html>
EOF)
->and($message->getPArts()[1]->getContent())->toBe('This is a test string');
});

0 comments on commit 94d5da9

Please sign in to comment.