I'm trying to construct a ldap filter for my Dovecot/Postfix setup which acts as the example pseudo code & result below:

return uidNumber OF objectClass=posixAccount IF they have a ou=mail AND the mailAddress in this ou=mail IS EQUAL to test@Mydomain.TLD

# User-1, people, Mydomain.TLD
dn: uid=User-1,ou=people,dc=MyDomain,dc=TLD
uidNumber: 2110

More specific like this while %s holds e.g.: test@Mydomain.TLD:

search_base = dc=Mydomain,dc=TLD
query_filter = ( &(objectClass=posixAccount)(ou=mail)(mailAddress=%s) )
result_attribute = uidNumber

But obviously uidNumber is being hold by the posixAccount container one level above - and therewith it won't display what I want. Unfortunately I couldn't figure out how to get it work. My LDAP structure looks like this:

=> dc=MyDomain,dc=TLD
==> ou=People
===> uid=User-1
====> uidNumber=4035
====> ou=mail
=====> mailAddress=test@Mydomain.TLD
===> uid=User-2


Any help would be greatly apprecitated

Thanks

Best Regards
Leander