Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a848d95

Browse filesBrowse files
committed
Implement review comments.
1 parent b488744 commit a848d95
Copy full SHA for a848d95

File tree

4 files changed

+10
-23
lines changed
Filter options

4 files changed

+10
-23
lines changed

‎src/Symfony/Component/Mailer/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/CHANGELOG.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ CHANGELOG
66

77
* Add DSN param `retry_period` to override default email transport retry period
88
* Add `Dsn::getBooleanOption()`
9-
* Add DSN param `force_ipv4` to enforce binding to IPv4
9+
* Add DSN param `source_ip` to allow binding to a specific IPv4 or IPv6 address. If you want to bind IPv4 without specifying an address, use `0.0.0.0`.
1010

1111
7.2
1212
---

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Tests/Transport/Smtp/EsmtpTransportFactoryTest.php
+4-10Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,22 +182,16 @@ public static function createProvider(): iterable
182182
];
183183

184184
$transport = new EsmtpTransport('example.com', 465, true, null, $logger);
185-
$transport->forceIpv4();
185+
$transport->getStream()->setSourceIp('0.0.0.0');
186186
yield [
187-
Dsn::fromString('smtps://:@example.com:465?force_ipv4=true'),
187+
Dsn::fromString('smtps://:@example.com:465?source_ip=0.0.0.0'),
188188
$transport,
189189
];
190190

191191
$transport = new EsmtpTransport('example.com', 465, true, null, $logger);
192-
$transport->forceIpv4();
192+
$transport->getStream()->setSourceIp('[2606:4700:20::681a:5fb]');
193193
yield [
194-
Dsn::fromString('smtps://:@example.com:465?force_ipv4'),
195-
$transport,
196-
];
197-
198-
$transport = new EsmtpTransport('example.com', 465, true, null, $logger);
199-
yield [
200-
Dsn::fromString('smtps://:@example.com:465?force_ipv4=false'),
194+
Dsn::fromString('smtps://:@example.com:465?source_ip=2606:4700:20::681a:5fb'),
201195
$transport,
202196
];
203197
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php
-8Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,6 @@ public function __construct(string $host = 'localhost', int $port = 0, ?bool $tl
7171
$stream->setPort($port);
7272
}
7373

74-
public function forceIpv4(): void
75-
{
76-
$stream = $this->getStream();
77-
if ($stream instanceof SocketStream) {
78-
$stream->setSourceIp('0.0.0.0');
79-
}
80-
}
81-
8274
/**
8375
* @return $this
8476
*/

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransportFactory.php
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,17 @@ public function create(Dsn $dsn): TransportInterface
3232
$tls = 'smtps' === $dsn->getScheme() ? true : ($autoTls ? null : false);
3333
$port = $dsn->getPort(0);
3434
$host = $dsn->getHost();
35-
$forceIpv4 = '' === $dsn->getOption('force_ipv4') || filter_var($dsn->getOption('force_ipv4', false), \FILTER_VALIDATE_BOOL);
3635

3736
$transport = new EsmtpTransport($host, $port, $tls, $this->dispatcher, $this->logger);
3837
$transport->setAutoTls($autoTls);
39-
if ($forceIpv4) {
40-
$transport->forceIpv4();
41-
}
4238

4339
/** @var SocketStream $stream */
4440
$stream = $transport->getStream();
41+
if ($sourceIp = filter_var($dsn->getOption('source_ip', false), \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
42+
$stream->setSourceIp("[$sourceIp]");
43+
} elseif ($sourceIp = filter_var($dsn->getOption('source_ip', false), \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4)) {
44+
$stream->setSourceIp($sourceIp);
45+
}
4546
$streamOptions = $stream->getStreamOptions();
4647

4748
if ('' !== $dsn->getOption('verify_peer') && !filter_var($dsn->getOption('verify_peer', true), \FILTER_VALIDATE_BOOL)) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.