I am trying to write a script that gets me the contents of all the Mails in ~/Maildir
. So I basically copypasted code from this question. Here is the full content of mailbox.py
:
import mailbox
maildir = mailbox.Maildir("~/Maildir");
for message in maildir:
print message["subject"]
if message.is_multipart():
print "ok"
It does print the subject of the first message, but instead of printing "ok" then, it dies stating
AttributeError: Message instance has no attribute 'is_multipart'
What did I do wrong?
You have forgotten to name your Python version so let me guess — it's Python 2.7, right? In Python 2.7
mailbox.Maildir
by default returns instances of rfc822.Messages, notemail.Message
s;rfc822.Message
has a completely different API.If you want
mailbox.Maildir
to returnemail.Message
s remove defaultfactory
:In Python 3
rfc822.Message
was removed somailbox.Maildir
returnsemail.Message
s by default.