Handle PGP signed messages
This commit is contained in:
parent
02368a57f8
commit
ea60f484a3
25
mbox2web
25
mbox2web
|
@ -7,7 +7,9 @@ import html.parser
|
||||||
import mailbox
|
import mailbox
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import tempfile
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
import jinja2
|
import jinja2
|
||||||
|
@ -142,6 +144,29 @@ def render_body(msg):
|
||||||
}
|
}
|
||||||
bodyhtml = bodytmpl.render(context)
|
bodyhtml = bodytmpl.render(context)
|
||||||
|
|
||||||
|
elif content_type == "multipart/signed":
|
||||||
|
content, signature = msg.get_payload()
|
||||||
|
with tempfile.NamedTemporaryFile(buffering=0) as content_fh:
|
||||||
|
content_fh.write(content.as_bytes())
|
||||||
|
with tempfile.NamedTemporaryFile(buffering=0, suffix=".asc") as signature_fh:
|
||||||
|
signature_fh.write(signature.get_payload(decode=True))
|
||||||
|
|
||||||
|
r = subprocess.run(["gpg", "--verify", signature_fh.name, content_fh.name],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
universal_newlines=True)
|
||||||
|
gpgresult = r.stderr
|
||||||
|
# Analyze gpgresult or just use r,returncode?
|
||||||
|
gpgstatus = "dubious"
|
||||||
|
|
||||||
|
contenthtml = render_message(content)
|
||||||
|
bodytmpl = jenv.get_template("body_multipart_signed.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