Skip to content

Commit f8cd3b5

Browse files
authored
Ensure that dot stuffing is done before encoding (#22)
* 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
1 parent bab7208 commit f8cd3b5

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/Writer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function writeBase64($input): void
106106
*/
107107
protected function writeFiltered($input, string $filter, array $options = []): void
108108
{
109-
$filter = stream_filter_append($this->output, $filter, STREAM_FILTER_WRITE, $options);
109+
$filter = stream_filter_prepend($this->output, $filter, STREAM_FILTER_WRITE, $options);
110110

111111
$this->write($input);
112112

tests/integration/MailServiceCest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Kodus\Mail\Test\Integration;
44

55
use IntegrationTester;
6+
use Kodus\Mail\Address;
7+
use Kodus\Mail\Message;
68
use Kodus\Mail\SMTP\Authenticator\NoAuthenticator;
79
use Kodus\Mail\SMTP\SMTPMailService;
810
use Kodus\Mail\Test\TestMessageFactory;
@@ -31,4 +33,30 @@ public function sendMail(IntegrationTester $I)
3133
$service->send($message);
3234
}
3335
}
36+
37+
public function ensureDotStuffingHappensBeforeQuotePrintableEncode(IntegrationTester $I)
38+
{
39+
$text_body = <<<EOT
40+
Test mail 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890.
41+
More text.
42+
EOT;
43+
44+
$service = new SMTPMailService(
45+
$I->createSocketConnector(), new NoAuthenticator(), "localhost"
46+
);
47+
48+
$message = new Message(
49+
new Address("blip@test.org", "Rasmus åh Schultz"),
50+
new Address("blub@test.org"),
51+
"Hey, Rasmus! I like ÆØÅæøå!",
52+
$text_body,
53+
);
54+
55+
$message->setDate("Thu, 15 Sep 2016 17:20:54 +0200");
56+
57+
$message->setSender(new Address("someone-else@test.org"));
58+
59+
// Throws \Kodus\Mail\SMTP\UnexpectedCodeException if dot stuffing is after encoding
60+
$service->send($message);
61+
}
3462
}

0 commit comments

Comments
 (0)