diff --git a/src/Transport/Sendmail.php b/src/Transport/Sendmail.php index 3223b3fa..98ee2142 100644 --- a/src/Transport/Sendmail.php +++ b/src/Transport/Sendmail.php @@ -222,12 +222,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'); diff --git a/test/Transport/SendmailTest.php b/test/Transport/SendmailTest.php index abdd3787..111f8f3b 100644 --- a/test/Transport/SendmailTest.php +++ b/test/Transport/SendmailTest.php @@ -28,6 +28,7 @@ class SendmailTest extends TestCase public $message; public $additional_headers; public $additional_parameters; + public $operating_system; public function setUp() { @@ -72,9 +73,14 @@ public function getMessage() return $message; } + private 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'); } @@ -96,7 +102,7 @@ public function testReceivesMailArtifactsOnUnixSystems() public function testReceivesMailArtifactsOnWindowsSystems() { - if ($this->operating_system != 'WIN') { + if (! $this->isWindows()) { $this->markTestSkipped('This test is Windows-specific'); } @@ -120,7 +126,7 @@ public function testReceivesMailArtifactsOnWindowsSystems() public function testLinesStartingWithFullStopsArePreparedProperlyForWindows() { - if ($this->operating_system != 'WIN') { + if (! $this->isWindows()) { $this->markTestSkipped('This test is Windows-specific'); } @@ -255,4 +261,25 @@ public function testDoNotAllowMessageWithoutToAndCcAndBccHeaders() $this->expectException(RuntimeException::class); $this->transport->send($message); } + + /** + * @see https://github.com/laminas/laminas-mail/issues/19 + */ + public function testHeadersToAndSubjectAreNotDuplicated() + { + $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->assertNotRegExp('/^To: matthew\@example\.org$/m', $this->additional_headers); + $this->assertNotRegExp('/^Subject: Greetings and Salutations!$/m', $this->additional_headers); + } }