paul@1 | 1 | #!/usr/bin/env python |
paul@1 | 2 | |
paul@15 | 3 | from MoinMessage import Message |
paul@16 | 4 | from email.mime.multipart import MIMEMultipart |
paul@1 | 5 | from email.mime.text import MIMEText |
paul@11 | 6 | import sys |
paul@1 | 7 | |
paul@1 | 8 | if __name__ == "__main__": |
paul@16 | 9 | try: |
paul@16 | 10 | type = sys.argv[1] |
paul@16 | 11 | action = sys.argv[2] |
paul@16 | 12 | args = sys.argv[3:] |
paul@16 | 13 | except IndexError: |
paul@16 | 14 | args = None |
paul@16 | 15 | |
paul@16 | 16 | if not args: |
paul@16 | 17 | print >>sys.stderr, "Need an update type, update action and some updates as arguments to this program." |
paul@16 | 18 | sys.exit(1) |
paul@16 | 19 | |
paul@15 | 20 | message = Message() |
paul@16 | 21 | parts = [] |
paul@1 | 22 | |
paul@16 | 23 | # Add each content fragment as either a separate update to a collection of |
paul@16 | 24 | # updates or as an alternative part to a single update. |
paul@16 | 25 | |
paul@16 | 26 | for arg in args: |
paul@16 | 27 | part = MIMEText(arg, "moin", sys.stdin.encoding) |
paul@16 | 28 | if type == "collection": |
paul@16 | 29 | part["Update-Action"] = action |
paul@16 | 30 | message.add_update(part) |
paul@16 | 31 | else: |
paul@16 | 32 | parts.append(part) |
paul@16 | 33 | |
paul@16 | 34 | if type != "collection": |
paul@16 | 35 | multipart = message.get_update(parts) |
paul@16 | 36 | multipart["Update-Action"] = action |
paul@16 | 37 | message.add_update(multipart) |
paul@1 | 38 | |
paul@15 | 39 | text = message.get_payload() |
paul@1 | 40 | print text |
paul@1 | 41 | |
paul@1 | 42 | # vim: tabstop=4 expandtab shiftwidth=4 |