paul@0 | 1 | #!/usr/bin/env python |
paul@0 | 2 | |
paul@0 | 3 | from email.mime.multipart import MIMEMultipart |
paul@1 | 4 | from email.mime.application import MIMEApplication |
paul@1 | 5 | from email.mime.base import MIMEBase |
paul@1 | 6 | from email.encoders import encode_noop |
paul@0 | 7 | import httplib |
paul@0 | 8 | import sys |
paul@0 | 9 | |
paul@0 | 10 | if __name__ == "__main__": |
paul@0 | 11 | host = sys.argv[1] |
paul@0 | 12 | path = sys.argv[2] + "?action=PostMessage" |
paul@1 | 13 | text = sys.stdin.read() |
paul@0 | 14 | |
paul@1 | 15 | message = MIMEMultipart("encrypted", protocol="application/pgp-encrypted") |
paul@0 | 16 | |
paul@1 | 17 | declaration = MIMEBase("application", "pgp-encrypted") |
paul@1 | 18 | declaration.set_payload("Version: 1") |
paul@1 | 19 | message.attach(declaration) |
paul@0 | 20 | |
paul@1 | 21 | content = MIMEApplication(text, "octet-stream", encode_noop) |
paul@1 | 22 | message.attach(content) |
paul@0 | 23 | |
paul@0 | 24 | text = message.as_string() |
paul@1 | 25 | |
paul@0 | 26 | print text |
paul@0 | 27 | print |
paul@0 | 28 | |
paul@0 | 29 | req = httplib.HTTPConnection(host) |
paul@0 | 30 | req.request("PUT", path, text) # {"Content-Length" : len(text)} |
paul@0 | 31 | resp = req.getresponse() |
paul@0 | 32 | print resp.read() |
paul@0 | 33 | |
paul@0 | 34 | # vim: tabstop=4 expandtab shiftwidth=4 |