8000 [Mailer] Add `retry_period` option for email transport by sdespont · Pull Request #54939 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Mailer] Add retry_period option for email transport #54939

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

Merged
merged 2 commits into from
Jan 4, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Simplify code
  • Loading branch information
fabpot committed Jan 4, 2025
commit 9716a894276772724198db135dddae4360018dcc
14 changes: 7 additions & 7 deletions src/Symfony/Component/Mailer/Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ public function fromStrings(#[\SensitiveParameter] array $dsns): Transports
public function fromString(#[\SensitiveParameter] string $dsn): TransportInterface
{
[$transport, $offset] = $this->parseDsn($dsn);
$dnsWithoutMainOptions = preg_replace('/[?&]retry_period=\d+/', '', $dsn);
if ($offset !== \strlen($dnsWithoutMainOptions)) {
if ($offset !== \strlen($dsn)) {
throw new InvalidArgumentException('The mailer DSN has some garbage at the end.');
}

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

$parsedUrl = parse_url($dsn);
parse_str($parsedUrl['query'] ?? '', $query);
$retryPeriod = min((int) ($query['retry_period'] ?? 60), 60);

while (true) {
foreach ($keywords as $name => $class) {
$name .= '(';
Expand All @@ -150,7 +145,12 @@ private function parseDsn(#[\SensitiveParameter] string $dsn, int $offset = 0):
}
}

return [new $class($args, $retryPeriod), $offset];
parse_str(substr($dsn, $offset + 1), $query);
if ($period = $query['retry_period'] ?? 0) {
return [new $class($args, (int) $period), $offset + \strlen('retry_period='.$period) + 1];
}

return [new $class($args), $offset];
}
}

Expand Down
0