Yes, it is not exactly a straightforward solution. I would like a more modular mail system which would give us more hooks to handle incoming mail. I know you can create milters, etc, but those are not a trivial thing to build. I once created extensions to the Apache web server with mod_perl which was really quite easy and I was able to make Apache do something the available extensions could not do alone. (SSL secured reverse proxy with LDAP lookup)
There is the James mail server which was created with Java which I believe had plans for plugins. But I cannot really run Java on my FreeBSD 5.x server.
Is there a modular IMAP server which has hooks for languages like Perl, Python or Ruby?
java for mail server is just a joke. Keep java for java stuff.
You can use existing product for that. The lowest level is SMTP
piping. For optimisation, you can use LMTP, the local version of
SMTP. If you're perl coder, just use Amavis.
In my configuration, i use Postfix, then amavis and after Cyrus.
Amavis do cleaning stuff, like virus search with ClamAV, domain
trashing with pyzor, spam hunting with spamassassin.
You can add your stuff here, amavis will ask you when a mail is
coming. Milter, the Sendmail interface is now coming to Postfix guy.
There is a python-milter.
With this filters you can alter mail content, or just tag it like
spamassassin do, after, mail can be redirected in the right mailbox,
with sieve rules, fetchmail rules or client side rules.
Just choose where you need to act.
M.