Mailgun: handle x.y.z status code in webhooks

Mailgun sometimes (though not usually) gives the 'code' event
field as an RFC-3463 extended SMTP status code. Handle either
format.

Fixes #62
This commit is contained in:
medmunds
2017-05-22 11:09:26 -07:00
parent bb54806dcf
commit ba6ccdb13a
2 changed files with 28 additions and 0 deletions

View File

@@ -92,6 +92,15 @@ class MailgunTrackingWebhookView(MailgunBaseWebhookView):
mta_status = int(esp_event['code'])
except (KeyError, TypeError):
pass
except ValueError:
# RFC-3463 extended SMTP status code (class.subject.detail, where class is "2", "4" or "5")
try:
status_class = esp_event['code'].split('.')[0]
except (TypeError, IndexError):
# illegal SMTP status code format
pass
else:
reject_reason = RejectReason.BOUNCED if status_class in ("4", "5") else RejectReason.OTHER
else:
reject_reason = self.reject_reasons.get(
mta_status,