Skip to content

Commit 601680b

Browse files
committed
Added imap id, attachment lists etc to all emails from imap
1 parent 74c19c9 commit 601680b

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

email/1.2.0/api.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ actions:
109109
example: "true"
110110
required: false
111111
options:
112-
- true
113112
- false
113+
- true
114114
schema:
115115
type: string
116116
returns:

email/1.2.0/src/app.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def merge(d1, d2):
278278
if len(id_list) == 0:
279279
return {
280280
"success": True,
281-
"emails": [],
281+
"messages": [],
282282
}
283283

284284
try:
@@ -309,8 +309,12 @@ def merge(d1, d2):
309309
else:
310310
output_dict = parsed_eml
311311

312+
output_dict["imap_id"] = id_list[i]
313+
output_dict["attachment"] = []
314+
output_dict["attachment_uids"] = []
315+
312316
# Add message-id as top returned field
313-
output_dict["message-id"] = parsed_eml["header"]["header"][
317+
output_dict["message_id"] = parsed_eml["header"]["header"][
314318
"message-id"
315319
][0]
316320

@@ -320,15 +324,22 @@ def merge(d1, d2):
320324
output_dict["email_uid"] = email_id[0]
321325

322326
if upload_attachments_shuffle:
323-
atts_up = [
324-
{
325-
"filename": x["filename"],
326-
"data": base64.b64decode(x["raw"]),
327-
}
328-
for x in parsed_eml["attachment"]
329-
]
330-
atts_ids = self.set_files(atts_up)
331-
output_dict["attachments_uids"] = atts_ids
327+
#self.logger.info(f"EML: {parsed_eml}")
328+
try:
329+
atts_up = [
330+
{
331+
"filename": x["filename"],
332+
"data": base64.b64decode(x["raw"]),
333+
}
334+
for x in parsed_eml["attachment"]
335+
]
336+
337+
atts_ids = self.set_files(atts_up)
338+
output_dict["attachments_uids"] = atts_ids
339+
340+
except Exception as e:
341+
self.logger.info(f"Major issue with EML attachment - are there attachments: {e}")
342+
332343

333344
emails.append(output_dict)
334345
except Exception as err:
@@ -340,14 +351,14 @@ def merge(d1, d2):
340351
try:
341352
to_return = {
342353
"success": True,
343-
"reason": json.loads(json.dumps(emails, default=default)),
354+
"messages": json.loads(json.dumps(emails, default=default)),
344355
}
345356
self.logger.info(f"Emails: {to_return}")
346357
return to_return
347358
except:
348359
return {
349360
"success": True,
350-
"reason": json.dumps(emails, default=default),
361+
"messages": json.dumps(emails, default=default),
351362
}
352363

353364
def parse_email_file(self, file_id, file_extension):

0 commit comments

Comments
 (0)