Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions parse_emails/handle_eml.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ def decode_content(mime):
Decode content
"""
charset = mime.get_content_charset()
if (charset == 'utf-8' and mime.get('content-transfer-encoding', '') == '8bit'):
return mime.get_payload()
payload = mime.get_payload(decode=True)
try:
if payload:
Expand Down
17 changes: 17 additions & 0 deletions parse_emails/tests/parse_emails_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,3 +887,20 @@ def test_multipart_defective():
results = email_parser.parse()
assert results.get('Text')
assert results.get('HTML')


def test_handle_eml_utf8_8bit():
"""
Given:
- chinese eml file encoded in utf-8, 8bit

When:
- parsing the file.

Then:
- make sure the chinese characters were decoded successfully.
"""
email_parser = EmailParser(file_path='parse_emails/tests/test_data/chinese_email_test.eml')
results = email_parser.parse()
expected_response = '这是一个示例邮件,用于演示指定的条件。\r\n它使用了 UTF-8 编码,可以支持多种语言的字符,包括中文。\r\n祝好,\r\n发件人'
assert results['Text'] == expected_response
16 changes: 16 additions & 0 deletions parse_emails/tests/test_data/chinese_email_test.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
To: [email protected]
From: "[email protected]" <[email protected]>
Subject: 示例邮件
Message-ID: <[email protected]>
Date: Wed, 23 Jan 2019 18:55:56 +0100
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101
Thunderbird/60.4.0
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Content-Language: en-US

这是一个示例邮件,用于演示指定的条件。
它使用了 UTF-8 编码,可以支持多种语言的字符,包括中文。
祝好,
发件人
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "parse-emails"
version = "0.1.26"
version = "0.1.27"
description = "Parses an email message file and extracts the data from it."
authors = ["Demisto"]
license = "MIT"
Expand Down