Small refactor to reduce complexity and satisfy codestyle.

This module could do with a look to check if we can simplify it. But at the moment we just want to record the complaint.
This commit is contained in:
Rebecca Law
2018-05-30 16:25:49 +01:00
parent e82fa2c8d4
commit 621c81a9d8

View File

@@ -33,12 +33,8 @@ def process_ses_response(ses_request):
notification_type = ses_message['notificationType']
if notification_type == 'Bounce':
current_app.logger.info('SES bounce dict: {}'.format(remove_emails_from_bounce(ses_message['bounce'])))
if ses_message['bounce']['bounceType'] == 'Permanent':
notification_type = ses_message['bounce']['bounceType'] # permanent or not
else:
notification_type = 'Temporary'
if notification_type == 'Complaint':
notification_type = determine_notification_bounce_type(notification_type, ses_message)
elif notification_type == 'Complaint':
current_app.logger.info("Complaint from SES: \n{}".format(ses_message))
return
@@ -95,6 +91,15 @@ def process_ses_response(ses_request):
return error
def determine_notification_bounce_type(notification_type, ses_message):
current_app.logger.info('SES bounce dict: {}'.format(remove_emails_from_bounce(ses_message['bounce'])))
if ses_message['bounce']['bounceType'] == 'Permanent':
notification_type = ses_message['bounce']['bounceType'] # permanent or not
else:
notification_type = 'Temporary'
return notification_type
def remove_emails_from_bounce(bounce_dict):
for recip in bounce_dict['bouncedRecipients']:
recip.pop('emailAddress')