Wrap text/html and text/enriched in templates

This commit is contained in:
Peter J. Holzer 2019-03-01 11:13:09 +01:00
parent d1dc1db853
commit 23a6ea4716
9 changed files with 111 additions and 2 deletions

View File

@ -87,10 +87,18 @@ def render_body(msg):
elif content_type == "text/html": elif content_type == "text/html":
htmlpart = HTMLPart() htmlpart = HTMLPart()
htmlpart.feed(msg.get_payload()) 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": elif content_type == "text/enriched":
tepart = TextEnrichedPart(msg.get_payload()) 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": elif content_type == "message/partial":
# 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")

View File

@ -0,0 +1,18 @@
<div class="partouter">
<div class="partheader">
message/rfc822
</div>
<div class="partinner">
<table>
<tr> <th>Message-Id </th> <td>{{message_id}} </td> </tr>
<tr> <th>Subject </th> <td>{{subject}} </td> </tr>
<tr> <th>From </th> <td>{{from}} </td> </tr>
<tr> <th>Date </th> <td>{{date}} </td> </tr>
</table>
{% for p in parts %}
{{p}}
{% endfor %}
</div>
</div>

View File

@ -0,0 +1,10 @@
<div class="partouter">
<div class="partheader">
multipart/digest
</div>
<div class="partinner">
{% for part in parts %}
{{part}}
{% endfor %}
</div>
</div>

View File

@ -0,0 +1,10 @@
<div class="partouter">
<div class="partheader">
multipart/mixed
</div>
<div class="partinner">
{% for part in parts %}
{{part}}
{% endfor %}
</div>
</div>

View File

@ -0,0 +1,8 @@
<div class="partouter">
<div class="partheader">
text/enriched
</div>
<div class="partinner">
{{body}}
</div>
</div>

View File

@ -0,0 +1,8 @@
<div class="partouter">
<div class="partheader">
text/html
</div>
<div class="partinner">
{{body}}
</div>
</div>

View File

@ -0,0 +1,10 @@
<div class="partouter">
<div class="partheader">
text/plain
</div>
<div class="partinner">
<pre>
{{body}}
</pre>
</div>
</div>

21
templates/message.html Normal file
View File

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>
{{list}}: {{subject}}
</title>
<link rel="stylesheet" href="../../style/debug.css">
</head>
<body>
<h1>{{subject}}</h1>
<table>
<tr> <th>Message-Id </th> <td>{{message_id}} </td> </tr>
<tr> <th>From </th> <td>{{from}} </td> </tr>
<tr> <th>Date </th> <td>{{date}} </td> </tr>
</table>
{{bodyhtml}}
</body>
</html>

16
templates/message2.html Normal file
View File

@ -0,0 +1,16 @@
<div class="partouter">
<div class="partheader">
message
</div>
<div class="partinner">
<table>
<tr> <th>Message-Id </th> <td>{{message_id}} </td> </tr>
<tr> <th>Subject </th> <td class="subject">{{subject}}</td> </tr>
<tr> <th>From </th> <td>{{from}} </td> </tr>
<tr> <th>Date </th> <td>{{date}} </td> </tr>
</table>
{{bodyhtml}}
</div>
</div>