Skip to content

Commit ce37267

Browse files
committed
feature #33237 [Mailer] Remove the auth mode DSN option and support in the eSMTP transport (fabpot)
This PR was merged into the 4.4 branch. Discussion ---------- [Mailer] Remove the auth mode DSN option and support in the eSMTP transport | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | yes <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | n/a | License | MIT | Doc PR | - The authentication mode can be automatically negotiated between the Mailer and the SMTP server. There is an option to force it to a given auth mode, but I don't see any valid use case. So, let's remove that feature. Commits ------- 34cbda5 [Mailer] removed the auth mode DSN option and support in the eSMTP transport
2 parents 034c06e + 34cbda5 commit ce37267

File tree

10 files changed

+16
-49
lines changed

10 files changed

+16
-49
lines changed

src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesSmtpTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class SesSmtpTransport extends EsmtpTransport
2525
*/
2626
public function __construct(string $username, string $password, string $region = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
2727
{
28-
parent::__construct(sprintf('email-smtp.%s.amazonaws.com', $region ?: 'eu-west-1'), 587, true, null, $dispatcher, $logger);
28+
parent::__construct(sprintf('email-smtp.%s.amazonaws.com', $region ?: 'eu-west-1'), 587, true, $dispatcher, $logger);
2929

3030
$this->setUsername($username);
3131
$this->setPassword($password);

src/Symfony/Component/Mailer/Bridge/Google/Transport/GmailSmtpTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class GmailSmtpTransport extends EsmtpTransport
2222
{
2323
public function __construct(string $username, string $password, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
2424
{
25-
parent::__construct('smtp.gmail.com', 465, true, null, $dispatcher, $logger);
25+
parent::__construct('smtp.gmail.com', 465, true, $dispatcher, $logger);
2626

2727
$this->setUsername($username);
2828
$this->setPassword($password);

src/Symfony/Component/Mailer/Bridge/Mailchimp/Transport/MandrillSmtpTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MandrillSmtpTransport extends EsmtpTransport
2222
{
2323
public function __construct(string $username, string $password, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
2424
{
25-
parent::__construct('smtp.mandrillapp.com', 587, true, null, $dispatcher, $logger);
25+
parent::__construct('smtp.mandrillapp.com', 587, true, $dispatcher, $logger);
2626

2727
$this->setUsername($username);
2828
$this->setPassword($password);

src/Symfony/Component/Mailer/Bridge/Mailgun/Transport/MailgunSmtpTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MailgunSmtpTransport extends EsmtpTransport
2222
{
2323
public function __construct(string $username, string $password, string $region = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
2424
{
25-
parent::__construct('us' !== ($region ?: 'us') ? sprintf('smtp.%s.mailgun.org', $region) : 'smtp.mailgun.org', 465, true, null, $dispatcher, $logger);
25+
parent::__construct('us' !== ($region ?: 'us') ? sprintf('smtp.%s.mailgun.org', $region) : 'smtp.mailgun.org', 465, true, $dispatcher, $logger);
2626

2727
$this->setUsername($username);
2828
$this->setPassword($password);

src/Symfony/Component/Mailer/Bridge/Postmark/Transport/PostmarkSmtpTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class PostmarkSmtpTransport extends EsmtpTransport
2222
{
2323
public function __construct(string $id, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
2424
{
25-
parent::__construct('smtp.postmarkapp.com', 587, true, null, $dispatcher, $logger);
25+
parent::__construct('smtp.postmarkapp.com', 587, true, $dispatcher, $logger);
2626

2727
$this->setUsername($id);
2828
$this->setPassword($id);

src/Symfony/Component/Mailer/Bridge/Sendgrid/Transport/SendgridSmtpTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class SendgridSmtpTransport extends EsmtpTransport
2222
{
2323
public function __construct(string $key, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
2424
{
25-
parent::__construct('smtp.sendgrid.net', 465, true, null, $dispatcher, $logger);
25+
parent::__construct('smtp.sendgrid.net', 465, true, $dispatcher, $logger);
2626

2727
$this->setUsername('apikey');
2828
$this->setPassword($key);

src/Symfony/Component/Mailer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
4.4.0
55
-----
66

7+
* [BC BREAK] removed the `auth_mode` DSN option (it is now always determined automatically)
78
* STARTTLS cannot be enabled anymore (it is used automatically if TLS is disabled and the server supports STARTTLS)
89
* [BC BREAK] Removed the `encryption` DSN option (use `smtps` instead)
910
* Added support for the `smtps` protocol (does the same as using `smtp` and port `465`)

src/Symfony/Component/Mailer/Tests/Transport/Smtp/EsmtpTransportFactoryTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,30 @@ public function createProvider(): iterable
3838
$eventDispatcher = $this->getDispatcher();
3939
$logger = $this->getLogger();
4040

41-
$transport = new EsmtpTransport('localhost', 25, false, null, $eventDispatcher, $logger);
41+
$transport = new EsmtpTransport('localhost', 25, false, $eventDispatcher, $logger);
4242

4343
yield [
4444
new Dsn('smtp', 'localhost'),
4545
$transport,
4646
];
4747

48-
$transport = new EsmtpTransport('example.com', 99, true, 'login', $eventDispatcher, $logger);
48+
$transport = new EsmtpTransport('example.com', 99, true, $eventDispatcher, $logger);
4949
$transport->setUsername(self::USER);
5050
$transport->setPassword(self::PASSWORD);
5151

5252
yield [
53-
new Dsn('smtps', 'example.com', self::USER, self::PASSWORD, 99, ['auth_mode' => 'login']),
53+
new Dsn('smtps', 'example.com', self::USER, self::PASSWORD, 99),
5454
$transport,
5555
];
5656

57-
$transport = new EsmtpTransport('example.com', 465, true, null, $eventDispatcher, $logger);
57+
$transport = new EsmtpTransport('example.com', 465, true, $eventDispatcher, $logger);
5858

5959
yield [
6060
new Dsn('smtps', 'example.com'),
6161
$transport,
6262
];
6363

64-
$transport = new EsmtpTransport('example.com', 465, true, null, $eventDispatcher, $logger);
64+
$transport = new EsmtpTransport('example.com', 465, true, $eventDispatcher, $logger);
6565

6666
yield [
6767
new Dsn('smtp', 'example.com', '', '', 465),

src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ class EsmtpTransport extends SmtpTransport
2929
private $authenticators = [];
3030
private $username = '';
3131
private $password = '';
32-
private $authMode;
3332

34-
public function __construct(string $host = 'localhost', int $port = 0, bool $tls = null, string $authMode = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
33+
public function __construct(string $host = 'localhost', int $port = 0, bool $tls = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
3534
{
3635
parent::__construct(null, $dispatcher, $logger);
3736

37+
// order is important here (roughly most secure and popular first)
3838
$this->authenticators = [
3939
new Auth\CramMd5Authenticator(),
4040
new Auth\LoginAuthenticator(),
@@ -61,9 +61,6 @@ public function __construct(string $host = 'localhost', int $port = 0, bool $tls
6161

6262
$stream->setHost($host);
6363
$stream->setPort($port);
64-
if (null !== $authMode) {
65-
$this->setAuthMode($authMode);
66-
}
6764
}
6865

6966
public function setUsername(string $username): self
@@ -90,18 +87,6 @@ public function getPassword(): string
9087
return $this->password;
9188
}
9289

93-
public function setAuthMode(string $mode): self
94-
{
95-
$this->authMode = $mode;
96-
97-
return $this;
98-
}
99-
100-
public function getAuthMode(): string
101-
{
102-
return $this->authMode;
103-
}
104-
10590
public function addAuthenticator(AuthenticatorInterface $authenticator): void
10691
{
10792
$this->authenticators[] = $authenticator;
@@ -166,7 +151,7 @@ private function handleAuth(array $modes): void
166151
$authNames = [];
167152
$errors = [];
168153
$modes = array_map('strtolower', $modes);
169-
foreach ($this->getActiveAuthenticators() as $authenticator) {
154+
foreach ($this->authenticators as $authenticator) {
170155
if (!\in_array(strtolower($authenticator->getAuthKeyword()), $modes, true)) {
171156
continue;
172157
}
@@ -195,22 +180,4 @@ private function handleAuth(array $modes): void
195180

196181
throw new TransportException($message);
197182
}
198-
199-
/**
200-
* @return AuthenticatorInterface[]
201-
*/
202-
private function getActiveAuthenticators(): array
203-
{
204-
if (!$mode = strtolower($this->authMode)) {
205-
return $this->authenticators;
206-
}
207-
208-
foreach ($this->authenticators as $authenticator) {
209-
if (strtolower($authenticator->getAuthKeyword()) === $mode) {
210-
return [$authenticator];
211-
}
212-
}
213-
214-
throw new TransportException(sprintf('Auth mode "%s" is invalid.', $mode));
215-
}
216183
}

src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransportFactory.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ final class EsmtpTransportFactory extends AbstractTransportFactory
2323
public function create(Dsn $dsn): TransportInterface
2424
{
2525
$tls = 'smtps' === $dsn->getScheme() ? true : null;
26-
$authMode = $dsn->getOption('auth_mode');
2726
$port = $dsn->getPort(0);
2827
$host = $dsn->getHost();
2928

30-
$transport = new EsmtpTransport($host, $port, $tls, $authMode, $this->dispatcher, $this->logger);
29+
$transport = new EsmtpTransport($host, $port, $tls, $this->dispatcher, $this->logger);
3130

3231
if ($user = $dsn->getUser()) {
3332
$transport->setUsername($user);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy