Allow cid's in multipart/mixed

This commit is contained in:
Peter J. Holzer 2019-05-12 22:06:51 +02:00
parent c84c517f62
commit f8f64d3506
1 changed files with 17 additions and 1 deletions

View File

@ -131,9 +131,25 @@ def render_body(msg, extra=None):
if type(parts) == str: if type(parts) == str:
# mislabelled, assume text/plain # mislabelled, assume text/plain
return render_text_plain(msg) 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 = [] partshtml = []
for part in msg.get_payload(): 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") bodytmpl = jenv.get_template("body_multipart_mixed.html")
context = { context = {
"parts": partshtml "parts": partshtml