Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge release 2.12.2 into 2.13.x #106

Merged
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,30 @@ All notable changes to this project will be documented in this file, in reverse

- Nothing.

## 2.12.2 - 2020-08-06

### Added

- Nothing.

### Changed

- Nothing.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- [#103](https://github.com/laminas/laminas-mail/pull/103) fixes issues on Windows whereby the "Subject" and "To" headers were duplicated.

- [#104](https://github.com/laminas/laminas-mail/pull/104) fixes an issue that occured when the `Sendmail` transport was configured with a `-f` option (From address). Prior to the fix, the option would be overwritten by the message `From` or `Sender` headers, which could lead to errors on systems where all mail must be sent from a specific address. The fixed behavior is to always honor the `-f` option, and ignore the `From` and `Sender` headers if it was provided to the transport.

## 2.12.1 - 2020-08-05

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/Protocol/SmtpPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function validate($plugin)
throw new InvalidServiceException(sprintf(
'Plugin of type %s is invalid; must extend %s',
(is_object($plugin) ? get_class($plugin) : gettype($plugin)),
Smtp::class
$this->instanceOf
));
}
}
Expand Down
10 changes: 4 additions & 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 Expand Up @@ -260,6 +255,9 @@ protected function prepareParameters(Mail\Message $message)
}

$parameters = (string) $this->parameters;
if (preg_match('/(^| )\-f.+/', $parameters)) {
return $parameters;
}

$sender = $message->getSender();
if ($sender instanceof AddressInterface) {
Expand Down
55 changes: 52 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;
}

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

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,47 @@ 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('[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->assertNotRegExp('/^To: matthew\@example\.org$/m', $this->additional_headers);
$this->assertNotRegExp('/^Subject: Greetings and Salutations!$/m', $this->additional_headers);
}

public function additionalParametersContainingFromSwitch(): iterable
{
yield 'leading' => ['-f\'[email protected]\''];
yield 'not-leading' => ['-bs -f\'[email protected]\''];
}

/**
* @dataProvider additionalParametersContainingFromSwitch
*/
public function testDoesNotInjectFromParameterFromSenderWhenFromOptionPresentInParameters(string $parameters): void
{
if ($this->operating_system == 'WIN') {
$this->markTestSkipped('This test is *nix-specific');
}

$message = $this->getMessage();
$this->transport->setParameters($parameters);

$this->transport->send($message);
$this->assertEquals($parameters, $this->additional_parameters);
}
}