Outro método é usar o recurso de expansões do mysql no postfix. Veja man 5 mysql_table .
Aqui a versão alternativa da sua consulta
query = SELECT '%d/%u/' FROM virtual_users WHERE email='%s';
Quando a entrada for [email protected] , a string %d/%u/
será expandida para example.com/user/
. Esta parte WHERE email='%s'
limitará essa consulta apenas ao nome de usuário válido.
Veja também esta postagem do blog para obter o exemplo dessas expansões.
O trecho relevante da página de documentação
query The SQL query template used to search the database, where %s is a substitute for the address Postfix is trying to resolve, e.g. query = SELECT replacement FROM aliases WHERE mailbox = '%s'
This parameter supports the following '%' expansions:
%% This is replaced by a literal '%' character.
%s This is replaced by the input key. SQL quoting is used to make sure that the input key does not add unexpected metacharacters.
%u When the input key is an address of the form user@domain, %u is replaced by the SQL quoted local part of the address. Otherwise, %u is replaced by the entire search string. If the localpart is empty, the query is suppressed and returns no results.
%d When the input key is an address of the form user@domain, %d is replaced by the SQL quoted domain part of the address. Otherwise, the query is suppressed and returns no results.