Michael
I'm doing something similar with sendmail. I added a new delivery agent to sendmail, then updated rule set 0 to intercept local messages of a certain format and send them to the new delivery agent. That delivery agent (which is actually a Korn shell script in our case, but you could use Perl, C, etc) examines the message and determines how to process it based on the recipient name. It was relatively easy to setup sendmail.cf once I understood it (the "bat" book from O'Reilly was helpful for that) and to program the Korn script.
An example: Messages come into sendmail destined for "customer.###" where ### is an ID number. Rule set zero, in the section that has determined the address is for local delivery, has a new rule added that looks for "customer.$+" and passes the message to a new MDA named "customer" for processing. This MDA actually invokes a "custproc" script and passes the recipient name, which allows custproc to determine what subprogram to call based on the ### portion of the name. There is nothing to prevent custproc from also checking for other headers or even the body of the message.
You might be able to do something similar on qmail, though I don't know that much about how qmail implements rules and MDAs. From what I've read of procmail, that should work as well.
Best of luck!
Scott