Function to process a delivery notification

def process_delivery(message, notification):
    """Function to process a delivery notification"""
    mail = message['mail']
    delivery = message['delivery']

    if 'timestamp' in delivery:
        delivered_datetime = clean_time(delivery['timestamp'])
    else:
        delivered_datetime = None

    deliveries = []
    for eachrecipient in delivery['recipients']:
        # Create each delivery 
        deliveries += [Delivery.objects.create(
            sns_topic=notification['TopicArn'],
            sns_messageid=notification['MessageId'],
            mail_timestamp=clean_time(mail['timestamp']),
            mail_id=mail['messageId'],
            mail_from=mail['source'],
            address=eachrecipient,
            # delivery
            delivered_time=delivered_datetime,
            processing_time=int(delivery['processingTimeMillis']),
            smtp_response=delivery['smtpResponse']
        )]

    # Send signals for each delivery.
    for eachdelivery in deliveries:
        signals.feedback.send(
            sender=Delivery,
            instance=eachdelivery,
            message=message,
            notification=notification
        )

    logger.info('Logged %s Deliveries(s)', str(len(deliveries)))

    return HttpResponse('Delivery Processed')