Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Bugfix/duplicat subject header #225

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ 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 reported in
[#22](https://github.com/zendframework/zend-mail/issues/22)

## 2.10.0 - 2018-06-07

Expand Down
7 changes: 1 addition & 6 deletions src/Transport/Sendmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
39 changes: 37 additions & 2 deletions test/Transport/SendmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class SendmailTest extends TestCase
public $message;
public $additional_headers;
public $additional_parameters;
public $operating_system;

public function setUp()
{
Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -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('[email protected]')
->addFrom('[email protected]')
->setSubject('Greetings and Salutations!')
->setBody("Sorry, I'm going to be late today!");

$this->transport->send($message);

$this->assertEquals('[email protected]', $this->to);
$this->assertEquals('Greetings and Salutations!', $this->subject);

$this->assertNotContains(
'To: [email protected], [email protected]' . $lineBreak,
$this->additional_headers
);
$this->assertNotContains(
'Subject: Greetings and Salutations!, Greetings and Salutations!' . $lineBreak,
$this->additional_headers
);
}
}