From 00ad5f864eab80a4b62f3c9c11ed81fcf9bab1d0 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Mon, 20 May 2019 23:25:49 +0200 Subject: [PATCH] Fix charset handling for text/html parts --- mbox2web | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mbox2web b/mbox2web index ac973a1..6f7d273 100755 --- a/mbox2web +++ b/mbox2web @@ -207,7 +207,10 @@ def render_body(msg, extra=None): return bodytmpl.render(context) def render_text_html(msg, extra=None): htmlpart = HTMLPart(extra) - htmlpart.feed(msg.get_payload(decode=True).decode(msg.get_charset() or "iso-8859-1")) + ct_params = dict(msg.get_params()) + charset = ct_params.get("charset", "iso-8859-1") + raw_text = msg.get_payload(decode=True).decode(charset, errors="replace") + htmlpart.feed(raw_text) bodytmpl = jenv.get_template("body_text_html.html") context = { "body": jinja2.Markup(htmlpart.as_string())