[Tutor] Parsing an mbox mail file
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Sat, 27 Jan 2001 18:34:24 -0800 (PST)
On Sat, 27 Jan 2001, Sheila King wrote:
> : So we could adjust your code like this:
> :
> :###
> : currentmssg = messages.next()
> : if (currentmssg ==None):
> : break
> : print currentmssg.fp.read() # let's look at the msg contents
> :###
>
> Interesting. I tried this out, and it sort of prints the bodies
> without the headers. But not exactly. Every once in a while, it prints
> one to three lines of the header.
That is a bit strange! I tested the code on my own /var/spool/mail, and
it skips over the headers for my mail file.
You might want to check that your file is strickly in an mbox format ---
that's one thing I can think of that would cause such behavior.
> I am going to play around with this a bit more, later. But for now, I've
> "solved" my problem, by not saving the messages in a strict mbox format. I'm
> preceding each message with a message separator line. Since I know what the
> message separator line is, I can read up to that line, and then discard it
> with no ill effects.
This will work. If you have time, maybe you could make a small test
"mail" file that duplicates that weird behavior.
I'm glad that your program works now!