Handle application/octet-stream
This commit is contained in:
parent
fbce052c69
commit
02368a57f8
18
mbox2web
18
mbox2web
|
@ -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")
|
||||
|
||||
|
|
Loading…
Reference in New Issue