diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ec4d761..32df7d25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ All notable changes to this project will be documented in this file, in reverse - [#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 diff --git a/src/Transport/Sendmail.php b/src/Transport/Sendmail.php index 98ee2142..e92f577d 100644 --- a/src/Transport/Sendmail.php +++ b/src/Transport/Sendmail.php @@ -255,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) { diff --git a/test/Transport/SendmailTest.php b/test/Transport/SendmailTest.php index 111f8f3b..f9524256 100644 --- a/test/Transport/SendmailTest.php +++ b/test/Transport/SendmailTest.php @@ -282,4 +282,26 @@ public function testHeadersToAndSubjectAreNotDuplicated() $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\'foo@example.com\'']; + yield 'not-leading' => ['-bs -f\'foo@example.com\'']; + } + + /** + * @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); + } }