imip-agent

tools/showmail.py

1072:519e1d452e0d
2016-03-06 Paul Boddie Added parsing and serialisation functions involving strings. freebusy-collections
     1 #!/usr/bin/env python     2      3 from email import message_from_string     4 import sys     5      6 def until_from(f):     7     l = []     8     s = f.readline()     9     while s:    10         l.append(s)    11         s = f.readline()    12         if s.startswith("From "):    13             break    14     return "".join(l)    15     16 def decode(part):    17     for key, value in part.items():    18         if key != "Content-Transfer-Encoding":    19             print "%s: %s" % (key, value)    20     print    21     decoded = part.get_payload(decode=True)    22     if decoded:    23         print decoded    24         print    25     else:    26         for part in part.get_payload():    27             decode(part)    28     29 message = message_from_string(until_from(sys.stdin))    30 decode(message)    31     32 # vim: tabstop=4 expandtab shiftwidth=4