From 23a6ea471625da6a33ebf71b3bef5993d03a81dd Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Fri, 1 Mar 2019 11:13:09 +0100 Subject: [PATCH] Wrap text/html and text/enriched in templates --- mbox2web | 12 ++++++++++-- templates/body_message_rfc822.html | 18 ++++++++++++++++++ templates/body_multipart_digest.html | 10 ++++++++++ templates/body_multipart_mixed.html | 10 ++++++++++ templates/body_text_enriched.html | 8 ++++++++ templates/body_text_html.html | 8 ++++++++ templates/body_text_plain.html | 10 ++++++++++ templates/message.html | 21 +++++++++++++++++++++ templates/message2.html | 16 ++++++++++++++++ 9 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 templates/body_message_rfc822.html create mode 100644 templates/body_multipart_digest.html create mode 100644 templates/body_multipart_mixed.html create mode 100644 templates/body_text_enriched.html create mode 100644 templates/body_text_html.html create mode 100644 templates/body_text_plain.html create mode 100644 templates/message.html create mode 100644 templates/message2.html diff --git a/mbox2web b/mbox2web index 2ae0e81..75cd54e 100755 --- a/mbox2web +++ b/mbox2web @@ -87,10 +87,18 @@ def render_body(msg): elif content_type == "text/html": htmlpart = HTMLPart() htmlpart.feed(msg.get_payload()) - bodyhtml = htmlpart.as_string() + bodytmpl = jenv.get_template("body_text_html.html") + context = { + "body": jinja2.Markup(htmlpart.as_string()) + } + bodyhtml = bodytmpl.render(context) elif content_type == "text/enriched": tepart = TextEnrichedPart(msg.get_payload()) - bodyhtml = tepart.as_string() + bodytmpl = jenv.get_template("body_text_enriched.html") + context = { + "body": jinja2.Markup(tepart.as_string()) + } + bodyhtml = bodytmpl.render(context) elif content_type == "message/partial": # Default header for get_param is Content-Type whole_msg_id = msg.get_param("id") diff --git a/templates/body_message_rfc822.html b/templates/body_message_rfc822.html new file mode 100644 index 0000000..4abc835 --- /dev/null +++ b/templates/body_message_rfc822.html @@ -0,0 +1,18 @@ +
+
+ message/rfc822 +
+
+ + + + + +
Message-Id {{message_id}}
Subject {{subject}}
From {{from}}
Date {{date}}
+ + {% for p in parts %} + {{p}} + {% endfor %} + +
+
diff --git a/templates/body_multipart_digest.html b/templates/body_multipart_digest.html new file mode 100644 index 0000000..ebcb60f --- /dev/null +++ b/templates/body_multipart_digest.html @@ -0,0 +1,10 @@ +
+
+ multipart/digest +
+
+ {% for part in parts %} + {{part}} + {% endfor %} +
+
diff --git a/templates/body_multipart_mixed.html b/templates/body_multipart_mixed.html new file mode 100644 index 0000000..221ca00 --- /dev/null +++ b/templates/body_multipart_mixed.html @@ -0,0 +1,10 @@ +
+
+ multipart/mixed +
+
+ {% for part in parts %} + {{part}} + {% endfor %} +
+
diff --git a/templates/body_text_enriched.html b/templates/body_text_enriched.html new file mode 100644 index 0000000..30ea197 --- /dev/null +++ b/templates/body_text_enriched.html @@ -0,0 +1,8 @@ +
+
+ text/enriched +
+
+ {{body}} +
+
diff --git a/templates/body_text_html.html b/templates/body_text_html.html new file mode 100644 index 0000000..a42fbb4 --- /dev/null +++ b/templates/body_text_html.html @@ -0,0 +1,8 @@ +
+
+ text/html +
+
+ {{body}} +
+
diff --git a/templates/body_text_plain.html b/templates/body_text_plain.html new file mode 100644 index 0000000..e86e5c4 --- /dev/null +++ b/templates/body_text_plain.html @@ -0,0 +1,10 @@ +
+
+ text/plain +
+
+
+{{body}}
+
+
+
diff --git a/templates/message.html b/templates/message.html new file mode 100644 index 0000000..aa3ab6d --- /dev/null +++ b/templates/message.html @@ -0,0 +1,21 @@ + + + + + + {{list}}: {{subject}} + + + + +

{{subject}}

+ + + + +
Message-Id {{message_id}}
From {{from}}
Date {{date}}
+ + {{bodyhtml}} + + + diff --git a/templates/message2.html b/templates/message2.html new file mode 100644 index 0000000..4c89f26 --- /dev/null +++ b/templates/message2.html @@ -0,0 +1,16 @@ +
+
+ message +
+
+ + + + + +
Message-Id {{message_id}}
Subject {{subject}}
From {{from}}
Date {{date}}
+ + {{bodyhtml}} + +
+