This thread might be interesting, you could check JohnZemans code:
[Sending files automatically to appropriate collections?)