diff --git a/email/1.2.0/requirements.txt b/email/1.2.0/requirements.txt index 926027e8..7f8dacf7 100644 --- a/email/1.2.0/requirements.txt +++ b/email/1.2.0/requirements.txt @@ -1,6 +1,6 @@ requests==2.25.1 glom==20.11.0 -eml-parser==1.17.0 +eml-parser==1.17.5 msg-parser==1.2.0 mail-parser==3.15.0 extract-msg==0.30.9 diff --git a/email/1.2.0/src/app.py b/email/1.2.0/src/app.py index 4a27c9b2..23993bf8 100644 --- a/email/1.2.0/src/app.py +++ b/email/1.2.0/src/app.py @@ -391,10 +391,9 @@ def parse_email_file(self, file_id, file_extension): "reason": "Couldn't get file with ID %s" % file_id } - print("File: %s" % file_path) if file_extension.lower() == 'eml': print('working with .eml file') - ep = eml_parser.EmlParser(include_attachment_data=True, include_raw_body=True, parse_attachment=True) + ep = eml_parser.EmlParser(include_attachment_data=True, include_raw_body=True, parse_attachments=True) try: parsed_eml = ep.decode_email_bytes(file_path['data']) if str(parsed_eml["header"]["date"]) == "1970-01-01 00:00:00+00:00": diff --git a/email/1.3.0/api.yaml b/email/1.3.0/api.yaml index 40998adf..017222d7 100644 --- a/email/1.3.0/api.yaml +++ b/email/1.3.0/api.yaml @@ -233,6 +233,25 @@ actions: required: false schema: type: bool + - name: parse_eml + description: Takes an eml string and parses it to JSON + parameters: + - name: filedata + description: The EML string data + required: true + multiline: true + example: 'EML string data' + schema: + type: string + - name: extract_attachments + description: Whether to extract the attachments straight into files + required: true + options: + - true + - false + example: 'true' + schema: + type: string - name: parse_email_file description: Takes a file from shuffle and analyzes it if it's a valid .eml or .msg parameters: diff --git a/email/1.3.0/src/app.py b/email/1.3.0/src/app.py index 62b3a26d..f80a17c0 100644 --- a/email/1.3.0/src/app.py +++ b/email/1.3.0/src/app.py @@ -384,8 +384,25 @@ def merge(d1, d2): "messages": json.dumps(emails, default=default), } + def parse_eml(self, filedata, extract_attachments=False): + parsedfile = { + "success": True, + "filename": "email.eml", + "data": filedata, + } + + return self.parse_email_file(parsedfile, extract_attachments) + def parse_email_file(self, file_id, extract_attachments=False): - file_path = self.get_file(file_id) + file_path = { + "success": False, + } + + if isinstance(file_id, dict) and "data" in file_id: + file_path = file_id + else: + file_path = self.get_file(file_id) + if file_path["success"] == False: return { "success": False, diff --git a/shuffle-tools/1.2.0/src/app.py b/shuffle-tools/1.2.0/src/app.py index bc4e10a5..c68c006d 100644 --- a/shuffle-tools/1.2.0/src/app.py +++ b/shuffle-tools/1.2.0/src/app.py @@ -981,7 +981,16 @@ def list_file_category_ids(self, file_category): def get_file_value(self, filedata): filedata = self.get_file(filedata) if filedata is None: - return "File is empty?" + return { + "success": False, + "reason": "File not found", + } + + if "data" not in filedata: + return { + "success": False, + "reason": "File content not found. File might be empty or not exist", + } try: return filedata["data"].decode() @@ -998,6 +1007,7 @@ def get_file_value(self, filedata): return { "success": False, "reason": "Got the file, but the encoding can't be printed", + "size": len(filedata["data"]), } def download_remote_file(self, url, custom_filename=""):