-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
101 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,64 @@ | |
use Opcodes\MailParser\Message; | ||
|
||
it('can parse a simple mail message', function () { | ||
$messageString = <<<EOF | ||
From: Sender <[email protected]> | ||
To: Receiver <[email protected]> | ||
Subject: Test Subject | ||
Message-ID: <[email protected]> | ||
MIME-Version: 1.0 | ||
Date: Fri, 25 Aug 2023 15:36:13 +0200 | ||
Content-Type: text/html; charset=utf-8 | ||
Content-Transfer-Encoding: quoted-printable | ||
Email content goes here. | ||
EOF; | ||
|
||
$message = Message::fromString($messageString); | ||
|
||
expect($message->getFrom())->toBe('Sender <[email protected]>') | ||
->and($message->getTo())->toBe('Receiver <[email protected]>') | ||
->and($message->getSubject())->toBe('Test Subject') | ||
->and($message->getId())->toBe('[email protected]') | ||
->and($message->getDate()?->format('Y-m-d H:i:s'))->toBe('2023-08-25 15:36:13') | ||
->and($message->getContentType())->toBe('text/html; charset=utf-8') | ||
->and($message->getHtmlPart()?->getContent())->toBe('Email content goes here.') | ||
->and($message->getHtmlPart()?->getHeaders())->toBe([ | ||
'Content-Type' => 'text/html; charset=utf-8', | ||
'Content-Transfer-Encoding' => 'quoted-printable', | ||
]); | ||
}); | ||
|
||
it('can parse lowercase headers', function () { | ||
$messageString = <<<EOF | ||
from: Sender <[email protected]> | ||
to: Receiver <[email protected]> | ||
subject: Test Subject | ||
message-id: <[email protected]> | ||
mime-version: 1.0 | ||
date: Fri, 25 Aug 2023 15:36:13 +0200 | ||
content-type: text/html; charset=utf-8 | ||
content-transfer-encoding: quoted-printable | ||
Email content goes here. | ||
EOF; | ||
|
||
$message = Message::fromString($messageString); | ||
|
||
expect($message->getHeaders())->toBe([ | ||
'from' => 'Sender <[email protected]>', | ||
'to' => 'Receiver <[email protected]>', | ||
'subject' => 'Test Subject', | ||
'message-id' => '<[email protected]>', | ||
'mime-version' => '1.0', | ||
'date' => 'Fri, 25 Aug 2023 15:36:13 +0200', | ||
'content-type' => 'text/html; charset=utf-8', | ||
]) | ||
->and($message->getFrom())->toBe('Sender <[email protected]>') | ||
->and($message->getHeader('Content-Type'))->toBe('text/html; charset=utf-8'); | ||
}); | ||
|
||
it('can parse a mail message with boundaries', function () { | ||
date_default_timezone_set('UTC'); | ||
$messageString = <<<EOF | ||
From: [email protected] | ||
|
@@ -177,7 +235,7 @@ | |
</body> | ||
</html> | ||
------=_Part_1_1234567890-- | ||
------=_Part_1_1234567890-- | ||
EOF; | ||
|
||
$message = Message::fromString($messageString); | ||
|