RE: [Exim] PostgreSQL & Aliassing Again

Top Page
Delete this message
Reply to this message
Author: Mark McRitchie
Date:  
To: 'Sander Smeenk'
CC: exim-users
Subject: RE: [Exim] PostgreSQL & Aliassing Again
On Wed, 2002-08-28 at 09:12, Sander Smeenk wrote:
> | system_aliases:
> | driver = redirect
> | allow_defer
> | allow_fail
> | data = ${lookup pgsql{SELECT destination FROM exim_user_aliases WHERE

lower(localpart) = lower('${quote_pgsql:$local_part}') AND lower(owner) =
lower('${quote_pgsql:$domain}') LIMIT 1}}
> | file_transport = address_file
> | pipe_transport = address_pipe
> | retry_use_local_part
>
> This works, as shown here:
>
> | hoho=> select * from exim_aliases;
> |  id | localpart |     destination      |    owner
> | ----+-----------+----------------------+-------------
> |  24 | test      | ssmeenk@??? | domain.tld

>
> | EXPN test@???
> | 250 <ssmeenk@???>
>
> But I also want that all email to a $local_part NOT SPECIFIED in the
> database goes to 'thisuser@???'. With 'normal' aliases files
> and lsearch{} lookups, you can put a line stating:
>
> | *: thisuser@???
>
> in your aliases file and it will match any local_part not specified
> before and route all that mail to the specified email address..
>
> Unfortunately, this is not possible with SQL, because '*' doesn't match
> 'thisuser' in SQL :/
>
> Can someone tell me how I should change my director config that it
> queries the database where to send mail that doesn't match any
> local_part specified?
>


Now, I'm not 100% convinced that this syntax will work (I use MySQL) but:

if you put an entry in your exim_user_aliases with the PostgreSQL wildcard
character in it (% under MySQL, not sure about PostgreSQL) as the localpart
eg
 |  id | localpart |     destination      |    owner
 | ----+-----------+----------------------+-------------
 |  24 | %         | ssmeenk@??? | domain.tld


and then if you use the 'LIKE' operator instead of '=' in your where clause,
but reverse the bits so that instead of matching the DB against the
${local_part} your matching the opposite way round:

SELECT destination FROM exim_user_aliases WHERE
lower('${quote_pgsql:$local_part}') LIKE lower(localpart) = AND lower(owner)
= lower('${quote_pgsql:$domain}'

Now, as that wild entry will always be matched, add "ORDER BY localpart DESC
LIMIT 1"
(I think its DESC you need, not sure which direction the sort happens in off
the top of my head) to the end of the query so that that only one address
will be returned, that should do the trick!

HTH
Mark.


Salamis Group of Companies - WWW.SALAMISGROUP.COM

This communication contains information which is confidential and may
also be privileged. It is for the exclusive use of the intended
recipient(s). If you are not the intended recipient(s) be advised
that any form of distribution, copying or use of this communication
or the information it contains is strictly prohibited and may be
unlawful. We apologise if you have received this communication in
error. Please return it to the sender immediately, delete this
communication from your computer and destroy any copies of it. Any
views/opinions expressed in this email are that of the author and may
not reflect the views of Salamis (M&I)Ltd.