Email consists of headers separated from the body by a blank line. I would use file() to open the email (which puts it into a array). For each element of the array up to a blank line, examine the line for each header you're interested in, using regular expressions to test and extract values.
Headers are very regular. Labels begin at column 1, are capitalized, and end with a colon and a space. Values begin immediately thereafter and run to the end of the line.
One caveat: A line that begins with an indent needs to be considered as appended to the previous line. That should make for some interesting code.