Adam Jensen <han...@riseup.net> writes: > ... > https://docs.python.org/2.7/library/mailbox.html#examples > > import mailbox > for message in mailbox.mbox('~/mbox'): > subject = message['subject'] # Could possibly be None. > if subject and 'python' in subject.lower(): > print subject > > What is the structure of "message"? I guess it's a dictionary but what > is its structure? What are the keys?
In addition to the previous (excellent) responses: A "message" models a MIME (RFC1521 Multipurpose Internet Mail Extensions) message (the international standard for the structure of emails). The standard tells you that a message consists essentially of two parts: a set of headers and a body and describes standard headers and their intended meaning (e.g. "To", "From", "Subject", ...). It allows a message to contain non-standard headers as well. With this knowledge, your "keys" related question can be answered: there is a (case insensitive) key for each header actually present in your message. If the message contains several headers with the same name, the subscription access gives you the first one; there is an alternative method to access all of them. -- https://mail.python.org/mailman/listinfo/python-list