You can take a look at
xapian. Depending on how you index the mail, you'd be able to do searches such as:
Code:
subject:"meeting tomorrow" from:"bigboss@mycompany" servers
You'll also have to think about how to archive the mail, e.g. the search can return a list of IMAP UIDs underneath, or whatever.