From 7078a0e53e3b050c8008f9d8ae43c8d697fbc94c Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 27 Sep 2018 02:12:02 +0200 Subject: [PATCH 1/2] Mailer: discover sendmail path instead of hardcoding it to /usr/sbin/sendmail `sendmail` can very well be in a path different from `/usr/sbin/sendmail`. We already search `$PATH` at `lib/private/Settings/Admin/Mail.php` to detect whether we want to offer sendmail as a mail transfer method, so let's be consistent and actually initialize `\Swift_SendmailTransport` with this path to sendmail, instead of just hardcoding `/usr/sbin/sendmail`. Signed-off-by: Florian Klink --- lib/private/Mail/Mailer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Mail/Mailer.php b/lib/private/Mail/Mailer.php index 6f148bc0c6..79208f9a69 100644 --- a/lib/private/Mail/Mailer.php +++ b/lib/private/Mail/Mailer.php @@ -274,7 +274,7 @@ class Mailer implements IMailer { $binaryPath = '/var/qmail/bin/sendmail'; break; default: - $binaryPath = '/usr/sbin/sendmail'; + $binaryPath = \OC_Helper::findBinaryPath('sendmail'); break; } From 054056a8df9b5fd6651db7fbe771ca04ba37761a Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 2 Nov 2018 14:03:11 +0100 Subject: [PATCH 2/2] Fallback to default path is sendmail can't be found If the sendmail binary can't be found at all we fallback to the default path. It most likely is not there but then at least a proper error message pops up. Updated the tests to also properly pass. Signed-off-by: Roeland Jago Douma --- lib/private/Mail/Mailer.php | 6 +++++- tests/lib/Mail/MailerTest.php | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/private/Mail/Mailer.php b/lib/private/Mail/Mailer.php index 79208f9a69..df23b66936 100644 --- a/lib/private/Mail/Mailer.php +++ b/lib/private/Mail/Mailer.php @@ -274,7 +274,11 @@ class Mailer implements IMailer { $binaryPath = '/var/qmail/bin/sendmail'; break; default: - $binaryPath = \OC_Helper::findBinaryPath('sendmail'); + $sendmail = \OC_Helper::findBinaryPath('sendmail'); + if ($sendmail === null) { + $sendmail = '/usr/sbin/sendmail'; + } + $binaryPath = $sendmail; break; } diff --git a/tests/lib/Mail/MailerTest.php b/tests/lib/Mail/MailerTest.php index d724cd630d..ddae38ff54 100644 --- a/tests/lib/Mail/MailerTest.php +++ b/tests/lib/Mail/MailerTest.php @@ -55,7 +55,13 @@ class MailerTest extends TestCase { ->with('mail_smtpmode', 'smtp') ->will($this->returnValue('sendmail')); - $this->assertEquals(new \Swift_SendmailTransport('/usr/sbin/sendmail -bs'), self::invokePrivate($this->mailer, 'getSendMailInstance')); + $path = \OC_Helper::findBinaryPath('sendmail'); + if ($path === null) { + $path = '/usr/sbin/sendmail'; + } + + $expected = new \Swift_SendmailTransport($path . ' -bs'); + $this->assertEquals($expected, self::invokePrivate($this->mailer, 'getSendMailInstance')); } public function testGetSendMailInstanceSendMailQmail() {