Skip to content

Commit

Permalink
fix(Mailer): Fix sendmail binary fallback
Browse files Browse the repository at this point in the history
feat: add debug logging to sendmail binary finder

Signed-off-by: Josh <josh.t.richards@gmail.com>

[skip ci]
  • Loading branch information
joshtrichards authored and AndyScherzinger committed Feb 4, 2025
1 parent 7448885 commit 86bdf51
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions apps/settings/lib/Settings/Admin/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions apps/settings/tests/Settings/Admin/MailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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
5 changes: 4 additions & 1 deletion lib/private/Mail/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,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 @@ -373,6 +375,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 @@ -16,6 +16,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 @@ -90,7 +91,7 @@ public function testGetSendmailInstanceSendMail($sendmailMode, $binaryParam) {
['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 86bdf51

Please sign in to comment.