new: Test parsing outlook message format

pull/631/head
Jakub Onderka 2020-10-05 16:32:11 +02:00
parent 7f0229b3f1
commit 5e0ad0a47f
4 changed files with 13 additions and 2 deletions

View File

@ -8,6 +8,7 @@ addons:
apt:
packages:
- libfuzzy-dev
- libemail-outlook-message-perl
python:
- "3.6"

View File

@ -87,7 +87,6 @@ class EMailObject(AbstractMISPObjectGenerator):
logger.debug("EmailObject was passed a non-ASCII encoded binary blob.")
try:
if bytes[:3] == b'\xef\xbb\xbf': # utf-8-sig byte-order mark (BOM)
# Set Pseudofile to correctly encoded email in case it is used at some later point.
bytes = bytes.decode("utf_8_sig").encode("ASCII")
message = email.message_from_bytes(bytes, policy=policy.default) # type: ignore
return message

Binary file not shown.

View File

@ -22,5 +22,16 @@ class TestEmailObject(unittest.TestCase):
self.assertIsInstance(file_name, str)
self.assertIsInstance(file_content, BytesIO)
def _get_values(self, obj: EMailObject, relation: str) -> List[str]:
def test_mail_1_msg(self):
email_object = EMailObject(Path("tests/email_testfiles/mail_1.msg"))
self.assertEqual(self._get_values(email_object, "subject")[0],
"Newsletter Prüfung Personalwesen / Prüfung Eröffnungsbilanz")
self.assertIsInstance(email_object.email, EmailMessage)
for file_name, file_content in email_object.attachments:
self.assertIsInstance(file_name, str)
self.assertIsInstance(file_content, BytesIO)
@staticmethod
def _get_values(obj: EMailObject, relation: str) -> List[str]:
return [attr.value for attr in obj.attributes if attr['object_relation'] == relation]