Fixed return values of all the new render functions

Oops. I should really check the output of the script, not just whether
it crashes in the expected place.
This commit is contained in:
Peter J. Holzer 2019-03-17 22:30:27 +01:00
parent 45848a73ae
commit 8acf092559
1 changed files with 16 additions and 16 deletions

View File

@ -88,7 +88,7 @@ def render_body(msg):
context = { context = {
"body": msg.get_payload(decode=True).decode(msg.get_charset() or "iso-8859-1") "body": msg.get_payload(decode=True).decode(msg.get_charset() or "iso-8859-1")
} }
bodyhtml = bodytmpl.render(context) return bodytmpl.render(context)
def render_multipart_mixed(msg): def render_multipart_mixed(msg):
parts = msg.get_payload() parts = msg.get_payload()
if type(parts) == str: if type(parts) == str:
@ -101,7 +101,7 @@ def render_body(msg):
context = { context = {
"parts": partshtml "parts": partshtml
} }
bodyhtml = bodytmpl.render(context) return bodytmpl.render(context)
def render_multipart_digest(msg): def render_multipart_digest(msg):
partshtml = [] partshtml = []
for part in msg.get_payload(): for part in msg.get_payload():
@ -110,7 +110,7 @@ def render_body(msg):
context = { context = {
"parts": partshtml "parts": partshtml
} }
bodyhtml = bodytmpl.render(context) return bodytmpl.render(context)
def render_message_rfc822(msg): def render_message_rfc822(msg):
partshtml = [] partshtml = []
for part in msg.get_payload(): for part in msg.get_payload():
@ -119,7 +119,7 @@ def render_body(msg):
context = { context = {
"parts": partshtml "parts": partshtml
} }
bodyhtml = bodytmpl.render(context) return bodytmpl.render(context)
def render_text_html(msg): def render_text_html(msg):
htmlpart = HTMLPart() htmlpart = HTMLPart()
htmlpart.feed(msg.get_payload(decode=True).decode(msg.get_charset() or "iso-8859-1")) htmlpart.feed(msg.get_payload(decode=True).decode(msg.get_charset() or "iso-8859-1"))
@ -127,7 +127,7 @@ def render_body(msg):
context = { context = {
"body": jinja2.Markup(htmlpart.as_string()) "body": jinja2.Markup(htmlpart.as_string())
} }
bodyhtml = bodytmpl.render(context) return bodytmpl.render(context)
def render_text_enriched(msg): def render_text_enriched(msg):
payload = msg.get_payload(decode=True).decode(msg.get_charset() or "iso-8859-1") payload = msg.get_payload(decode=True).decode(msg.get_charset() or "iso-8859-1")
tepart = TextEnrichedPart(payload) tepart = TextEnrichedPart(payload)
@ -135,7 +135,7 @@ def render_body(msg):
context = { context = {
"body": jinja2.Markup(tepart.as_string()) "body": jinja2.Markup(tepart.as_string())
} }
bodyhtml = bodytmpl.render(context) return bodytmpl.render(context)
def render_message_partial(msg): def render_message_partial(msg):
# Default header for get_param is Content-Type # Default header for get_param is Content-Type
whole_msg_id = msg.get_param("id") whole_msg_id = msg.get_param("id")
@ -156,14 +156,14 @@ def render_body(msg):
whole_msg_embedded_id = whole_msg_id whole_msg_embedded_id = whole_msg_id
archive(whole_msg) archive(whole_msg)
del partial_message_cache[whole_msg_id] del partial_message_cache[whole_msg_id]
bodyhtml = "<p>This is part %d of %d of <a href='../%s/'>%s</a></p>" % ( return "<p>This is part %d of %d of <a href='../%s/'>%s</a></p>" % (
int(msg.get_param("number")), int(msg.get_param("number")),
int(msg.get_param("total")), int(msg.get_param("total")),
encode_message_id(whole_msg_id), encode_message_id(whole_msg_id),
html.escape(whole_msg_id)) html.escape(whole_msg_id))
def render_application_octet_stream(msg): def render_application_octet_stream(msg):
bodyhtml = save_part(msg, "attachment") return save_part(msg, "attachment")
def render_multipart_signed(msg): def render_multipart_signed(msg):
content, signature = msg.get_payload() content, signature = msg.get_payload()
@ -187,7 +187,7 @@ def render_body(msg):
"gpgresult": gpgresult, "gpgresult": gpgresult,
"gpgstatus": gpgstatus, "gpgstatus": gpgstatus,
} }
bodyhtml = bodytmpl.render(context) return bodytmpl.render(context)
def render_application_pgp(msg): def render_application_pgp(msg):
with tempfile.NamedTemporaryFile(buffering=0) as content_fh: with tempfile.NamedTemporaryFile(buffering=0) as content_fh:
@ -210,7 +210,7 @@ def render_body(msg):
"gpgresult": gpgresult, "gpgresult": gpgresult,
"gpgstatus": gpgstatus, "gpgstatus": gpgstatus,
} }
bodyhtml = bodytmpl.render(context) return bodytmpl.render(context)
def render_multipart_alternative(msg): def render_multipart_alternative(msg):
partshtml = [] partshtml = []
@ -223,24 +223,24 @@ def render_body(msg):
"types": partstypes, "types": partstypes,
"parts": partshtml, "parts": partshtml,
} }
bodyhtml = bodytmpl.render(context) return bodytmpl.render(context)
def render_application_x_unknown_content_type_scpfile(msg): def render_application_x_unknown_content_type_scpfile(msg):
bodytmpl = jenv.get_template("body_application_x-unknown-content-type-scpfile.html") bodytmpl = jenv.get_template("body_application_x-unknown-content-type-scpfile.html")
context = { context = {
"body": msg.get_payload(decode=True).decode(msg.get_charset() or "iso-8859-1") "body": msg.get_payload(decode=True).decode(msg.get_charset() or "iso-8859-1")
} }
bodyhtml = bodytmpl.render(context) return bodytmpl.render(context)
def render_application_pgp_signature(msg): def render_application_pgp_signature(msg):
# A PGP signature outside of a multipart/signed - useless # A PGP signature outside of a multipart/signed - useless
bodytmpl = jenv.get_template("body_application_pgp-signature.html") bodytmpl = jenv.get_template("body_application_pgp-signature.html")
context = { context = {
} }
bodyhtml = bodytmpl.render(context) return bodytmpl.render(context)
def render_application_x_gzip(msg): def render_application_x_gzip(msg):
bodyhtml = save_part(msg, "attachment") return save_part(msg, "attachment")
def render_message_news(msg): def render_message_news(msg):
partshtml = [] partshtml = []
@ -251,10 +251,10 @@ def render_body(msg):
"msg": msg, "msg": msg,
"parts": partshtml, "parts": partshtml,
} }
bodyhtml = bodytmpl.render(context) return bodytmpl.render(context)
def render_image_gif(msg): def render_image_gif(msg):
bodyhtml = save_part(msg, "inline") return save_part(msg, "inline")
renderers = { renderers = {
"text/plain": render_text_plain, "text/plain": render_text_plain,