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

[stable26] use getsystemvalue-functions in Mailer.php #39006

Merged
merged 2 commits into from
Jun 26, 2023
Merged
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
12 changes: 6 additions & 6 deletions lib/private/Mail/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,20 +293,20 @@ protected function getSmtpInstance(): EsmtpTransport {
// either null or true - if nothing is passed, let the symfony mailer figure out the configuration by itself
$mailSmtpsecure = ($this->config->getSystemValue('mail_smtpsecure', null) === 'ssl') ? true : null;
$transport = new EsmtpTransport(
$this->config->getSystemValue('mail_smtphost', '127.0.0.1'),
(int)$this->config->getSystemValue('mail_smtpport', 25),
$this->config->getSystemValueString('mail_smtphost', '127.0.0.1'),
$this->config->getSystemValueInt('mail_smtpport', 25),
$mailSmtpsecure,
null,
$this->logger
);
/** @var SocketStream $stream */
$stream = $transport->getStream();
/** @psalm-suppress InternalMethod */
$stream->setTimeout($this->config->getSystemValue('mail_smtptimeout', 10));
$stream->setTimeout($this->config->getSystemValueInt('mail_smtptimeout', 10));

if ($this->config->getSystemValue('mail_smtpauth', false)) {
$transport->setUsername($this->config->getSystemValue('mail_smtpname', ''));
$transport->setPassword($this->config->getSystemValue('mail_smtppassword', ''));
if ($this->config->getSystemValueBool('mail_smtpauth', false)) {
$transport->setUsername($this->config->getSystemValueString('mail_smtpname', ''));
$transport->setPassword($this->config->getSystemValueString('mail_smtppassword', ''));
}

$streamingOptions = $this->config->getSystemValue('mail_smtpstreamoptions', []);
Expand Down
37 changes: 27 additions & 10 deletions tests/lib/Mail/MailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,16 @@ public function testCreateEMailTemplate() {
public function testStreamingOptions() {
$this->config->method('getSystemValue')
->willReturnMap([
['mail_smtpmode', 'smtp', 'smtp'],
['mail_smtpstreamoptions', [], ['foo' => 1]],
]);
$this->config->method('getSystemValueString')
->willReturnMap([
['mail_smtpmode', 'smtp', 'smtp'],
['overwrite.cli.url', '', ''],
['mail_smtphost', '127.0.0.1', '127.0.0.1'],
]);
$this->config->method('getSystemValueInt')
->willReturnMap([
['mail_smtpport', 25, 25],
['mail_smtptimeout', 10, 10],
]);
Expand All @@ -256,12 +263,20 @@ public function testStreamingOptions() {
public function testStreamingOptionsWrongType() {
$this->config->method('getSystemValue')
->willReturnMap([
['mail_smtpmode', 'smtp', 'smtp'],
['mail_smtpstreamoptions', [], 'bar'],
]);
$this->config->method('getSystemValueString')
->willReturnMap([
['mail_smtpmode', 'smtp', 'smtp'],
['overwrite.cli.url', '', ''],
['mail_smtphost', '127.0.0.1', '127.0.0.1'],
]);
$this->config->method('getSystemValueInt')
->willReturnMap([
['mail_smtpport', 25, 25],
['mail_smtptimeout', 10, 10],
]);

$mailer = self::invokePrivate($this->mailer, 'getInstance');
/** @var EsmtpTransport $transport */
$transport = self::invokePrivate($mailer, 'transport');
Expand All @@ -270,16 +285,17 @@ public function testStreamingOptionsWrongType() {
}

public function testLocalDomain(): void {
$this->config->method('getSystemValue')
$this->config->method('getSystemValueString')
->willReturnMap([
['mail_smtpmode', 'smtp', 'smtp'],
['overwrite.cli.url', '', 'https://some.valid.url.com:8080'],
['mail_smtphost', '127.0.0.1', '127.0.0.1'],
]);
$this->config->method('getSystemValueInt')
->willReturnMap([
['mail_smtpport', 25, 25],
['mail_smtptimeout', 10, 10],
]);
$this->config->method('getSystemValueString')
->with('overwrite.cli.url', '')
->willReturn('https://some.valid.url.com:8080');

/** @var SymfonyMailer $mailer */
$mailer = self::invokePrivate($this->mailer, 'getInstance');
Expand All @@ -292,16 +308,17 @@ public function testLocalDomain(): void {
}

public function testLocalDomainInvalidUrl(): void {
$this->config->method('getSystemValue')
$this->config->method('getSystemValueString')
->willReturnMap([
['mail_smtpmode', 'smtp', 'smtp'],
['overwrite.cli.url', '', 'https:only.slash.does.not.work:8080'],
['mail_smtphost', '127.0.0.1', '127.0.0.1'],
]);
$this->config->method('getSystemValueInt')
->willReturnMap([
['mail_smtpport', 25, 25],
['mail_smtptimeout', 10, 10],
]);
$this->config->method('getSystemValueString')
->with('overwrite.cli.url', '')
->willReturn('https:only.slash.does.not.work:8080');

/** @var SymfonyMailer $mailer */
$mailer = self::invokePrivate($this->mailer, 'getInstance');
Expand Down