aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2024-09-16 18:18:14 +0200
committerGitHub <noreply@github.com>2024-09-16 18:18:14 +0200
commitede0c26b78722f07ea4b672ff7c00f9723e0454e (patch)
tree238ce2f166036f21a1af1cca01a9e878162a2e91
parentdde0b48c9375ed4f5fd7bac3b03e2b1c75ce9926 (diff)
parent87aa1267a84cef6f8d6bd43956fab2787c80627c (diff)
downloadnextcloud-server-ede0c26b78722f07ea4b672ff7c00f9723e0454e.tar.gz
nextcloud-server-ede0c26b78722f07ea4b672ff7c00f9723e0454e.zip
Merge pull request #46480 from nextcloud/fix/mailer-binaryfinder-fallback
fix(Mailer): Fix sendmail binary fallback
-rw-r--r--apps/settings/lib/Settings/Admin/Mail.php3
-rw-r--r--apps/settings/tests/Settings/Admin/MailTest.php3
-rw-r--r--lib/private/Mail/Mailer.php5
-rw-r--r--tests/lib/Mail/MailerTest.php3
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 0775b50aaa1..a94e3da18fe 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 @@ class Mail implements IDelegatedSettings {
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 021dbac241b..8ea0ea9bb0c 100644
--- a/apps/settings/tests/Settings/Admin/MailTest.php
+++ b/apps/settings/tests/Settings/Admin/MailTest.php
@@ -7,6 +7,7 @@ namespace OCA\Settings\Tests\Settings\Admin;
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 @@ class MailTest extends TestCase {
'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 0a818b847aa..7497a8d9079 100644
--- a/lib/private/Mail/Mailer.php
+++ b/lib/private/Mail/Mailer.php
@@ -334,8 +334,10 @@ class Mailer implements IMailer {
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 @@ class Mailer implements IMailer {
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 9f37b776f17..f215e385e3f 100644
--- a/tests/lib/Mail/MailerTest.php
+++ b/tests/lib/Mail/MailerTest.php
@@ -12,6 +12,7 @@ use OC\Mail\Mailer;
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 @@ class MailerTest extends TestCase {
['mail_sendmailmode', 'smtp', $sendmailMode],
]);
- $path = \OC_Helper::findBinaryPath('sendmail');
+ $path = \OCP\Server::get(IBinaryFinder::class)->findBinaryPath('sendmail');
if ($path === false) {
$path = '/usr/sbin/sendmail';
}