From 95d793ea6a7100a38ca656141273767f67e1eb87 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Fri, 17 Oct 2025 09:04:56 +0200 Subject: [PATCH 1/2] fix: [tools-emailobject] Circuvent crashes when dealing with ms-tnef messages --- pymisp/tools/emailobject.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pymisp/tools/emailobject.py b/pymisp/tools/emailobject.py index 4de2a46b..21d112db 100644 --- a/pymisp/tools/emailobject.py +++ b/pymisp/tools/emailobject.py @@ -158,7 +158,10 @@ def _build_eml(self, message: EmailMessage, body: dict[str, Any], attachments: l body.get('html'), body.get('rtf')] if i is not None] # If this a non-multipart email then we only need to attach the payload - if message.get_content_maintype() != 'multipart': + if ( + message.get_content_maintype() != "multipart" and + "application/ms-tnef" not in message.get("content-type", message.get_content_maintype()) + ): for _body in body_objects: if "text/{}".format(_body['subtype']) == message.get_content_type(): message.set_content(**_body) From 69ef1737f898f992422740e77805c552168f965d Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Fri, 17 Oct 2025 09:17:43 +0200 Subject: [PATCH 2/2] fix: [tools:emailobject] Gracefully handle case where getStringStream cannot find the requested stream --- pymisp/tools/emailobject.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pymisp/tools/emailobject.py b/pymisp/tools/emailobject.py index 21d112db..a19f3c5c 100644 --- a/pymisp/tools/emailobject.py +++ b/pymisp/tools/emailobject.py @@ -222,12 +222,13 @@ def _build_eml(self, message: EmailMessage, body: dict[str, Any], attachments: l for attch in attachments: # Add attachments at the end. if attch.cid not in related_content.keys(): _content_type = attch.getStringStream('__substg1.0_370E') - maintype, subtype = _content_type.split("/", 1) - message.add_attachment(attch.data, - maintype=maintype, - subtype=subtype, - cid=attch.cid, - filename=attch.longFilename) + if _content_type is not None: + maintype, subtype = _content_type.split("/", 1) + message.add_attachment(attch.data, + maintype=maintype, + subtype=subtype, + cid=attch.cid, + filename=attch.longFilename) if p := message.get_payload(): if isinstance(p, list): cur_attach = p[-1]