Parsing Email Headers

T misceverything at gmail.com
Fri Mar 12 00:19:36 CET 2010


Thanks for your suggestions!  Here's what seems to be working - it's
basically the same thing I originally had, but first checks to see if
the line is blank

                response, lines, bytes = M.retr(i+1)
                # For each line in message
                for line in lines:
                    if not line.strip():
                        M.dele(i+1)
                        break

                    emailMessage = email.message_from_string(line)
                    # Get fields
                    fields = emailMessage.keys()
                    # If email contains "From" field
                    if emailMessage.has_key("From"):
                        # Get contents of From field
                        from_field = emailMessage.__getitem__("From")



More information about the Python-list mailing list