From f8f64d3506d382ed7a3d1e9a49f96fec57da6317 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sun, 12 May 2019 22:06:51 +0200 Subject: [PATCH] Allow cid's in multipart/mixed --- mbox2web | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/mbox2web b/mbox2web index e95fabf..3f7c130 100755 --- a/mbox2web +++ b/mbox2web @@ -131,9 +131,25 @@ def render_body(msg, extra=None): if type(parts) == str: # mislabelled, assume text/plain return render_text_plain(msg) + # First, scan for parts with a content-id. A multipart/mixed shouldn't + # have them, but I've seen them in the wild and it should be harmless + # to support at least images. We don't want all content types, though, + # because save_part doesn't support nested parts and I don't want to + # fully implement what is really just a workaround for buggy software. + for i, part in enumerate(msg.get_payload()): + content_id = part.get("Content-Id") + content_type = part.get_content_type() + if content_id and content_type.startswith("image/"): + if extra is None: + extra = {} + extra[content_id] = { + "i": i, + "part": part, + "url": save_part(part, "_url"), + } partshtml = [] for part in msg.get_payload(): - partshtml.append(render_body(part)) + partshtml.append(render_body(part, extra)) bodytmpl = jenv.get_template("body_multipart_mixed.html") context = { "parts": partshtml