def clear_message(self):
     """
     Clears the test message being built.
     """
     self.message = Message()
     patch_message_for_django_compat(self.message)
     self.headers = []
Example #2
0
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