Skip to content

Commit

Permalink
Ensure that dot stuffing is done before encoding (#22)
Browse files Browse the repository at this point in the history
* Added test with mesage body that breaks if dot stuffing is done before encoding. Changed `Writer::writeFiltered` to use `stream_filter_prepend`.

* Added comment since we have no assertions
  • Loading branch information
vortrixs authored Oct 3, 2024
1 parent bab7208 commit f8cd3b5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function writeBase64($input): void
*/
protected function writeFiltered($input, string $filter, array $options = []): void
{
$filter = stream_filter_append($this->output, $filter, STREAM_FILTER_WRITE, $options);
$filter = stream_filter_prepend($this->output, $filter, STREAM_FILTER_WRITE, $options);

$this->write($input);

Expand Down
28 changes: 28 additions & 0 deletions tests/integration/MailServiceCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Kodus\Mail\Test\Integration;

use IntegrationTester;
use Kodus\Mail\Address;
use Kodus\Mail\Message;
use Kodus\Mail\SMTP\Authenticator\NoAuthenticator;
use Kodus\Mail\SMTP\SMTPMailService;
use Kodus\Mail\Test\TestMessageFactory;
Expand Down Expand Up @@ -31,4 +33,30 @@ public function sendMail(IntegrationTester $I)
$service->send($message);
}
}

public function ensureDotStuffingHappensBeforeQuotePrintableEncode(IntegrationTester $I)
{
$text_body = <<<EOT
Test mail 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890.
More text.
EOT;

$service = new SMTPMailService(
$I->createSocketConnector(), new NoAuthenticator(), "localhost"
);

$message = new Message(
new Address("[email protected]", "Rasmus åh Schultz"),
new Address("[email protected]"),
"Hey, Rasmus! I like ÆØÅæøå!",
$text_body,
);

$message->setDate("Thu, 15 Sep 2016 17:20:54 +0200");

$message->setSender(new Address("[email protected]"));

// Throws \Kodus\Mail\SMTP\UnexpectedCodeException if dot stuffing is after encoding
$service->send($message);
}
}

0 comments on commit f8cd3b5

Please sign in to comment.