Skip to content

Commit c5703ae

Browse files
Sébastien Despontfabpot
authored andcommitted
Add retry_period option for email transport
1 parent 04ee771 commit c5703ae

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Symfony/Component/Mailer/Tests/TransportTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public static function fromStringProvider(): iterable
5858
'roundrobin(dummy://a failover(dummy://b dummy://a) dummy://b)',
5959
new RoundRobinTransport([$transportA, new FailoverTransport([$transportB, $transportA]), $transportB]),
6060
];
61+
62+
yield 'round robin transport with retry period' => [
63+
'roundrobin(dummy://a dummy://b)?retry_period=15',
64+
new RoundRobinTransport([$transportA, $transportB], 15),
65+
];
6166
}
6267

6368
/**

src/Symfony/Component/Mailer/Transport.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ public function fromStrings(#[\SensitiveParameter] array $dsns): Transports
107107
public function fromString(#[\SensitiveParameter] string $dsn): TransportInterface
108108
{
109109
[$transport, $offset] = $this->parseDsn($dsn);
110-
if ($offset !== \strlen($dsn)) {
110+
$dnsWithoutMainOptions = preg_replace('/[?&]retry_period=\d+/', '', $dsn);
111+
if ($offset !== \strlen($dnsWithoutMainOptions)) {
111112
throw new InvalidArgumentException('The mailer DSN has some garbage at the end.');
112113
}
113114

@@ -121,6 +122,10 @@ private function parseDsn(#[\SensitiveParameter] string $dsn, int $offset = 0):
121122
'roundrobin' => RoundRobinTransport::class,
122123
];
123124

125+
$parsedUrl = parse_url($dsn);
126+
parse_str($parsedUrl['query'] ?? '', $query);
127+
$retryPeriod = min((int) ($query['retry_period'] ?? 60), 60);
128+
124129
while (true) {
125130
foreach ($keywords as $name => $class) {
126131
$name .= '(';
@@ -145,7 +150,7 @@ private function parseDsn(#[\SensitiveParameter] string $dsn, int $offset = 0):
145150
}
146151
}
147152

148-
return [new $class($args), $offset];
153+
return [new $class($args, $retryPeriod), $offset];
149154
}
150155
}
151156

0 commit comments

Comments
 (0)