1.1 --- a/MoinMessage.py Thu Dec 26 18:26:25 2013 +0100
1.2 +++ b/MoinMessage.py Sat Dec 28 00:43:31 2013 +0100
1.3 @@ -11,6 +11,7 @@
1.4 from email.mime.multipart import MIMEMultipart
1.5 from email.mime.application import MIMEApplication
1.6 from email.mime.base import MIMEBase
1.7 +from email.parser import Parser
1.8 from email.utils import formatdate, parsedate
1.9 from subprocess import Popen, PIPE
1.10 from tempfile import mkstemp
1.11 @@ -278,7 +279,10 @@
1.12 # Verify the message.
1.13
1.14 fingerprint, identity = self.verifyMessageText(signature.get_payload(), content.as_string())
1.15 - return fingerprint, identity, content
1.16 +
1.17 + # Extract the actual content inside the signed message.
1.18 +
1.19 + return fingerprint, identity, Parser().parsestr(content.get_payload(decode=True))
1.20
1.21 def signMessage(self, message, keyid):
1.22
1.23 @@ -286,13 +290,19 @@
1.24 Return a signed version of 'message' using the given 'keyid'.
1.25 """
1.26
1.27 + # Make a representation-insensitive container for the message.
1.28 +
1.29 text = message.as_string()
1.30 - signature = self.run(["--armor", "-u", keyid, "--detach-sig"], text)
1.31 + content = MIMEApplication(text)
1.32 +
1.33 + # Sign the container's representation.
1.34 +
1.35 + signature = self.run(["--armor", "-u", keyid, "--detach-sig"], content.as_string())
1.36
1.37 # Make the container for the message.
1.38
1.39 signed_message = MIMEMultipart("signed", protocol="application/pgp-signature")
1.40 - signed_message.attach(message)
1.41 + signed_message.attach(content)
1.42
1.43 signature_part = MIMEBase("application", "pgp-signature")
1.44 signature_part.set_payload(signature)