If you absolutely want to do this, consider tacking something on existing software. The first intuition I had when I read your post was: use normal mailfile delivery via an existing mailserver and write a process that starts from these mailfiles and pushes them into the database.
As for why:
- Mailservers are a complex piece of software and not only much work, but much security-critical work. Why start over when you have dozens of man-years of development time done in programs like sendmail, procmail, or exim?
- Design philiosophy: real hackers don't write from scratch, but extend what is there

Good reading:
The Art of Unix Programming
On second thought: using exim (ok it's the one mailserver where I halfway find my way around the config), you can use external programs as transports. Intergrating a "push to database" transport shouldn't be that hard...
Bye, Marc.