-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: setup check for mail transport php-mail
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
- Loading branch information
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail\SetupChecks; | ||
|
||
use OCP\IConfig; | ||
use OCP\IL10N; | ||
use OCP\SetupCheck\ISetupCheck; | ||
use OCP\SetupCheck\SetupResult; | ||
|
||
class MailTransport implements ISetupCheck { | ||
Check failure on line 17 in lib/SetupChecks/MailTransport.php GitHub Actions / static-psalm-analysis dev-stable27UndefinedClass
|
||
public function __construct( | ||
private IConfig $config, | ||
private IL10N $l10n, | ||
) { | ||
} | ||
|
||
public function getName(): string { | ||
return $this->l10n->t('Mail Transport configuration'); | ||
} | ||
|
||
public function getCategory(): string { | ||
return 'mail'; | ||
} | ||
|
||
public function run(): SetupResult { | ||
$transport = $this->config->getSystemValueString('app.mail.transport', 'smtp'); | ||
|
||
if ($transport === 'smtp') { | ||
return SetupResult::success(); | ||
} | ||
|
||
return SetupResult::warning( | ||
$this->l10n->t('The app.mail.transport setting is not set to smtp. This configuration can cause issues with modern email security measures such as SPF and DKIM because emails are sent directly from the web server, which is often not properly configured for this purpose. To address this, we have discontinued support for the mail transport. Please remove app.mail.transport from your configuration to use the SMTP transport and hide this message. A properly configured SMTP setup is required to ensure email delivery.') | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
namespace Unit\SetupChecks; | ||
|
||
use ChristophWurst\Nextcloud\Testing\TestCase; | ||
use OC\L10N\L10N; | ||
use OCA\Mail\SetupChecks\MailTransport; | ||
use OCP\IConfig; | ||
use OCP\IL10N; | ||
use OCP\SetupCheck\SetupResult; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
|
||
class MailTransportTest extends TestCase { | ||
private IConfig&MockObject $config; | ||
private IL10N&MockObject $l10n; | ||
private MailTransport $check; | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
$this->config = $this->createMock(IConfig::class); | ||
$this->l10n = $this->createMock(L10N::class); | ||
|
||
$this->check = new MailTransport($this->config, $this->l10n); | ||
} | ||
|
||
public function testSuccess(): void { | ||
$this->config->method('getSystemValueString') | ||
->willReturn('smtp'); | ||
|
||
$result = $this->check->run(); | ||
|
||
$this->assertEquals(SetupResult::SUCCESS, $result->getSeverity()); | ||
} | ||
|
||
public function testWarning(): void { | ||
$this->config->method('getSystemValueString') | ||
->willReturn('mail'); | ||
|
||
$result = $this->check->run(); | ||
|
||
$this->assertEquals(SetupResult::WARNING, $result->getSeverity()); | ||
} | ||
|
||
public function testName(): void { | ||
$this->l10n->method('t') | ||
->willReturn('Translated Name'); | ||
|
||
$this->assertEquals('Translated Name', $this->check->getName()); | ||
} | ||
|
||
public function testCategory(): void { | ||
$this->assertEquals('mail', $this->check->getCategory()); | ||
} | ||
} |