multifile and mimetools to parse email folder

rdskar1 at rdskar1 at
Tue Jun 5 23:27:45 EDT 2001

I played around with multifile and mimetools again tonight and found out
a few things.
when a boundary is found (for a multipart message), multifile methods
push, next and pop make it easy to move through the parts of the message.
when next returns a zero (end of message), one readline will move to the
start of the next message.
the readline() method can be used on a multifile to move through an email file if the
message headers does not provide a boundary item. 
the problem is having a reliable way of identifying the first line of the
next message. 
Worst case is that mimetools.Message can be created and interrogated on
each read.
there should be a better way.
there is a Lines: item in the header that would tell how many readlines
until the next message..
I'm not sure if I can rely on that item being there. 

In article <nLWS6.30254$lP5.13578256 at>,
rdskar1 at wrote:

> I want to read through an email folder (I use mutt on debian, the
> 'folder' is a text file) and decode the attachments. I understand how
> mimetools works, but I am having trouble moving from message to message
> with multifile. I have been trying  various combinations off multifile
> push, pop and readline methods,  but I haven't hit on the right
> combinations.
> infl=open('emailfile','r') file=multifile.MultiFile(infl)
> msg=mimetools.Message(file) file.push(msg.getparam('boundary'))
> repeat until returns 0 how do I get to the next message?
> Thanks in advance, Bob

More information about the Python-list mailing list