I have an existing Linux server that already processes incoming email using some custom email handling scripts (in Perl) that do somewhat complex processing such as routing certain special addresses to a list of external email addresses that are looked up in a mySql database. In the end all email processed on this server ends up being forwarded off the site... no users access the site itself to read their email.
I would like to add Google as a spam filtering layer to this system. The problem is that if I specify Google as an MX handler for my domain, it is not clear how I would get Google to send the mail (after spam filtering) to my server to process, and how I would get Google to retain all the "To:" addresses unchanged so that the existing scripts on my server can work with as little change as possible.
If there are any online resources that address this situation, I would appreciate some pointers.