MaildirMessage

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Jul 13 03:19:48 CEST 2007


En Thu, 12 Jul 2007 21:46:32 -0300, Tzury <Afro.Systems at gmail.com>  
escribió:

> I am getting the following error when trying to iterate in a message
> in a Maildir directory.
> please help.
>
>>>> from mailbox import Maildir, MaildirMessage
>>>> mbox = Maildir('path/to/mailbox', create = False, factory =  
>>>> MaildirMessage)
>>>> for msg in mbox:
> ...     for m in msg:
> ...             print m
> ...
> Traceback (most recent call last):
>   File "<stdin>", line 2, in <module>
>   File "email/message.py", line 286, in __getitem__
>   File "email/message.py", line 352, in get
> AttributeError: 'int' object has no attribute 'lower'

msg is an instance of MaildirMessage (subclass of Message) - it has no  
specific iterator, so "for m in msg" tries to use the sequence protocol,  
starting at 0; that is, tries to get msg[0]. Message objects support the  
mapping protocol, and msg[0] tries to find a *header* 0, converting the  
name 0 to lowercase, and fails miserably.
Try with:

for msg in mbox:
   print msg

or read the MaildirMessage (and Message) docs to see the ways you can  
handle it.

-- 
Gabriel Genellina




More information about the Python-list mailing list