I've never done this myself, but it seems like if you could get fetchmail configured right, there shouldn't be much (if any) bash scripting needed to get it to do what you want.
This tutorial seems like it would be useful to you:
http://www.axllent.org/docs/networki...with_fetchmail
I would also check the man page for fetchmail. You would probably have more luck posting any questions that come up about fetchmail in one of the other subforums, like maybe the Linux Software subforum.