Merge pull request #42 from TheMysteriousX/master

multipart messages can be nested within each other
pull/44/head
Raphaël Vinot 2020-06-07 20:44:00 +02:00 committed by GitHub
commit 7ab2b432df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -95,7 +95,12 @@ class Mail2MISP():
def _find_attached_forward(self):
forwarded_emails = []
for attachment in self.original_mail.iter_attachments():
attachment_content = attachment.get_content()
try:
attachment_content = attachment.get_content()
except KeyError:
# Attachment type has no handler
continue
# Search for email forwarded as attachment
# I could have more than one, attaching everything.
if isinstance(attachment_content, message.EmailMessage):

View File

@ -82,6 +82,14 @@ class TestMailToMISP(unittest.TestCase):
self.assertEqual(self.mail2misp.misp_event.analysis, '0')
self.mail2misp.add_event()
def test_nested_mime(self):
config = importlib.import_module('tests.config_forward')
self.mail2misp = Mail2MISP('', '', '', config=config, offline=True)
with open('tests/mails/test_nested_mime.eml', 'rb') as f:
self.mail2misp.load_email(BytesIO(f.read()))
self.mail2misp.process_email_body()
self.assertEqual(self.mail2misp.clean_email_body, 'example.org\r\nwww.example.org\r\n')
def test_attached_emails(self):
config = importlib.import_module('tests.config_carrier')
self.mail2misp = Mail2MISP('', '', '', config=config, offline=True)
@ -89,5 +97,6 @@ class TestMailToMISP(unittest.TestCase):
attached_emails = self.mail2misp.get_attached_emails(BytesIO(f.read()))
self.assertEqual(len(attached_emails), 7)
if __name__ == '__main__':
unittest.main()