This is simple to do with Procmail.
:0
* ^To: <uniqueID>\.CommonID\.User1@domain\.cim
! User1@domain.com
It's not clear what <uniqueID>
and CommonID
should represent, but if they can be expressed as regular expressions, you are all set.
The LDA can pass your email on standard input to any program you write. Procmail is specialized for this purpose so even if you want to write your program in PHP, it might make sense to invoke it from Procmail rather than directly from the LDA.