IMAPFilter is a mail filtering utility. It connects to remote mail servers using the Internet Message Access Protocol (IMAP), sends searching queries to the server and processes mailboxes based on the results.
This document outlines the setup of a typical Sendmail -> DSPAM -> Procmail system. If you don't use Procmail, then substitute your LDA where applicable.