Mailserver proxy (all protocols, webmail included)

I’m trying to configure a full proxy for my mailservers.
With full, I mean for all protocols.

We have, for example, 2 mail servers:
zimbra (imap,pop3,smtp,webmail)
linux+roundcube (imap, pop3, smtp, webmail)

Using MySQL I’m able to configure imap,pop3,smtp proxy: when a user
to the proxy, my nginx script checks on a database where to redirect the
login. If to the Zimbra server or to the linux server.

The problem is with webmail: is there some way to redirect http to
webmail or to roundcube, depending on the username? Do I have to create
login page and then use webmail’s api to redirect the login?

What I want is to give a single hostname to users, for example, and then let nginx redirect users to the right
webmail how it does for imap,pop3 and smtp.