This is really easy to set up using Dovecot Sieve [1]. I set it up the other day to bounce reject messages that had too many swear words as a proof-of-concept for an idea a Facebook friend had about making sure people stay nice in email. The syntax of the server-side filters is a bit strange but there's even a Thunderbird plugin that allows you to edit them from the client.