Properties of mbox message in mbox module in Python
Question
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
Solution
It depends entirely on what headers are in the message. Most of them are optional. Check RFC 2076 for common ones.
OTHER TIPS
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
Using your variables
mm=mailbox.mbox(mboxfile)
message=mm[0]
message.keys()
You can now access using mm['Subject'] or mm['Message-ID']