From 92fe2c904be2b48fd818decce608251f46f53917 Mon Sep 17 00:00:00 2001 From: tzmfreedom Date: Wed, 19 Jun 2019 21:01:44 +0900 Subject: [PATCH] only when -f option is set, set -f option automatically --- src/Transport/Sendmail.php | 3 +++ test/Transport/SendmailTest.php | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/Transport/Sendmail.php b/src/Transport/Sendmail.php index 821c94e3..681c5e9e 100644 --- a/src/Transport/Sendmail.php +++ b/src/Transport/Sendmail.php @@ -259,6 +259,9 @@ protected function prepareParameters(Mail\Message $message) } $parameters = (string) $this->parameters; + if (preg_match('/^\-f.+$/', $parameters) || strpos($parameters, ' -f') !== false) { + return $parameters; + } $sender = $message->getSender(); if ($sender instanceof AddressInterface) { diff --git a/test/Transport/SendmailTest.php b/test/Transport/SendmailTest.php index 9200863a..38e4fae7 100644 --- a/test/Transport/SendmailTest.php +++ b/test/Transport/SendmailTest.php @@ -27,6 +27,7 @@ class SendmailTest extends TestCase public $message; public $additional_headers; public $additional_parameters; + public $operating_system; public function setUp() { @@ -252,4 +253,30 @@ public function testDoNotAllowMessageWithoutToAndCcAndBccHeaders() $this->expectException(RuntimeException::class); $this->transport->send($message); } + + public function testNotSetOptionAutomaticallyOnLeadingF() + { + if ($this->operating_system == 'WIN') { + $this->markTestSkipped('This test is *nix-specific'); + } + + $message = $this->getMessage(); + $this->transport->setParameters('-f\'foo@example.com\''); + + $this->transport->send($message); + $this->assertEquals('-f\'foo@example.com\'', $this->additional_parameters); + } + + public function testNotSetOptionAutomaticallyOnMiddleF() + { + if ($this->operating_system == 'WIN') { + $this->markTestSkipped('This test is *nix-specific'); + } + + $message = $this->getMessage(); + $this->transport->setParameters('-bs -f\'foo@example.com\''); + + $this->transport->send($message); + $this->assertEquals('-bs -f\'foo@example.com\'', $this->additional_parameters); + } }