On 8/8/12 11:27 AM, email builder wrote: > >>>> 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.
This is not beauty, this is KISS. ;) 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 pfa has this covered by adding a record in the alias table for both aliases (b...@example.com->a...@example.com) and mailboxes (a...@example.com->a...@example.com). This means that a list of all mail addresses (aliases and mailboxes) are available in alias.address, and that a single query on that table is enough to check all variants. If you don't like that design (I don't, but I have other things to worry about), write a difficult query or again, split the work over separate lookups: one for aliases in alias domains, and one for accounts in alias domains. -- Tom