def prepare_message(received_message, to_email, date): """ Converts a message which is to be sent to a subscriber to a :py:class:`CustomEmailMessage <distro_tracker.core.utils.email_messages.CustomEmailMessage>` so that it can be sent out using Django's API. It also sets the required evelope-to value in order to track the bounce for the message. :param received_message: The modified received package message to be sent to the subscribers. :type received_message: :py:class:`email.message.Message` or an equivalent interface object :param to_email: The email of the subscriber to whom the message is to be sent :type to_email: string :param date: The date which should be used as the message's sent date. :type date: :py:class:`datetime.datetime` """ bounce_address = 'bounces+{date}@{distro_tracker_fqdn}'.format( date=date.strftime('%Y%m%d'), distro_tracker_fqdn=DISTRO_TRACKER_FQDN) message = CustomEmailMessage( msg=patch_message_for_django_compat(received_message), from_email=verp.encode(bounce_address, to_email), to=[to_email]) return message
def create_bounce_address(self, to): """ Helper method creating a bounce address for the given destination email """ bounce_address = 'bounces+{date}@{distro_tracker_fqdn}'.format( date=timezone.now().date().strftime('%Y%m%d'), distro_tracker_fqdn=DISTRO_TRACKER_FQDN) return verp.encode(bounce_address, to)