MIME Message Parsing : email « Network « Python Tutorial






import sys, email

def printmsg(msg, level = 0):
    l = "|  " * level
    l2 = l + "|"
    print l + "+ Message Headers:"
    for header, value in msg.items():
        print l2, header + ":", value
    if msg.is_multipart():
        for item in msg.get_payload():
            printmsg(item, level + 1)

msg = email.message_from_file(sys.stdin)
printmsg(msg)








21.25.email
21.25.1.MIME message generation with 8-bit headers
21.25.2.# MIME Header Parsing
21.25.3.MIME Message Parsing
21.25.4.Message Generation with Date and Message-ID
21.25.5.Message Generation
21.25.6.Message Parsing