The spam filter system uses basic scripting language for processing messages. This can be used for custom content filtering as well if you need to look inside the messages (e.g. at message content, attachments) as well as at the message headers etc.
See the spam filter reference for instructions on which files to edit, and the scripting language reference.