From 49fb5203ab948d492682a82ccc11f5bddacddbd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andi=20R=C3=BCckauer?= Date: Fri, 15 Mar 2019 12:07:36 +0100 Subject: [PATCH 1/5] Implemented test to verify to and subject headers are not duplicated --- test/Transport/SendmailTest.php | 39 +++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/test/Transport/SendmailTest.php b/test/Transport/SendmailTest.php index 9200863a..11ba9c73 100644 --- a/test/Transport/SendmailTest.php +++ b/test/Transport/SendmailTest.php @@ -27,6 +27,7 @@ class SendmailTest extends TestCase public $message; public $additional_headers; public $additional_parameters; + public $operating_system = ''; public function setUp() { @@ -71,9 +72,14 @@ public function getMessage() return $message; } + public function isWindows() + { + return $this->operating_system === 'WIN'; + } + public function testReceivesMailArtifactsOnUnixSystems() { - if ($this->operating_system == 'WIN') { + if ($this->isWindows()) { $this->markTestSkipped('This test is *nix-specific'); } @@ -119,7 +125,7 @@ public function testReceivesMailArtifactsOnWindowsSystems() public function testLinesStartingWithFullStopsArePreparedProperlyForWindows() { - if ($this->operating_system != 'WIN') { + if (! $this->isWindows()) { $this->markTestSkipped('This test is Windows-specific'); } @@ -252,4 +258,33 @@ public function testDoNotAllowMessageWithoutToAndCcAndBccHeaders() $this->expectException(RuntimeException::class); $this->transport->send($message); } + + /** + * @see https://github.com/zendframework/zend-mail/issues/22 + */ + public function testHeadersToAndSubjectAreNotDuplicated() + { + $lineBreak = $this->isWindows() ? "\r\n" : "\n"; + + $message = new Message(); + $message + ->addTo('matthew@example.org') + ->addFrom('ralph@example.org') + ->setSubject('Greetings and Salutations!') + ->setBody("Sorry, I'm going to be late today!"); + + $this->transport->send($message); + + $this->assertEquals('matthew@example.org', $this->to); + $this->assertEquals('Greetings and Salutations!', $this->subject); + + $this->assertNotContains( + 'To: matthew@example.org, matthew@example.org' . $lineBreak, + $this->additional_headers + ); + $this->assertNotContains( + 'Subject: Greetings and Salutations!, Greetings and Salutations!' . $lineBreak, + $this->additional_headers + ); + } } From 81bc5cacd74205b375998b26b7f22ab8390ed854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andi=20R=C3=BCckauer?= Date: Fri, 15 Mar 2019 12:07:45 +0100 Subject: [PATCH 2/5] Strip 'to' and 'subject' headers regardless of operating system, fixes #22 --- src/Transport/Sendmail.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Transport/Sendmail.php b/src/Transport/Sendmail.php index 821c94e3..78aeb851 100644 --- a/src/Transport/Sendmail.php +++ b/src/Transport/Sendmail.php @@ -221,12 +221,7 @@ protected function prepareBody(Mail\Message $message) */ protected function prepareHeaders(Mail\Message $message) { - // On Windows, simply return verbatim - if ($this->isWindowsOs()) { - return $message->getHeaders()->toString(); - } - - // On *nix platforms, strip the "to" header + // Strip the "to" and "subject" headers $headers = clone $message->getHeaders(); $headers->removeHeader('To'); $headers->removeHeader('Subject'); From 500107fdaced95026dc9306ad4b4716ccdf06ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andi=20R=C3=BCckauer?= Date: Fri, 15 Mar 2019 12:13:03 +0100 Subject: [PATCH 3/5] Add CHANGELOG entry for #225 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7ac968e..a68d7c92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- Nothing. +- [#225](https://github.com/zendframework/zend-mail/pull/225) fixes duplicate `to` and `subject` headers on Windows ## 2.10.0 - 2018-06-07 From cf79426ea3da8d11478b9849a8ab2f3d0d9a23cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andi=20R=C3=BCckauer?= Date: Fri, 15 Mar 2019 12:22:39 +0100 Subject: [PATCH 4/5] Removed initial value assignment, which is being overwritten in constructor --- test/Transport/SendmailTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Transport/SendmailTest.php b/test/Transport/SendmailTest.php index 11ba9c73..cb898c30 100644 --- a/test/Transport/SendmailTest.php +++ b/test/Transport/SendmailTest.php @@ -27,7 +27,7 @@ class SendmailTest extends TestCase public $message; public $additional_headers; public $additional_parameters; - public $operating_system = ''; + public $operating_system; public function setUp() { From a37062e37aeb6ab60061e775aeed95f4441bc848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andi=20R=C3=BCckauer?= Date: Sat, 16 Mar 2019 20:31:46 +0100 Subject: [PATCH 5/5] Reference reporting issue --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a68d7c92..3fb54ead 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,8 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- [#225](https://github.com/zendframework/zend-mail/pull/225) fixes duplicate `to` and `subject` headers on Windows +- [#225](https://github.com/zendframework/zend-mail/pull/225) fixes duplicate `to` and `subject` headers on Windows reported in + [#22](https://github.com/zendframework/zend-mail/issues/22) ## 2.10.0 - 2018-06-07