Handle multipart/alternative and application/x-unknown-content-type-scpfile

Strange combination, but the first message with multipart/alternative
also contained a .scp file and not as an attachment.

The template for multipart/alternative allows switching between the
alternatives.
This commit is contained in:
Peter J. Holzer 2019-03-02 23:33:39 +01:00
parent 090fd79c79
commit 77d2b87b1e
3 changed files with 54 additions and 0 deletions

View File

@ -211,6 +211,26 @@ def render_body(msg):
}
bodyhtml = bodytmpl.render(context)
elif content_type == "multipart/alternative":
partshtml = []
partstypes = []
for part in msg.get_payload():
partstypes.append(part.get_content_type())
partshtml.append(render_body(part))
bodytmpl = jenv.get_template("body_multipart_alternative.html")
context = {
"types": partstypes,
"parts": partshtml,
}
bodyhtml = bodytmpl.render(context)
elif content_type == "application/x-unknown-content-type-scpfile":
bodytmpl = jenv.get_template("body_application_x-unknown-content-type-scpfile.html")
context = {
"body": msg.get_payload(decode=True).decode(msg.get_charset() or "iso-8859-1")
}
bodyhtml = bodytmpl.render(context)
else:
raise RuntimeError("Content-type " + content_type + " not implemented yet")

View File

@ -0,0 +1,10 @@
<div class="partouter">
<div class="partheader">
application/x-unknown-content-type-scpfile
</div>
<div class="partinner">
<pre>
{{body}}
</pre>
</div>
</div>

View File

@ -0,0 +1,24 @@
<div class="partouter">
<div class="partheader">
multipart/alternative
</div>
<div class="partinner">
{% for type in types %}
<input id="sp{{prefix}}_{{loop.index}}" type="radio" name="g{{prefix}}">
<label for="sp{{prefix}}_{{loop.index}}">{{type}}</label>
<style>
#p{{prefix}}_{{loop.index}} {
display: none;
}
input#sp{{prefix}}_{{loop.index}}:checked ~ #p{{prefix}}_{{loop.index}} {
display: block;
}
</style>
{% endfor %}
{% for part in parts %}
<div id="p{{prefix}}_{{loop.index}}">
{{part}}
</div>
{% endfor %}
</div>
</div>