Skip to content

[Mailer][Postmark][Webhook] Accept different date formats #53829

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 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ public function convert(array $payload): AbstractMailerEvent
'SpamComplaint' => $payload['BouncedAt'],
default => throw new ParseException(sprintf('Unsupported event "%s".', $payload['RecordType'])),
};
if (!$date = \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', $payloadDate)) {

$date = \DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, $payloadDate)
// microseconds, 6 digits
?: \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', $payloadDate)
// microseconds, 7 digits
?: \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.u?P', $payloadDate);

if (!$date) {
throw new ParseException(sprintf('Invalid date "%s".', $payloadDate));
}
$event->setDate($date);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"Details": "Test bounce details",
"Email": "john@example.com",
"From": "sender@example.com",
"BouncedAt": "2022-09-02T14:29:19Z",
"BouncedAt": "2022-09-02T14:29:19.1234567Z",
"DumpAvailable": true,
"Inactive": true,
"CanActivate": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
$wh->setTags(['Test']);
$wh->setMetadata(['example' => 'value', 'example_2' => 'value']);
$wh->setReason('The server was unable to deliver your message (ex: unknown user, mailbox not found).');
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', '2022-09-02T14:29:19Z'));
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', '2022-09-02T14:29:19.123456Z'));

return $wh;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
$wh->setTags(['welcome-email']);
$wh->setMetadata(['example' => 'value', 'example_2' => 'value']);
$wh->setReason('');
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', '2022-09-02T11:49:27Z'));
$wh->setDate(\DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, '2022-09-02T11:49:27Z'));

return $wh;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
$wh->setRecipientEmail('john@example.com');
$wh->setTags(['welcome-email']);
$wh->setMetadata(['example' => 'value', 'example_2' => 'value']);
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', '2022-09-02T14:31:09Z'));
$wh->setDate(\DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, '2022-09-02T14:31:09Z'));

return $wh;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
$wh->setRecipientEmail('john@example.com');
$wh->setTags(['welcome-email']);
$wh->setMetadata(['example' => 'value', 'example_2' => 'value']);
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', '2022-09-02T14:30:47Z'));
$wh->setDate(\DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, '2022-09-02T14:30:47Z'));

return $wh;
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"Details": "Test spam complaint details",
"Email": "john@example.com",
"From": "sender@example.com",
"BouncedAt": "2022-09-02T14:29:57Z",
"BouncedAt": "2022-09-02T14:29:57.123456Z",
"DumpAvailable": true,
"Inactive": true,
"CanActivate": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
$wh->setRecipientEmail('john@example.com');
$wh->setTags(['Test']);
$wh->setMetadata(['example' => 'value', 'example_2' => 'value']);
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', '2022-09-02T14:29:57Z'));

$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', '2022-09-02T14:29:57.123456Z'));
return $wh;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
$wh->setRecipientEmail('john@example.com');
$wh->setTags(['welcome-email']);
$wh->setMetadata(['example' => 'value', 'example_2' => 'value']);
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', '2022-09-02T14:32:30Z'));
$wh->setDate(\DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, '2022-09-02T14:32:30Z'));

return $wh;