mirror of
https://github.com/nextcloud/server.git
synced 2026-06-09 08:44:07 -04:00
fix(Mailer): Fix sendmail binary fallback
Signed-off-by: Josh <josh.t.richards@gmail.com>
This commit is contained in:
parent
bfa0888217
commit
431c6d0609
4 changed files with 33 additions and 11 deletions
|
|
@ -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;
|
||||
|
|
@ -30,9 +31,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', ''),
|
||||
|
|
|
|||
|
|
@ -7,17 +7,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();
|
||||
|
|
@ -30,7 +30,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')
|
||||
|
|
@ -51,7 +66,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',
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue