Skip to content

Commit c3b3585

Browse files
committed
Pushing email stuff
1 parent 881a605 commit c3b3585

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed

email/1.2.0/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
requests==2.25.1
22
glom==20.11.0
3-
eml-parser==1.17.0
3+
eml-parser==1.17.5
44
msg-parser==1.2.0
55
mail-parser==3.15.0
66
extract-msg==0.30.9

email/1.2.0/src/app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,9 @@ def parse_email_file(self, file_id, file_extension):
391391
"reason": "Couldn't get file with ID %s" % file_id
392392
}
393393

394-
print("File: %s" % file_path)
395394
if file_extension.lower() == 'eml':
396395
print('working with .eml file')
397-
ep = eml_parser.EmlParser(include_attachment_data=True, include_raw_body=True, parse_attachment=True)
396+
ep = eml_parser.EmlParser(include_attachment_data=True, include_raw_body=True, parse_attachments=True)
398397
try:
399398
parsed_eml = ep.decode_email_bytes(file_path['data'])
400399
if str(parsed_eml["header"]["date"]) == "1970-01-01 00:00:00+00:00":

email/1.3.0/api.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,25 @@ actions:
233233
required: false
234234
schema:
235235
type: bool
236+
- name: parse_eml
237+
description: Takes an eml string and parses it to JSON
238+
parameters:
239+
- name: filedata
240+
description: The EML string data
241+
required: true
242+
multiline: true
243+
example: 'EML string data'
244+
schema:
245+
type: string
246+
- name: extract_attachments
247+
description: Whether to extract the attachments straight into files
248+
required: true
249+
options:
250+
- true
251+
- false
252+
example: 'true'
253+
schema:
254+
type: string
236255
- name: parse_email_file
237256
description: Takes a file from shuffle and analyzes it if it's a valid .eml or .msg
238257
parameters:

email/1.3.0/src/app.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,25 @@ def merge(d1, d2):
384384
"messages": json.dumps(emails, default=default),
385385
}
386386

387+
def parse_eml(self, filedata, extract_attachments=False):
388+
parsedfile = {
389+
"success": True,
390+
"filename": "email.eml",
391+
"data": filedata,
392+
}
393+
394+
return self.parse_email_file(parsedfile, extract_attachments)
395+
387396
def parse_email_file(self, file_id, extract_attachments=False):
388-
file_path = self.get_file(file_id)
397+
file_path = {
398+
"success": False,
399+
}
400+
401+
if isinstance(file_id, dict) and "data" in file_id:
402+
file_path = file_id
403+
else:
404+
file_path = self.get_file(file_id)
405+
389406
if file_path["success"] == False:
390407
return {
391408
"success": False,

shuffle-tools/1.2.0/src/app.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,16 @@ def list_file_category_ids(self, file_category):
981981
def get_file_value(self, filedata):
982982
filedata = self.get_file(filedata)
983983
if filedata is None:
984-
return "File is empty?"
984+
return {
985+
"success": False,
986+
"reason": "File not found",
987+
}
988+
989+
if "data" not in filedata:
990+
return {
991+
"success": False,
992+
"reason": "File content not found. File might be empty or not exist",
993+
}
985994

986995
try:
987996
return filedata["data"].decode()
@@ -998,6 +1007,7 @@ def get_file_value(self, filedata):
9981007
return {
9991008
"success": False,
10001009
"reason": "Got the file, but the encoding can't be printed",
1010+
"size": len(filedata["data"]),
10011011
}
10021012

10031013
def download_remote_file(self, url, custom_filename=""):

0 commit comments

Comments
 (0)