IMHO this is better implemented either server-side, or with rules in each user's mail client. Solutions already exist for both. Doing continuous client-side polling & filtering wastes bandwidth and CPU cycles.
But it's doable, and if you don't have control of server or user client software, it might be the only option, I guess.