Beispiel #1
0
    def test_remove_bcc_from_header(self):
        """
        Test if Bcc is removed from message header before send it
        """
        my_sender = 'Me <*****@*****.**>'
        to = 'Leo Iannacone <*****@*****.**>'
        Cc = 'Leo2 Iannacone <*****@*****.**>, Leo3 Iannacone <*****@*****.**>'
        Bcc = ['Leo{0} Nnc <leo{0}@tests.com>'.format(i) for i in range(4, 30)]
        Bcc = ', '.join(Bcc)
        payload = 'This is the payload of test_remove_bcc_from_header'
        m = MIMEText(payload)
        m['To'] = to
        m['Cc'] = Cc
        m['Bcc'] = Bcc
        m['From'] = my_sender

        new_message = Gmail._remove_bcc_from_header(m)

        # message must be a correct email (parsable)
        new_message = email.message_from_string(new_message)
        self.assertIsInstance(new_message, Message)

        # must not have 'Bcc'
        self.assertFalse('Bcc' in new_message)

        # and must have the same payload
        self.assertEqual(payload, new_message.get_payload())