Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove php-mail transport #10516

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Configure how often Mail keeps users' mailboxes updated in the background in sec
```

### Use php-mail for sending mail

> [!WARNING]
> Support for using php-mail will be removed with Mail 4.2

You can use the php-mail function to send mails. This is needed for some webhosters (1&1 (1und1)):
```php
'app.mail.transport' => 'php-mail'
Expand Down
3 changes: 3 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
use OCA\Mail\Service\Search\MailSearch;
use OCA\Mail\Service\TrustedSenderService;
use OCA\Mail\Service\UserPreferenceService;
use OCA\Mail\SetupChecks\MailTransport;
use OCA\Mail\Vendor\Favicon\Favicon;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
Expand Down Expand Up @@ -155,6 +156,8 @@

$context->registerNotifierService(Notifier::class);

$context->registerSetupCheck(MailTransport::class);

Check warning on line 159 in lib/AppInfo/Application.php

View check run for this annotation

Codecov / codecov/patch

lib/AppInfo/Application.php#L159

Added line #L159 was not covered by tests

// bypass Horde Translation system
Horde_Translation::setHandler('Horde_Imap_Client', new HordeTranslationHandler());
Horde_Translation::setHandler('Horde_Mime', new HordeTranslationHandler());
Expand Down
5 changes: 0 additions & 5 deletions lib/SMTP/SmtpClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace OCA\Mail\SMTP;

use Horde_Mail_Transport;
use Horde_Mail_Transport_Mail;
use Horde_Mail_Transport_Smtphorde;
use Horde_Smtp_Password_Xoauth2;
use OCA\Mail\Account;
Expand Down Expand Up @@ -43,10 +42,6 @@ public function __construct(IConfig $config,
*/
public function create(Account $account): Horde_Mail_Transport {
$mailAccount = $account->getMailAccount();
$transport = $this->config->getSystemValue('app.mail.transport', 'smtp');
if ($transport === 'php-mail') {
return new Horde_Mail_Transport_Mail();
}

$decryptedPassword = null;
if ($mailAccount->getOutboundPassword() !== null) {
Expand Down
43 changes: 43 additions & 0 deletions lib/SetupChecks/MailTransport.php
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 {
public function __construct(

Check warning on line 18 in lib/SetupChecks/MailTransport.php

View check run for this annotation

Codecov / codecov/patch

lib/SetupChecks/MailTransport.php#L18

Added line #L18 was not covered by tests
private IConfig $config,
private IL10N $l10n,
) {
}

Check warning on line 22 in lib/SetupChecks/MailTransport.php

View check run for this annotation

Codecov / codecov/patch

lib/SetupChecks/MailTransport.php#L22

Added line #L22 was not covered by tests

public function getName(): string {
return $this->l10n->t('Mail Transport configuration');

Check warning on line 25 in lib/SetupChecks/MailTransport.php

View check run for this annotation

Codecov / codecov/patch

lib/SetupChecks/MailTransport.php#L24-L25

Added lines #L24 - L25 were not covered by tests
}

public function getCategory(): string {
return 'mail';

Check warning on line 29 in lib/SetupChecks/MailTransport.php

View check run for this annotation

Codecov / codecov/patch

lib/SetupChecks/MailTransport.php#L28-L29

Added lines #L28 - L29 were not covered by tests
}

public function run(): SetupResult {
$transport = $this->config->getSystemValueString('app.mail.transport', 'smtp');

Check warning on line 33 in lib/SetupChecks/MailTransport.php

View check run for this annotation

Codecov / codecov/patch

lib/SetupChecks/MailTransport.php#L32-L33

Added lines #L32 - L33 were not covered by tests

if ($transport === 'smtp') {
return SetupResult::success();

Check warning on line 36 in lib/SetupChecks/MailTransport.php

View check run for this annotation

Codecov / codecov/patch

lib/SetupChecks/MailTransport.php#L35-L36

Added lines #L35 - L36 were not covered by tests
}

return SetupResult::error(
$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.')
);

Check warning on line 41 in lib/SetupChecks/MailTransport.php

View check run for this annotation

Codecov / codecov/patch

lib/SetupChecks/MailTransport.php#L39-L41

Added lines #L39 - L41 were not covered by tests
}
}
25 changes: 0 additions & 25 deletions lib/SystemConfig.php

This file was deleted.

14 changes: 0 additions & 14 deletions tests/Unit/SMTP/SmtpClientFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace OCA\Mail\Tests\Unit\Smtp;

use ChristophWurst\Nextcloud\Testing\TestCase;
use Horde_Mail_Transport_Mail;
use Horde_Mail_Transport_Smtphorde;
use OCA\Mail\Account;
use OCA\Mail\Db\MailAccount;
Expand Down Expand Up @@ -43,19 +42,6 @@ protected function setUp(): void {
$this->factory = new SmtpClientFactory($this->config, $this->crypto, $this->hostNameFactory);
}

public function testPhpMailTransport() {
$account = $this->createMock(Account::class);
$this->config->expects($this->once())
->method('getSystemValue')
->with('app.mail.transport', 'smtp')
->willReturn('php-mail');

$transport = $this->factory->create($account);

$this->assertNotNull($transport);
$this->assertInstanceOf(Horde_Mail_Transport_Mail::class, $transport);
}

public function testSmtpTransport() {
$mailAccount = new MailAccount([
'smtpHost' => 'smtp.domain.tld',
Expand Down
Loading