got it... I subconsciously ignore anything on the bottom that resembles a sig. This sounds like a nightmare of a project from a security and flexibility standpoint. Also, you'll be harvesting spam crap into MySQL.
Why not just install squirrelmail which would do all of that for you? It stores everything in MySQL.
http://www.squirrelmail.org/docs/admin/admin-5.html