paul@5 | 1 | #!/usr/bin/env python |
paul@5 | 2 | |
paul@5 | 3 | from email.mime.multipart import MIMEMultipart |
paul@5 | 4 | from email.mime.application import MIMEApplication |
paul@5 | 5 | from email.mime.base import MIMEBase |
paul@5 | 6 | from email.encoders import encode_noop |
paul@5 | 7 | import sys |
paul@5 | 8 | |
paul@5 | 9 | if __name__ == "__main__": |
paul@5 | 10 | text = sys.stdin.read() |
paul@5 | 11 | protocol = "application/pgp-encrypted" |
paul@5 | 12 | subtype = "encrypted" |
paul@5 | 13 | |
paul@5 | 14 | # Make the container for the message. |
paul@5 | 15 | |
paul@5 | 16 | message = MIMEMultipart(subtype, protocol=protocol) |
paul@5 | 17 | |
paul@5 | 18 | # For encrypted content, add the declaration and content. |
paul@5 | 19 | |
paul@5 | 20 | declaration = MIMEBase("application", "pgp-encrypted") |
paul@5 | 21 | declaration.set_payload("Version: 1") |
paul@5 | 22 | message.attach(declaration) |
paul@5 | 23 | |
paul@5 | 24 | content = MIMEApplication(text, "octet-stream", encode_noop) |
paul@5 | 25 | message.attach(content) |
paul@5 | 26 | |
paul@5 | 27 | # Show the resulting message text. |
paul@5 | 28 | |
paul@5 | 29 | text = message.as_string() |
paul@5 | 30 | |
paul@5 | 31 | print text |
paul@5 | 32 | |
paul@5 | 33 | # vim: tabstop=4 expandtab shiftwidth=4 |