Skip to content

Commit e129f15

Browse files
committed
[Mailer] removed the auth mode DSN option and support in the eSMTP transport
1 parent 4e6a8b2 commit e129f15

File tree

4 files changed

+10
-43
lines changed

4 files changed

+10
-43
lines changed

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`)

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),

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
}

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)