From 7fe400e99a40c7f20b2a3cbbbbd3133010d57747 Mon Sep 17 00:00:00 2001 From: jdepalma <33504952+jdepalma@users.noreply.github.com> Date: Tue, 3 Dec 2019 15:02:48 -0500 Subject: [PATCH] Update Ews2Case.py Changes to work with Exchange 2010 to address https://github.com/TheHive-Project/Synapse/issues/4 Kudos to @ninSmith for the majority of it. I've only added the import bs4 --- workflows/Ews2Case.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/workflows/Ews2Case.py b/workflows/Ews2Case.py index d4aced3..c0b5896 100644 --- a/workflows/Ews2Case.py +++ b/workflows/Ews2Case.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf8 -*- +from bs4 import BeautifulSoup import os, sys import logging current_dir = os.path.dirname(os.path.abspath(__file__)) @@ -147,17 +148,22 @@ def getEmailBody(email): 'Subject: ' + str(email.subject) + '\n\n') body = email.text_body - - #alternate way to get the body - #soup = BeautifulSoup(email.body, 'html.parser') - #try: - # #html email - # body = soup.body.text - #except AttributeError: - # #non html email - # body = soup.text - - return ('```\n' + replyToInfo + body + '\n```') + #email.text_body should get the body either it is + #html or raw text + #unfortunately it is only supported with Exchange 2013 + #so we need to get the body from another way + + if body is None: + #alternate way to get the body + soup = BeautifulSoup(email.body, 'html.parser') + try: + #html email + body = soup.body.text + except AttributeError: + #non html email + body = soup.text + + return ('```\n' + replyToInfo + str(body) + '\n```') if __name__ == '__main__': connectEws()