paul@565 | 1 | #!/usr/bin/env python |
paul@565 | 2 | |
paul@1051 | 3 | from email import message_from_string |
paul@564 | 4 | import sys |
paul@564 | 5 | |
paul@1051 | 6 | def until_from(f): |
paul@1051 | 7 | l = [] |
paul@1051 | 8 | s = f.readline() |
paul@1051 | 9 | while s: |
paul@1051 | 10 | l.append(s) |
paul@1051 | 11 | s = f.readline() |
paul@1051 | 12 | if s.startswith("From "): |
paul@1051 | 13 | break |
paul@1051 | 14 | return "".join(l) |
paul@1051 | 15 | |
paul@564 | 16 | def decode(part): |
paul@564 | 17 | for key, value in part.items(): |
paul@687 | 18 | if key != "Content-Transfer-Encoding": |
paul@687 | 19 | print "%s: %s" % (key, value) |
paul@564 | 20 | print |
paul@564 | 21 | decoded = part.get_payload(decode=True) |
paul@564 | 22 | if decoded: |
paul@564 | 23 | print decoded |
paul@564 | 24 | print |
paul@564 | 25 | else: |
paul@564 | 26 | for part in part.get_payload(): |
paul@564 | 27 | decode(part) |
paul@564 | 28 | |
paul@1051 | 29 | message = message_from_string(until_from(sys.stdin)) |
paul@564 | 30 | decode(message) |
paul@572 | 31 | |
paul@572 | 32 | # vim: tabstop=4 expandtab shiftwidth=4 |