Пример #1
0
 def test_invariant_encode_decode(self):
     """
     Tests that decoding an encoded address returns the original pair.
     """
     from_email, to_email = '*****@*****.**', '*****@*****.**'
     self.assertEqual(
         verp.decode(verp.encode(from_email, to_email)),
         (from_email, to_email))
Пример #2
0
 def create_bounce_address(self, to):
     """
     Helper method creating a bounce address for the given destination email
     """
     bounce_address = 'bounces+{date}@{pts_fqdn}'.format(
         date=timezone.now().date().strftime('%Y%m%d'),
         pts_fqdn=PTS_FQDN)
     return verp.encode(bounce_address, to)
Пример #3
0
    def test_encode(self):
        """
        Tests for the encode method.
        """
        self.assertEqual(
            verp.encode('*****@*****.**', '[email protected]'),
            '[email protected]')

        self.assertEqual(
            verp.encode('*****@*****.**', '*****@*****.**'),
            '[email protected]')

        self.assertEqual(
            verp.encode('*****@*****.**', '*****@*****.**'),
            '[email protected]')

        self.assertEqual(
            verp.encode('*****@*****.**', 'user+!%-:@[][email protected]'),
            '[email protected]')
Пример #4
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 <pts.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}@{pts_fqdn}".format(date=date.strftime("%Y%m%d"), pts_fqdn=PTS_FQDN)
    message = CustomEmailMessage(msg=received_message, from_email=verp.encode(bounce_address, to_email), to=[to_email])
    return message