1 #!/usr/bin/env python 2 3 from email.mime.multipart import MIMEMultipart 4 from email.mime.application import MIMEApplication 5 from email.mime.base import MIMEBase 6 from email import message_from_string 7 import sys 8 9 if __name__ == "__main__": 10 message = sys.argv[1] 11 text = open(message).read() 12 signature = sys.stdin.read() 13 protocol = "application/pgp-signature" 14 subtype = "signed" 15 16 # Make the container for the message. 17 18 message = MIMEMultipart(subtype, protocol=protocol) 19 20 submessage = message_from_string(text) 21 message.attach(submessage) 22 23 signature_part = MIMEBase("application", "pgp-signature") 24 signature_part.set_payload(signature) 25 message.attach(signature_part) 26 27 # Show the resulting message text. 28 29 text = message.as_string() 30 31 print text 32 33 # vim: tabstop=4 expandtab shiftwidth=4