Properties of mbox message in mbox module in Python

2.4k Views Asked by At

I trying my luck to manage my mailbox with python.

My example code is

for eachmail in mailbox.mbox(mboxfile):
    print eachmail['From']

I got following by printing entire content.

Delivered-To
Subject
To
Content-Type
MIME-Version
Message-Id

Is there any full document showing what are all the properties I can get from the mbox message instance? Python docs doesn't specify any of these http://docs.python.org/library/mailbox.html#mailbox.mbox

3

There are 3 best solutions below

0
On BEST ANSWER

It depends entirely on what headers are in the message. Most of them are optional. Check RFC 2076 for common ones.

0
On

Those are the email message headers. The specific headers will vary drastically, and you can't really count on any of them existing (even ones you would expect to exist like To, or Subject)… But Wikipedia has a pretty good list of common headers and their meanings: http://en.wikipedia.org/wiki/Email#Header_fields

0
On

Using your variables

mm=mailbox.mbox(mboxfile)
message=mm[0]
message.keys()

You can now access using mm['Subject'] or mm['Message-ID']