Fix charset handling for text/html parts

This commit is contained in:
Peter J. Holzer 2019-05-20 23:25:49 +02:00
parent bdb5842d75
commit 00ad5f864e
1 changed files with 4 additions and 1 deletions

View File

@ -207,7 +207,10 @@ def render_body(msg, extra=None):
return bodytmpl.render(context) return bodytmpl.render(context)
def render_text_html(msg, extra=None): def render_text_html(msg, extra=None):
htmlpart = HTMLPart(extra) 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") bodytmpl = jenv.get_template("body_text_html.html")
context = { context = {
"body": jinja2.Markup(htmlpart.as_string()) "body": jinja2.Markup(htmlpart.as_string())