Exemple #1
0
    def test_decode_body(self):
        basic_email_text = read_file_to_string(GET_BASIC_EMAIL)
        test_email = message_from_string(basic_email_text)

        email_parser = EmailParser(self.log)
        actual_body = email_parser.decode_body(test_email)

        self.assertEqual(actual_body, "Test\n")
Exemple #2
0
    def test_decode_body_unicode(self):
        basic_email_text = read_file_to_string(GET_BASIC_EMAIL)
        test_email = message_from_string(basic_email_text)
        test_email._payload = 'u"é'

        email_parser = EmailParser(self.log)
        actual_body = email_parser.decode_body(test_email)

        self.assertEqual(actual_body, 'u"')
Exemple #3
0
    def test_decode_multipart_body_html_unicode(self):
        raw_text = read_file_to_string(GET_DOUBLE_ATTACHED_WITH_IMAGES)
        test_email = message_from_string(raw_text)

        email_parser = EmailParser(self.log)
        test_email._payload[0]._payload[
            1]._payload = '<html>FOO u"é BAR</html>'
        actual_body = email_parser.decode_body(test_email._payload[0])

        expected_body = '<html>FOO u"é BAR</html>'
        self.assertEqual(expected_body, actual_body)
Exemple #4
0
    def test_decode_multipart_body_unicode(self):
        raw_text = read_file_to_string(GET_DOUBLE_ATTACHED_WITH_IMAGES)
        test_email = message_from_string(raw_text)

        email_parser = EmailParser(self.log)
        test_email._payload[0]._payload[0]._payload = (
            test_email._payload[0]._payload[0]._payload.replace(
                "*****@*****.**", 'u"é'))
        actual_body = email_parser.decode_body(
            test_email._payload[0]._payload[0])

        expected_body = """________________________________From: Example User <u">Sent: Tuesday, August 13, 2019 3:56 PMTo: Example User <u">Subject: User Test________________________________From: Example User <u">Sent: Tuesday, August 13, 2019 10:55 AMTo: Example User <u">Subject: Fw: Short Test Email________________________________From: Example UserSent: Tuesday, August 13, 2019 9:30 AMTo: u" <u">Subject: Short Test Email"""
        self.assertEqual(expected_body, actual_body)