Sounds like a pretty good description of what Fetchmail does, have a look at
http://tuxedo.org/~esr/fetchmail/ for further details. You might end up using a Fetchmail/procmail setup mind you, in which case if qmail will support then it might be easier.
cheers
Jamie...