do a search on the net for rfc822.
everything is mentioned there.
as mentioned by Ade, the e-mail message contains headers (from, to, subject, date), and then a single empty line (just \n), and the rest is the message body.
don't know the complexity of your script, but you should find out about MIME too and encoded mails (base64/qp) if you require it.
have a good and productive day. 🙂