I coded something a few years back which sounds like what you're looking for.
It's pretty useless to me at the moment but it might be good for learning from.

Here's the link: http://download.yousendit.com/067F2DC1307951E1