Currently, we have a fully working POP/IMAP/Webmail system (using Dovecot and Roundcube) that is a gleaming tower of perfection in its intended design. We have thousands of customers who belong to a "default" domain (I'll call it ourdomain.com), and successfully log in with a username and password. We have a few thousand more who own domains that we host, and they log in successfully with their full e-mail address and password (call it customerdomain.com). It's been this way since the 1990s, with a lot of entrenched customer configuration.
The problem is now that people are used to logging into web forms with a full e-mail address, people who use ourdomain.com have to be reminded to log into webmail using only their username. This is a call our tech support department gets several times a week (and even I am guilty of doing this, I just don't call tech support about it), and probably should be eliminated with some kind of software solution.
So how do we get either Roundcube or Dovecot to recognise "username@ourdomain.com" as "username" instead, without having to change everyone's actual username in our system? But only do that if the domain is "ourdomain.com" and not "customerdomain.com". Keep in mind that any custom coding we do will have to be re-implemented every time we do security upgrades, and we would only consider that option as the last possible choice.
TL;DR:
We need this logic:
if $email contains @ourdomain.com
{
remove @ourdomain.com;
submit to roundcube;
} else {
submit to roundcube;
}