From ff39b80cdfdea38e5c10b5a942e7b010f7dbd8ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sat, 27 Feb 2021 13:32:37 +0200 Subject: [PATCH] Add unit test for long header wrapping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Elan Ruusamäe --- test/Transport/SmtpTest.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/Transport/SmtpTest.php b/test/Transport/SmtpTest.php index 07a1f9c9..eb987540 100644 --- a/test/Transport/SmtpTest.php +++ b/test/Transport/SmtpTest.php @@ -199,6 +199,33 @@ public function testReceivesMailArtifacts(): void $this->assertStringContainsString("\r\n\r\nThis is only a test.", $data, $data); } + /** + * Fold long lines during smtp communication in Protocol\Smtp class. + * Test folding of long lines following RFC 5322 section-2.2.3 + * + * @see https://github.com/laminas/laminas-mail/pull/140 + */ + public function testLongLinesFoldingRFC5322(): void + { + $message = $this->getMessage(); + // Create buffer of 8192 bytes (PHP_SOCK_CHUNK_SIZE) + $buffer = str_repeat('0123456789abcdef', 512); + $this->assertEquals(8192, strlen($buffer)); + + $headerValue = substr($buffer, 0, 1000); + $bufferSizeHeaderValue = substr($buffer, 0, 8192 - strlen('X-Exact-Length') + 2); + $message->getHeaders()->addHeaders([ + 'X-Ms-Exchange-Antispam-Messagedata' => $headerValue, + 'X-Exact-Length' => $bufferSizeHeaderValue, + ]); + + $this->transport->send($message); + $data = $this->connection->getLog(); + // The original header can't be present if it's wrapped + $this->assertStringNotContainsString($headerValue, $data, "May not contain headerValue"); + $this->assertStringNotContainsString($bufferSizeHeaderValue, $data, "May not contain bufferSizeHeaderValue"); + } + public function testCanUseAuthenticationExtensionsViaPluginManager(): void { $options = new SmtpOptions([