From 87aa1267a84cef6f8d6bd43956fab2787c80627c Mon Sep 17 00:00:00 2001 From: Josh Date: Fri, 12 Jul 2024 18:59:45 -0400 Subject: [PATCH] fix(Mailer): Fix sendmail binary fallback feat: add debug logging to sendmail binary finder Signed-off-by: Josh --- apps/settings/lib/Settings/Admin/Mail.php | 3 ++- apps/settings/tests/Settings/Admin/MailTest.php | 3 ++- lib/private/Mail/Mailer.php | 5 ++++- tests/lib/Mail/MailerTest.php | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/settings/lib/Settings/Admin/Mail.php b/apps/settings/lib/Settings/Admin/Mail.php index 0775b50aaa1ac..a94e3da18fe89 100644 --- a/apps/settings/lib/Settings/Admin/Mail.php +++ b/apps/settings/lib/Settings/Admin/Mail.php @@ -6,6 +6,7 @@ namespace OCA\Settings\Settings\Admin; use OCP\AppFramework\Http\TemplateResponse; +use OCP\IBinaryFinder; use OCP\IConfig; use OCP\IL10N; use OCP\Settings\IDelegatedSettings; @@ -32,7 +33,7 @@ public function __construct(IConfig $config, IL10N $l) { public function getForm() { $parameters = [ // Mail - 'sendmail_is_available' => (bool)\OC_Helper::findBinaryPath('sendmail'), + 'sendmail_is_available' => (bool)\OCP\Server::get(IBinaryFinder::class)->findBinaryPath('sendmail'), 'mail_domain' => $this->config->getSystemValue('mail_domain', ''), 'mail_from_address' => $this->config->getSystemValue('mail_from_address', ''), 'mail_smtpmode' => $this->config->getSystemValue('mail_smtpmode', ''), diff --git a/apps/settings/tests/Settings/Admin/MailTest.php b/apps/settings/tests/Settings/Admin/MailTest.php index 021dbac241b28..8ea0ea9bb0ced 100644 --- a/apps/settings/tests/Settings/Admin/MailTest.php +++ b/apps/settings/tests/Settings/Admin/MailTest.php @@ -7,6 +7,7 @@ use OCA\Settings\Settings\Admin\Mail; use OCP\AppFramework\Http\TemplateResponse; +use OCP\IBinaryFinder; use OCP\IConfig; use OCP\IL10N; use Test\TestCase; @@ -51,7 +52,7 @@ public function testGetForm(): void { 'settings', 'settings/admin/additional-mail', [ - 'sendmail_is_available' => (bool)\OC_Helper::findBinaryPath('sendmail'), + 'sendmail_is_available' => (bool)\OCP\Server::get(IBinaryFinder::class)->findBinaryPath('sendmail'), 'mail_domain' => 'mx.nextcloud.com', 'mail_from_address' => 'no-reply@nextcloud.com', 'mail_smtpmode' => 'smtp', diff --git a/lib/private/Mail/Mailer.php b/lib/private/Mail/Mailer.php index 0a818b847aab8..7497a8d907967 100644 --- a/lib/private/Mail/Mailer.php +++ b/lib/private/Mail/Mailer.php @@ -334,8 +334,10 @@ protected function getSendMailInstance(): SendmailTransport { break; default: $sendmail = \OCP\Server::get(IBinaryFinder::class)->findBinaryPath('sendmail'); - if ($sendmail === null) { + if ($sendmail === false) { + // fallback (though not sure what good it'll do) $sendmail = '/usr/sbin/sendmail'; + $this->logger->debug('sendmail binary search failed, using fallback ' . $sendmail, ['app' => 'core']); } $binaryPath = $sendmail; break; @@ -346,6 +348,7 @@ protected function getSendMailInstance(): SendmailTransport { default => ' -bs', }; + $this->logger->debug('Using sendmail binary: ' . $binaryPath, ['app' => 'core']); return new SendmailTransport($binaryPath . $binaryParam, null, $this->logger); } } diff --git a/tests/lib/Mail/MailerTest.php b/tests/lib/Mail/MailerTest.php index 9f37b776f173e..f215e385e3f75 100644 --- a/tests/lib/Mail/MailerTest.php +++ b/tests/lib/Mail/MailerTest.php @@ -12,6 +12,7 @@ use OC\Mail\Message; use OCP\Defaults; use OCP\EventDispatcher\IEventDispatcher; +use OCP\IBinaryFinder; use OCP\IConfig; use OCP\IL10N; use OCP\IURLGenerator; @@ -86,7 +87,7 @@ public function testGetSendmailInstanceSendMail($sendmailMode, $binaryParam): vo ['mail_sendmailmode', 'smtp', $sendmailMode], ]); - $path = \OC_Helper::findBinaryPath('sendmail'); + $path = \OCP\Server::get(IBinaryFinder::class)->findBinaryPath('sendmail'); if ($path === false) { $path = '/usr/sbin/sendmail'; }