зеркало из https://github.com/nextcloud/server.git
Set local domain for swiftmailer transport
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
This commit is contained in:
Родитель
719430559f
Коммит
747325fc43
|
@ -45,11 +45,11 @@ use OCP\IL10N;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
use OCP\L10N\IFactory;
|
use OCP\L10N\IFactory;
|
||||||
|
use OCP\Mail\Events\BeforeMessageSent;
|
||||||
use OCP\Mail\IAttachment;
|
use OCP\Mail\IAttachment;
|
||||||
use OCP\Mail\IEMailTemplate;
|
use OCP\Mail\IEMailTemplate;
|
||||||
use OCP\Mail\IMailer;
|
use OCP\Mail\IMailer;
|
||||||
use OCP\Mail\IMessage;
|
use OCP\Mail\IMessage;
|
||||||
use OCP\Mail\Events\BeforeMessageSent;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Mailer provides some basic functions to create a mail message that can be used in combination with
|
* Class Mailer provides some basic functions to create a mail message that can be used in combination with
|
||||||
|
@ -293,6 +293,15 @@ class Mailer implements IMailer {
|
||||||
$transport->setStreamOptions($streamingOptions);
|
$transport->setStreamOptions($streamingOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$overwriteCliUrl = parse_url(
|
||||||
|
$this->config->getSystemValueString('overwrite.cli.url', ''),
|
||||||
|
PHP_URL_HOST
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!empty($overwriteCliUrl)) {
|
||||||
|
$transport->setLocalDomain($overwriteCliUrl);
|
||||||
|
}
|
||||||
|
|
||||||
return $transport;
|
return $transport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,8 @@ use OCP\ILogger;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
use OCP\L10N\IFactory;
|
use OCP\L10N\IFactory;
|
||||||
use OCP\Mail\Events\BeforeMessageSent;
|
use OCP\Mail\Events\BeforeMessageSent;
|
||||||
use Test\TestCase;
|
|
||||||
use Swift_SwiftException;
|
use Swift_SwiftException;
|
||||||
|
use Test\TestCase;
|
||||||
|
|
||||||
class MailerTest extends TestCase {
|
class MailerTest extends TestCase {
|
||||||
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
|
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
|
||||||
|
@ -218,4 +218,42 @@ class MailerTest extends TestCase {
|
||||||
$mailer = self::invokePrivate($this->mailer, 'getInstance');
|
$mailer = self::invokePrivate($this->mailer, 'getInstance');
|
||||||
$this->assertEquals(0, count($mailer->getTransport()->getStreamOptions()));
|
$this->assertEquals(0, count($mailer->getTransport()->getStreamOptions()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testLocalDomain(): void {
|
||||||
|
$this->config->method('getSystemValue')
|
||||||
|
->willReturnMap([
|
||||||
|
['mail_smtpmode', 'smtp', 'smtp']
|
||||||
|
]);
|
||||||
|
$this->config->method('getSystemValueString')
|
||||||
|
->with('overwrite.cli.url', '')
|
||||||
|
->willReturn('https://some.valid.url.com:8080');
|
||||||
|
|
||||||
|
/** @var \Swift_Mailer $mailer */
|
||||||
|
$mailer = self::invokePrivate($this->mailer, 'getInstance');
|
||||||
|
self::assertInstanceOf(\Swift_Mailer::class, $mailer);
|
||||||
|
|
||||||
|
/** @var \Swift_Transport_EsmtpTransport $transport */
|
||||||
|
$transport = $mailer->getTransport();
|
||||||
|
self::assertInstanceOf(\Swift_Transport_EsmtpTransport::class, $transport);
|
||||||
|
self::assertEquals('some.valid.url.com', $transport->getLocalDomain());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLocalDomainInvalidUrl(): void {
|
||||||
|
$this->config->method('getSystemValue')
|
||||||
|
->willReturnMap([
|
||||||
|
['mail_smtpmode', 'smtp', 'smtp']
|
||||||
|
]);
|
||||||
|
$this->config->method('getSystemValueString')
|
||||||
|
->with('overwrite.cli.url', '')
|
||||||
|
->willReturn('https:only.slash.does.not.work:8080');
|
||||||
|
|
||||||
|
/** @var \Swift_Mailer $mailer */
|
||||||
|
$mailer = self::invokePrivate($this->mailer, 'getInstance');
|
||||||
|
self::assertInstanceOf(\Swift_Mailer::class, $mailer);
|
||||||
|
|
||||||
|
/** @var \Swift_Transport_EsmtpTransport $transport */
|
||||||
|
$transport = $mailer->getTransport();
|
||||||
|
self::assertInstanceOf(\Swift_Transport_EsmtpTransport::class, $transport);
|
||||||
|
self::assertEquals('[127.0.0.1]', $transport->getLocalDomain());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче