Merge pull request #46480 from nextcloud/fix/mailer-binaryfinder-fallback

fix(Mailer): Fix sendmail binary fallback
This commit is contained in:
Robin Appelman 2024-09-16 18:18:14 +02:00 committed by GitHub
commit ede0c26b78
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 10 additions and 4 deletions

View file

@ -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', ''),

View file

@ -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',

View file

@ -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);
}
}

View file

@ -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';
}