8000 [Mailer][Postmark][Webhook] Accept different date formats · symfony/symfony@8af3d02 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8af3d02

Browse files
committed
[Mailer][Postmark][Webhook] Accept different date formats
Postmark webhooks sometimes use "plain" ISO 6801 format, sometimes including 7 digits microseconds. As the PHP parameter only allows for 6 digits neither would parse without fallbacks. Fixes #53788
1 parent fa843ce commit 8af3d02

File tree

9 files changed

+16
-10
lines changed

9 files changed

+16
-10
lines changed

src/Symfony/Component/Mailer/Bridge/Postmark/RemoteEvent/PostmarkPayloadConverter.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ public function convert(array $payload): AbstractMailerEvent
4747
'SpamComplaint' => $payload['BouncedAt'],
4848
default => throw new ParseException(sprintf('Unsupported event "%s".', $payload['RecordType'])),
4949
};
50-
if (!$date = \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', $payloadDate)) {
50+
51+
$date = \DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, $payloadDate)
52+
// microseconds, 6 digits
53+
?: \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', $payloadDate)
54+
// microseconds, 7 digits
55+
?: \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.u?P', $payloadDate);
56+
57+
if (!$date) {
5158
throw new ParseException(sprintf('Invalid date "%s".', $payloadDate));
5259
}
5360
$event->setDate($date);

src/Symfony/Component/Mailer/Bridge/Postmark/Tests/Webhook/Fixtures/bounce.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"Details": "Test bounce details",
1717
"Email": "john@example.com",
1818
"From": "sender@example.com",
19-
"BouncedAt": "2022-09-02T14:29:19Z",
19+
"BouncedAt": "2022-09-02T14:29:19.1234567Z",
2020
"DumpAvailable": true,
2121
"Inactive": true,
2222
"CanActivate": true,

src/Symfony/Component/Mailer/Bridge/Postmark/Tests/Webhook/Fixtures/bounce.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
$wh->setTags(['Test']);
88
$wh->setMetadata(['example' => 'value', 'example_2' => 'value']);
99
$wh->setReason('The server was unable to deliver your message (ex: unknown user, mailbox not found).');
10-
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', '2022-09-02T14:29:19Z'));
10+
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', '2022-09-02T14:29:19.123456Z'));
1111

1212
return $wh;

src/Symfony/Component/Mailer/Bridge/Postmark/Tests/Webhook/Fixtures/delivery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
$wh->setTags(['welcome-email']);
88
$wh->setMetadata(['example' => 'value', 'example_2' => 'value']);
99
$wh->setReason('');
10-
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', '2022-09-02T11:49:27Z'));
10+
$wh->setDate(\DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, '2022-09-02T11:49:27Z'));
1111

1212
return $wh;

src/Symfony/Component/Mailer/Bridge/Postmark/Tests/Webhook/Fixtures/link_click.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
$wh->setRecipientEmail('john@example.com');
77
$wh->setTags(['welcome-email']);
88
$wh->setMetadata(['example' => 'value', 'example_2' => 'value']);
9-
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', '2022-09-02T14:31:09Z'));
9+
$wh->setDate(\DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, '2022-09-02T14:31:09Z'));
1010

1111
return $wh;

src/Symfony/Component/Mailer/Bridge/Postmark/Tests/Webhook/Fixtures/open.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
$wh->setRecipientEmail('john@example.com');
77
$wh->setTags(['welcome-email']);
88
$wh->setMetadata(['example' => 'value', 'example_2' => 'value']);
9-
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', '2022-09-02T14:30:47Z'));
9+
$wh->setDate(\DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, '2022-09-02T14:30:47Z'));
1010

1111
return $wh;

src/Symfony/Component/Mailer/Bridge/Postmark/Tests/Webhook/Fixtures/spam_complaint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"Details": "Test spam complaint details",
1717
"Email": "john@example.com",
1818
"From": "sender@example.com",
19-
"BouncedAt": "2022-09-02T14:29:57Z",
19+
"BouncedAt": "2022-09-02T14:29:57.123456Z",
2020
"DumpAvailable": true,
2121
"Inactive": true,
2222
"CanActivate": false,

src/Symfony/Component/Mailer/Bridge/Postmark/Tests/Webhook/Fixtures/spam_complaint.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
$wh->setRecipientEmail('john@example.com');
77
$wh->setTags(['Test']);
88
$wh->setMetadata(['example' => 'value', 'example_2' => 'value']);
9-
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', '2022-09-02T14:29:57Z'));
10-
9+
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', '2022-09-02T14:29:57.123456Z'));
1110
return $wh;

src/Symfony/Component/Mailer/Bridge/Postmark/Tests/Webhook/Fixtures/subscription_change.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
$wh->setRecipientEmail('john@example.com');
77
$wh->setTags(['welcome-email']);
88
$wh->setMetadata(['example' => 'value', 'example_2' => 'value']);
9-
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sT', '2022-09-02T14:32:30Z'));
9+
$wh->setDate(\DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, '2022-09-02T14:32:30Z'));
1010

1111
return $wh;

0 commit comments

Comments
 (0)
0