fix decoding of sender e-mail if badly encoded
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -336,6 +336,9 @@ class TestParser(unittest.TestCase):
|
||||
from_message_object = email.message_from_string("From: John Smith <johnsmith@gmail.com>")
|
||||
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?= <caciliahxg827m@example.org>")
|
||||
self.assertEqual([{'email': 'caciliahxg827m@example.org', 'name': 'C<EFBFBD>cilia'}], get_mail_addresses(invalid_encoding_in_from_message_object, 'from'))
|
||||
|
||||
def test_parse_email_with_policy(self):
|
||||
if not SMTP:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user