Skip to content

Commit

Permalink
Merge pull request #46480 from nextcloud/fix/mailer-binaryfinder-fall…
Browse files Browse the repository at this point in the history
…back

fix(Mailer): Fix sendmail binary fallback
  • Loading branch information
icewind1991 authored Sep 16, 2024
2 parents dde0b48 + 87aa126 commit ede0c26
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion apps/settings/lib/Settings/Admin/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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', ''),
Expand Down
3 changes: 2 additions & 1 deletion apps/settings/tests/Settings/Admin/MailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 4 additions & 1 deletion lib/private/Mail/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
3 changes: 2 additions & 1 deletion tests/lib/Mail/MailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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';
}
Expand Down

0 comments on commit ede0c26

Please sign in to comment.