>>>  query = select if ('%d' = 'example-2.com', 

>>> IFNULL((select dest from
>>>  aliases where addr = '%u...@example.com'), (select addr from users 
>>>  where addr = '%u...@example.com')), NULL)
>>> 
>>>  I've found that in conjunction with a 2nd query (the original
>>>  normal one), everything seems to work as expected (including
>>>  aliases with only local parts like "postmaster")
>>> 
>>>  But I'm still unsure if this kind of query is correct, if I'm 
>>> on
>>>  the right track. Can anyone tell me if there's a better way to do
>>>  it?
>>> 
>>>  Where are all those examples that are supposedly posted on this
>>>  list previously?
>
> You have been pointed to postfixadmin before, which has all of this
> builtin. Did you check their documentation? Every existing db-based
> postfix adminsitration suite should have an example for you.

Sorry, I hoped not to have to learn a whole new tool when it was said there 
were already examples posted to this list. I'll try to take a look and see how 
easy it is to pick up parts like this

> My query for alias domains on postgres, using postfixadmin database model:
> 
> query = SELECT goto FROM postfix_alias AS alias, postfix_alias_domain AS
> alias_domain WHERE alias_domain.alias_domain = '%d' AND alias.address =
> '%u' || '@' || alias_domain.target_domain AND alias.active = 
> '1' AND
> alias_domain.active = '1'
> 
> Definitely less hurting the head than your query this early in the
> morning, imho.

Beauty is in the eye of the beholder I guess. I also gave pseudocode and after 
staring at your query, it does part of what mine does, but I have a question 
why it does not do the other part. 

What my tests have shown to work is:

0) if %d isn't the aliased domain "example-2.com" then forget it
1) Look in alias table to see if there is an alias for "user" in the 
target/primary domain "example.com", if there is, return it
2) If there was not an alias, we must look in the account table to find if 
there is a real account address for "user" in the target/primary domain 
"example.com", if there is, return it
3) otherwise, return NULL so postfix can reject the address

Your query only does steps 0 and 1. I found that if you skip step 2 mail will 
only be delivered for addresses that happen to have aliases in the 
target/primary domain.

Why does yours work? Do you ALSO have another query just like the one you show 
here that does the same thing in your account maps lookup query?  That might 
explain this.  And in that case, my query does both in one place - is there any 
reason why my approach would be dangerous?

Thanks a bunches for taking the time to help me

Reply via email to