Sorry I had to vote -- on this one. The mail-to-database problem is one I had to fiddle with
two months ago.
- Your script doesn't do anything with attachments, they will just be saved encoded into the body text column.
- Usually you know into which database you want to insert mail, so dynamically selecting it isn't necessary.
- Passing passwords on the command line isn't a good idea, they can be found in the shell's history (if it has one).
- Traversing over the header in a while loop should be faster than mapping (but this is untested).
- I prefer using placeholders to insert values, so I don't have to fiddle with correct quoting.
These are just my 2 cents.