catch-all addresses should not have precedence over mail users
Aliases have precedence over mail users. A catch-all address would grab mail intended for a mail user and send it elsewhere. This adds some SQL hackery to create dummy aliases for all mail users. fixes #200 closes #214 another way
This commit is contained in:
parent
a4c70f7a92
commit
698ae03505
1 changed files with 8 additions and 1 deletions
|
@ -93,9 +93,16 @@ query = SELECT 1 FROM users WHERE email='%s'
|
|||
EOF
|
||||
|
||||
# SQL statement to rewrite an email address if an alias is present.
|
||||
# Aliases have precedence over users, but that's counter-intuitive for
|
||||
# catch-all aliases ("@domain.com") which should *not* catch mail users.
|
||||
# To fix this, not only query the aliases table but also the users
|
||||
# table, i.e. turn users into aliases from themselves to themselves.
|
||||
# If there is both an alias and a user for the same address either
|
||||
# might be returned by the UNION, so the whole query is wrapped in
|
||||
# another select that prioritizes the alias definition.
|
||||
cat > /etc/postfix/virtual-alias-maps.cf << EOF;
|
||||
dbpath=$db_path
|
||||
query = SELECT destination FROM aliases WHERE source='%s'
|
||||
query = SELECT destination from (SELECT destination, 0 as priority FROM aliases WHERE source='%s' UNION SELECT email as destination, 1 as priority FROM users WHERE email='%s') ORDER BY priority LIMIT 1;
|
||||
EOF
|
||||
|
||||
# Restart Services
|
||||
|
|
Loading…
Reference in a new issue