simple text file 'parsing' question

Phil Mayes nospam at
Sat Jun 19 08:44:11 CEST 1999

KP wrote in message <376B1AAC.19FE8BCE at>...
>Here's my dilema: a directory filled (200+) with small emails. My goal
>is to strip all the headers and combine them into one file. I can read
>all the files just fine and write them all to one file, but I cannot
>discern how to strip the headers. The answer must be very simple, yet
>I cannot see it. Can anyone give a few pointers on how to do it, our
>what module might be best? Thank you.

A raw email always has a blank line between the header and the body.
(To be pendantic, it should also have all its lines ending in CRLF.)
So you can read it in and find the gap by looking for 2 EOLs:

import string
f = open('c:\\apps\\eudora\\in.mbx', 'r')
all =
x = string.find(all, '\n\n')
body = all[x+2:]
# append body to output file
Phil Mayes    pmayes AT olivebr DOT com

More information about the Python-list mailing list