Skip to content

Commit

Permalink
bug: account for IPV6 in sendgrid (#7219)
Browse files Browse the repository at this point in the history
  • Loading branch information
thelostone-mc authored Aug 12, 2020
1 parent 7e2212c commit 7e4dcec
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions app/marketing/webhookviews.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from datetime import datetime

from django.core.validators import validate_ipv46_address
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt

Expand Down Expand Up @@ -51,15 +52,23 @@ def process(request):
response = json.loads(request.body)

for event in response:

try:
ip = event.get('ip')
validate_ipv46_address(ip)
ip_address = ip
except Exception:
ip_address = None

try:
created_on = datetime.utcfromtimestamp(event['timestamp']).replace(tzinfo=pytz.utc)
email_event = EmailEvent(
email=event['email'],
event=event['event'],
category=event.get('category', ''),
created_on=created_on,
ip_address=event.get('ip').split(':')[0],
)
ip_address=ip_address,
)
events.append(email_event)
except Exception:
pass
Expand Down

0 comments on commit 7e4dcec

Please sign in to comment.