1.1 --- a/tests/test_post.py Sat Jul 21 19:58:34 2012 +0200
1.2 +++ b/tests/test_post.py Sat Jul 21 21:01:16 2012 +0200
1.3 @@ -4,22 +4,51 @@
1.4 from email.mime.application import MIMEApplication
1.5 from email.mime.base import MIMEBase
1.6 from email.encoders import encode_noop
1.7 +from email import message_from_string
1.8 import httplib
1.9 import sys
1.10
1.11 if __name__ == "__main__":
1.12 host = sys.argv[1]
1.13 path = sys.argv[2] + "?action=PostMessage"
1.14 - text = sys.stdin.read()
1.15
1.16 - message = MIMEMultipart("encrypted", protocol="application/pgp-encrypted")
1.17 + try:
1.18 + message = sys.argv[3]
1.19 + text = open(message).read()
1.20 + signature = sys.stdin.read()
1.21 + protocol = "application/pgp-signature"
1.22 + subtype = "signed"
1.23 + except IndexError:
1.24 + text = sys.stdin.read()
1.25 + signature = None
1.26 + protocol = "application/pgp-encrypted"
1.27 + subtype = "encrypted"
1.28 +
1.29 + # Make the container for the message.
1.30 +
1.31 + message = MIMEMultipart(subtype, protocol=protocol)
1.32 +
1.33 + # For encrypted content, add the declaration and content.
1.34
1.35 - declaration = MIMEBase("application", "pgp-encrypted")
1.36 - declaration.set_payload("Version: 1")
1.37 - message.attach(declaration)
1.38 + if not signature:
1.39 + declaration = MIMEBase("application", "pgp-encrypted")
1.40 + declaration.set_payload("Version: 1")
1.41 + message.attach(declaration)
1.42 +
1.43 + content = MIMEApplication(text, "octet-stream", encode_noop)
1.44 + message.attach(content)
1.45 +
1.46 + # For signed content,
1.47
1.48 - content = MIMEApplication(text, "octet-stream", encode_noop)
1.49 - message.attach(content)
1.50 + else:
1.51 + submessage = message_from_string(text)
1.52 + message.attach(submessage)
1.53 +
1.54 + signature_part = MIMEBase("application", "pgp-signature")
1.55 + signature_part.set_payload(signature)
1.56 + message.attach(signature_part)
1.57 +
1.58 + # Show the resulting message text.
1.59
1.60 text = message.as_string()
1.61