Skip to content

Commit

Permalink
Pushing email stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
frikky committed Mar 25, 2024
1 parent 881a605 commit c3b3585
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
2 changes: 1 addition & 1 deletion email/1.2.0/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions email/1.2.0/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
19 changes: 19 additions & 0 deletions email/1.3.0/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 18 additions & 1 deletion email/1.3.0/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 11 additions & 1 deletion shuffle-tools/1.2.0/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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=""):
Expand Down

0 comments on commit c3b3585

Please sign in to comment.