[exim] Rewrite syntax, expansion and condtion help + MARCOs

Pàgina inicial
Delete this message
Reply to this message
Autor: Ron White
Data:  
A: exim-users
Assumpte: [exim] Rewrite syntax, expansion and condtion help + MARCOs
I'm trying to get something simple to work, but my lack of understanding
and knowledge of Exim is still giving me a few problems. If I'm honest,
I'm probably a bit too stupid to understand what is going on here.

What I'm trying to do is have the rewrite section lookup a full email
address in a mysql database. If that address exists I don't want any
rewriting done and I don't want to check any more rules. I'm close to
it, but can't achieve it and I suspect it's my weak understanding.

This will rewrite the address back to itself, but if there is no match
it does not seem to run any subsequent statements:

*@* "${if eq {${lookup mysql{MYSQL_RCPT}}}\
{$local_part@$domain}{$0}fail}" Tq

As will this (which is kind of better to my eyes, but still miles off)
*@*     "${if eq {\
        ${lookup mysql{MYSQL_RCPT}}\
        }{$local_part@$domain}{$local_part@$domain}fail}" Tq


And it gives the desired behaviour in a roundabout way:
exim -brw foo@bar
  sender: foo@bar
    from: foo@bar
      to: foo@bar
      cc: foo@bar
     bcc: foo@bar
reply-to: foo@bar
env-from: foo@bar
2010-05-09 11:21:18 [3295] "foo@bar" from env-to rewritten as "foo@bar"
by rule 2
  env-to: foo@bar


I have two problems here. First, there is probably an easier way to do
this so I don't actually need to rewrite with the same address? Also, as
is - if the test fails (there is no such recipient in the database) no
further rules are tested.

The only flag I can see that will do what I want is the '*' asterisk.
And this is only briefly mentioned in relation to the S flag, but I
can't seem to form it correctly - please don't laugh, but I tried this:

*@*     "${if eq {\
        ${lookup mysql{MYSQL_RCPT}}\
        }{$local_part@$domain}{*}fail}" Tq


But it yields:

exim -brw foo@bar
Rewrite of foo@bar yielded unqualified address "*"
env-to: foo@bar

Clearly I'm getting something wrong / not understanding something in the
formation of the rule here :-)

.....

Moving on (it's related)
I then would like a rule that (because the rule above has failed to
match a valid address) looks up the domain in a mysql database and
checks to see if the catch all flag (catchall_enable) is set to 1. If it
is, it then rewrites the address with a value in the same database
record called catchall_destination. This works, but I'm sure there has
to be a much more graceful way to do it by recovering the value needed
for the substitution in the first query?

*@*     "${if eq {\
        ${lookup mysql{SELECT 1 FROM domains WHERE \
dom_name='${quote_mysql:$domain}' AND catchall_enable=1}}\
        }{1}\
        {${lookup mysql{SELECT catchall_dest FROM domains WHERE
catchall_enable=1 AND dom_name='${quote_mysql:$domain}'}}@$domain}fail}"
Tq


but again, no further rules are tested if it fails.

I apologise for asking a number of questions that may appear rather
obvious in the last couple of weeks. I appreciate that it may be
annoying for some list readers. I appreciate that it is covered in the
documentation, I just seem to have trouble understanding and applying it
so I am very grateful for any help.