Handle application/octet-stream

This commit is contained in:
Peter J. Holzer 2019-03-01 11:58:22 +01:00
parent fbce052c69
commit 02368a57f8
1 changed files with 18 additions and 0 deletions

View File

@ -1,6 +1,7 @@
#!/usr/bin/python3
import email.parser
import hashlib
import html
import html.parser
import mailbox
@ -125,6 +126,23 @@ def render_body(msg):
encode_message_id(whole_msg_id),
html.escape(whole_msg_id))
elif content_type == "application/octet-stream":
name = msg.get_param("name") or "(data)"
m = hashlib.sha256()
payload = msg.get_payload(decode=True)
m.update(payload)
filename = m.hexdigest() + ".bin"
os.makedirs("parts", exist_ok=True)
with open("parts/" + filename, "wb") as fh:
fh.write(payload)
bodytmpl = jenv.get_template("body_application_octet_stream.html")
context = {
"name": name,
"url": "../../parts/" + filename,
}
bodyhtml = bodytmpl.render(context)
else:
raise RuntimeError("Content-type " + content_type + " not implemented yet")