mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Postmark: workaround invalid "test inbound" data
Postmark's "test" button in their inbound settings posts data with attachments that don't match their docs or actual inbound behavior. Accept that and issue a warning. Closes #304
This commit is contained in:
committed by
GitHub
parent
d9a80e7347
commit
885eb9b98a
@@ -1,8 +1,9 @@
|
||||
import json
|
||||
import warnings
|
||||
|
||||
from django.utils.dateparse import parse_datetime
|
||||
|
||||
from ..exceptions import AnymailConfigurationError
|
||||
from ..exceptions import AnymailConfigurationError, AnymailWarning
|
||||
from ..inbound import AnymailInboundMessage
|
||||
from ..signals import (
|
||||
AnymailInboundEvent,
|
||||
@@ -169,7 +170,13 @@ class PostmarkInboundWebhookView(PostmarkBaseWebhookView):
|
||||
attachments = [
|
||||
AnymailInboundMessage.construct_attachment(
|
||||
content_type=attachment["ContentType"],
|
||||
content=attachment["Content"],
|
||||
content=(
|
||||
attachment.get("Content")
|
||||
# WORKAROUND:
|
||||
# The test webhooks are not like their real webhooks
|
||||
# This allows the test webhooks to be parsed.
|
||||
or attachment["Data"]
|
||||
),
|
||||
base64=True,
|
||||
filename=attachment.get("Name", "") or None,
|
||||
content_id=attachment.get("ContentID", "") or None,
|
||||
@@ -177,6 +184,18 @@ class PostmarkInboundWebhookView(PostmarkBaseWebhookView):
|
||||
for attachment in esp_event.get("Attachments", [])
|
||||
]
|
||||
|
||||
# Warning to the user regarding the workaround of above.
|
||||
for attachment in esp_event.get("Attachments", []):
|
||||
if "Data" in attachment:
|
||||
warnings.warn(
|
||||
"Received a test webhook attachment. "
|
||||
"It is recommended to test with real inbound events. "
|
||||
"See https://github.com/anymail/django-anymail/issues/304 "
|
||||
"for more information.",
|
||||
AnymailWarning,
|
||||
)
|
||||
break
|
||||
|
||||
message = AnymailInboundMessage.construct(
|
||||
from_email=self._address(esp_event.get("FromFull")),
|
||||
to=", ".join([self._address(to) for to in esp_event.get("ToFull", [])]),
|
||||
|
||||
Reference in New Issue
Block a user