fix: ignore poorly encoded email parts
This commit is contained in:
parent
59d1eefa61
commit
f974fcabac
2 changed files with 9 additions and 2 deletions
|
|
@ -435,7 +435,8 @@ class Email:
|
|||
|
||||
self.from_real_name = parse_addr(_from_email)[0] if "@" in _from_email else _from_email
|
||||
|
||||
def decode_email(self, email):
|
||||
@staticmethod
|
||||
def decode_email(email):
|
||||
if not email:
|
||||
return
|
||||
decoded = ""
|
||||
|
|
@ -443,7 +444,7 @@ class Email:
|
|||
frappe.as_unicode(email).replace('"', " ").replace("'", " ")
|
||||
):
|
||||
if encoding:
|
||||
decoded += part.decode(encoding)
|
||||
decoded += part.decode(encoding, "replace")
|
||||
else:
|
||||
decoded += safe_decode(part)
|
||||
return decoded
|
||||
|
|
|
|||
|
|
@ -197,6 +197,12 @@ Reply-To: test2_@erpnext.com
|
|||
mail = Email(content_bytes)
|
||||
self.assertEqual(mail.text_content, text_content)
|
||||
|
||||
def test_poorly_encoded_messages(self):
|
||||
mail = Email.decode_email(
|
||||
"=?iso-2022-jp?B?VEFLQVlBTUEgS2FvcnUgWxskQnxiOzMbKEIgGyRCNzAbKEJd?=\n\t<user@example.com>"
|
||||
)
|
||||
self.assertIn("user@example.com", mail)
|
||||
|
||||
|
||||
def fixed_column_width(string, chunk_size):
|
||||
parts = [string[0 + i : chunk_size + i] for i in range(0, len(string), chunk_size)]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue