import sys, email msg = email.message_from_file(sys.stdin) print " *** Headers in message: " for header, value in msg.items(): print header + ":" print " " + value if msg.is_multipart(): print "exiting." sys.exit(1) if 'subject' in msg: print "Subject: ", msg['subject'] print msg.get_payload()