diff --git a/mbox2web b/mbox2web index 7b7d7c1..692a160 100755 --- a/mbox2web +++ b/mbox2web @@ -51,7 +51,7 @@ def render_message(msg): return jinja2.Markup(msghtml) -def save_part(msg): +def save_part(msg, disposition): content_type = msg.get_content_type() extension = { "application/octet-stream": ".bin", @@ -59,6 +59,7 @@ def save_part(msg): "text/x-vcard": ".vcf", "text/plain": ".txt", "application/x-gzip": ".gz", # more likely tar.gz, but we can't know without looking into it which we ain't + "image/gif": ".gif", }[content_type] name = msg.get_param("name") or "(data)" @@ -69,7 +70,8 @@ def save_part(msg): 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") + template_name = disposition + "_" + content_type.replace("/", "_") + ".html" + bodytmpl = jenv.get_template(template_name) context = { "name": name, "url": "../../parts/" + filename, @@ -88,7 +90,7 @@ def render_body(msg): # We probably should clean up html. Alternatively we could just store # all of them application/octet-stream, which browsers should download # and not try to display. - bodyhtml = save_part(msg) + bodyhtml = save_part(msg, content_disposition) elif content_type == "text/plain": bodytmpl = jenv.get_template("body_text_plain.html") @@ -165,7 +167,7 @@ def render_body(msg): html.escape(whole_msg_id)) elif content_type == "application/octet-stream": - bodyhtml = save_part(msg) + bodyhtml = save_part(msg, "attachment") elif content_type == "multipart/signed": content, signature = msg.get_payload() @@ -242,7 +244,7 @@ def render_body(msg): bodyhtml = bodytmpl.render(context) elif content_type == "application/x-gzip": - bodyhtml = save_part(msg) + bodyhtml = save_part(msg, "attachment") elif content_type == "message/news": partshtml = [] @@ -254,6 +256,10 @@ def render_body(msg): "parts": partshtml, } bodyhtml = bodytmpl.render(context) + + elif content_type == "image/gif": + bodyhtml = save_part(msg, "inline") + else: raise RuntimeError("Content-type " + content_type + " not implemented yet") @@ -286,6 +292,7 @@ class HTMLPart(html.parser.HTMLParser): "h2", "a", "wbr", "hr", "pre", "img", "font", "i", "br", "table", "tr", "th", "td", "b", "select", "option", "input", "sup", "address", "center", "p", "h1", "dl", "h3", "ul", "li", "ol", "u", "blockquote", + "h4", ] hide_tags = [ "title" ] ignore_tags = [ "html", "head", "body", "marquee", "meta", "form", ] diff --git a/templates/attachment_application_octet-stream.html b/templates/attachment_application_octet-stream.html new file mode 100644 index 0000000..0e1d0b6 --- /dev/null +++ b/templates/attachment_application_octet-stream.html @@ -0,0 +1,9 @@ +