From f2a7708a3c1d49bab40cf19ec27da19554ea9ae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leonard?= Date: Thu, 4 May 2023 15:46:39 +0000 Subject: [PATCH] use path in multipart attachment name --- analyzers/EmlParser/parse.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/analyzers/EmlParser/parse.py b/analyzers/EmlParser/parse.py index 117a8191d..59968115c 100755 --- a/analyzers/EmlParser/parse.py +++ b/analyzers/EmlParser/parse.py @@ -254,7 +254,13 @@ def parseEml(filepath, job_directory, wkhtmltoimage, sanitized_rendering): for a in decoded_email.get("attachment"): a["mime"] = magic.from_buffer(binascii.a2b_base64(a.get("raw"))) if isinstance(a.get("raw"), bytes): - filepath = os.path.join(job_directory, "output", a.get("filename", "")) + path, filename = os.path.split(a.get("filename", "")) + if path != "": + os.umask(0) + os.makedirs( + f"{job_directory}/output/{path}", exist_ok=True, mode=0o777 + ) + filepath = os.path.join(job_directory, "output", path, filename) with open(filepath, "wb") as f: f.write(base64.b64decode(a["raw"])) f.close()