Skip to content

Commit

Permalink
Fixes laminas#19 Fixes laminas#72 duplicate subject header on windows
Browse files Browse the repository at this point in the history
Signed-off-by: Abdul Malik Ikhsan <[email protected]>
  • Loading branch information
samsonasik committed Aug 5, 2020
1 parent 80a39ef commit a6f59d4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
7 changes: 1 addition & 6 deletions src/Transport/Sendmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
41 changes: 38 additions & 3 deletions test/Transport/SendmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SendmailTest extends TestCase
public $message;
public $additional_headers;
public $additional_parameters;
public $operating_system;

public function setUp()
{
Expand Down Expand Up @@ -72,9 +73,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 All @@ -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');
}

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

Expand Down Expand Up @@ -255,4 +261,33 @@ public function testDoNotAllowMessageWithoutToAndCcAndBccHeaders()
$this->expectException(RuntimeException::class);
$this->transport->send($message);
}

/**
* @see @see https://github.com/laminas/laminas-mail/issues/19
*/
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
);
}
}

0 comments on commit a6f59d4

Please sign in to comment.