Handle application/pgp
This commit is contained in:
parent
9f44375354
commit
a737ce1760
25
mbox2web
25
mbox2web
|
@ -176,7 +176,7 @@ def render_body(msg):
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
universal_newlines=True)
|
universal_newlines=True)
|
||||||
gpgresult = r.stderr
|
gpgresult = r.stderr
|
||||||
# Analyze gpgresult or just use r,returncode?
|
# XXX - Analyze gpgresult or just use r,returncode?
|
||||||
gpgstatus = "dubious"
|
gpgstatus = "dubious"
|
||||||
|
|
||||||
contenthtml = render_message(content)
|
contenthtml = render_message(content)
|
||||||
|
@ -188,6 +188,29 @@ def render_body(msg):
|
||||||
}
|
}
|
||||||
bodyhtml = bodytmpl.render(context)
|
bodyhtml = bodytmpl.render(context)
|
||||||
|
|
||||||
|
elif content_type == "application/pgp":
|
||||||
|
with tempfile.NamedTemporaryFile(buffering=0) as content_fh:
|
||||||
|
content_fh.write(msg.get_payload(decode=True))
|
||||||
|
r = subprocess.run(["gpg", "--decrypt", content_fh.name],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
)
|
||||||
|
gpgresult = r.stderr.decode()
|
||||||
|
# XXX - Analyze gpgresult or just use r,returncode?
|
||||||
|
gpgstatus = "dubious"
|
||||||
|
decrypted_content = r.stdout
|
||||||
|
|
||||||
|
p = email.parser.BytesParser()
|
||||||
|
embedded_message = p.parsebytes(decrypted_content)
|
||||||
|
contenthtml = render_message(embedded_message)
|
||||||
|
bodytmpl = jenv.get_template("body_application_pgp.html")
|
||||||
|
context = {
|
||||||
|
"content": contenthtml,
|
||||||
|
"gpgresult": gpgresult,
|
||||||
|
"gpgstatus": gpgstatus,
|
||||||
|
}
|
||||||
|
bodyhtml = bodytmpl.render(context)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("Content-type " + content_type + " not implemented yet")
|
raise RuntimeError("Content-type " + content_type + " not implemented yet")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue