aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/settings/lib/Settings/Admin/Mail.php5
-rw-r--r--apps/settings/tests/Settings/Admin/MailTest.php31
-rw-r--r--lib/private/Mail/Mailer.php5
-rw-r--r--tests/lib/Mail/MailerTest.php3
4 files changed, 33 insertions, 11 deletions
diff --git a/apps/settings/lib/Settings/Admin/Mail.php b/apps/settings/lib/Settings/Admin/Mail.php
index 1cdb7315713..99962599ad3 100644
--- a/apps/settings/lib/Settings/Admin/Mail.php
+++ b/apps/settings/lib/Settings/Admin/Mail.php
@@ -28,6 +28,7 @@
namespace OCA\Settings\Settings\Admin;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IBinaryFinder;
use OCP\IConfig;
use OCP\IL10N;
use OCP\Settings\IDelegatedSettings;
@@ -52,9 +53,11 @@ class Mail implements IDelegatedSettings {
* @return TemplateResponse
*/
public function getForm() {
+ $finder = \OCP\Server::get(IBinaryFinder::class);
+
$parameters = [
// Mail
- 'sendmail_is_available' => (bool) \OC_Helper::findBinaryPath('sendmail'),
+ 'sendmail_is_available' => $finder->findBinaryPath('sendmail') !== false,
'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 c3b08a9d509..f4fb7b89e03 100644
--- a/apps/settings/tests/Settings/Admin/MailTest.php
+++ b/apps/settings/tests/Settings/Admin/MailTest.php
@@ -30,17 +30,17 @@ 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 PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class MailTest extends TestCase {
- /** @var Mail */
- private $admin;
- /** @var IConfig */
- private $config;
- /** @var IL10N */
- private $l10n;
+
+ private Mail $admin;
+ private IConfig|MockObject $config;
+ private IL10N|MockObject $l10n;
protected function setUp(): void {
parent::setUp();
@@ -53,7 +53,22 @@ class MailTest extends TestCase {
);
}
- public function testGetForm() {
+ public static function dataGetForm(): array {
+ return [
+ [true],
+ [false],
+ ];
+ }
+
+ /** @dataProvider dataGetForm */
+ public function testGetForm(bool $sendmail) {
+ $finder = $this->createMock(IBinaryFinder::class);
+ $finder->expects(self::once())
+ ->method('findBinaryPath')
+ ->with('sendmail')
+ ->willReturn($sendmail ? '/usr/bin/sendmail': false);
+ $this->overwriteService(IBinaryFinder::class, $finder);
+
$this->config
->expects($this->any())
->method('getSystemValue')
@@ -74,7 +89,7 @@ class MailTest extends TestCase {
'settings',
'settings/admin/additional-mail',
[
- 'sendmail_is_available' => (bool) \OC_Helper::findBinaryPath('sendmail'),
+ 'sendmail_is_available' => $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 2839c1c504e..4cd523ba414 100644
--- a/lib/private/Mail/Mailer.php
+++ b/lib/private/Mail/Mailer.php
@@ -361,8 +361,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;
@@ -373,6 +375,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 e3995fd17be..5e8993f10ea 100644
--- a/tests/lib/Mail/MailerTest.php
+++ b/tests/lib/Mail/MailerTest.php
@@ -16,6 +16,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;
@@ -90,7 +91,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';
}