mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Fix: Postmark tracking webhook handle SubscriptionChange events
Handle Postmark SubscriptionChange events as Anymail unsubscribe, subscribe, or bounce Anymail tracking events.
This commit is contained in:
@@ -34,6 +34,7 @@ class PostmarkTrackingWebhookView(PostmarkBaseWebhookView):
|
||||
'Delivery': EventType.DELIVERED,
|
||||
'Open': EventType.OPENED,
|
||||
'SpamComplaint': EventType.COMPLAINED,
|
||||
'SubscriptionChange': EventType.UNSUBSCRIBED,
|
||||
'Inbound': EventType.INBOUND, # future, probably
|
||||
}
|
||||
|
||||
@@ -61,6 +62,7 @@ class PostmarkTrackingWebhookView(PostmarkBaseWebhookView):
|
||||
'InboundError': (EventType.INBOUND_FAILED, None),
|
||||
'DMARCPolicy': (EventType.REJECTED, RejectReason.BLOCKED),
|
||||
'TemplateRenderingFailed': (EventType.FAILED, None),
|
||||
'ManualSuppression': (EventType.UNSUBSCRIBED, RejectReason.UNSUBSCRIBED),
|
||||
}
|
||||
|
||||
def esp_to_anymail_event(self, esp_event):
|
||||
@@ -87,11 +89,21 @@ class PostmarkTrackingWebhookView(PostmarkBaseWebhookView):
|
||||
event_type, reject_reason = self.event_types[esp_event['Type']]
|
||||
except KeyError:
|
||||
pass
|
||||
if event_type == EventType.UNSUBSCRIBED:
|
||||
if esp_event['SuppressSending']:
|
||||
# Postmark doesn't provide a way to distinguish between
|
||||
# explicit unsubscribes and bounces
|
||||
try:
|
||||
event_type, reject_reason = self.event_types[esp_event['SuppressionReason']]
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
event_type, reject_reason = self.event_types['Subscribe']
|
||||
|
||||
recipient = getfirst(esp_event, ['Email', 'Recipient'], None) # Email for bounce; Recipient for open
|
||||
|
||||
try:
|
||||
timestr = getfirst(esp_event, ['DeliveredAt', 'BouncedAt', 'ReceivedAt'])
|
||||
timestr = getfirst(esp_event, ['DeliveredAt', 'BouncedAt', 'ReceivedAt', 'ChangedAt'])
|
||||
except KeyError:
|
||||
timestamp = None
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user