diff --git a/imbox/parser.py b/imbox/parser.py index 6e25a34..9ad1314 100644 --- a/imbox/parser.py +++ b/imbox/parser.py @@ -33,7 +33,7 @@ def decode_mail_header(value, default_charset='us-ascii'): return str_decode(str_encode(value, default_charset, 'replace'), default_charset) else: for index, (text, charset) in enumerate(headers): - logger.debug("Mail header no. {}: {} encoding {}".format(index, str_decode(text, charset or 'utf-8'), charset)) + logger.debug("Mail header no. {}: {} encoding {}".format(index, str_decode(text, charset or 'utf-8', 'replace'), charset)) try: headers[index] = str_decode(text, charset or default_charset, 'replace') diff --git a/tests/parser_tests.py b/tests/parser_tests.py index 46baa70..73f8de0 100644 --- a/tests/parser_tests.py +++ b/tests/parser_tests.py @@ -336,6 +336,9 @@ class TestParser(unittest.TestCase): from_message_object = email.message_from_string("From: John Smith ") self.assertEqual([{'email': 'johnsmith@gmail.com', 'name': 'John Smith'}], get_mail_addresses(from_message_object, 'from')) + invalid_encoding_in_from_message_object = email.message_from_string("From: =?UTF-8?Q?C=E4cilia?= ") + self.assertEqual([{'email': 'caciliahxg827m@example.org', 'name': 'C�cilia'}], get_mail_addresses(invalid_encoding_in_from_message_object, 'from')) + def test_parse_email_with_policy(self): if not SMTP: return