Re: [exim] problem with ${if } in nested and {} condition

Top Pagina
Delete this message
Reply to this message
Auteur: Phil Pennock
Datum:  
Aan: Marten Lehmann
CC: exim-users
Onderwerp: Re: [exim] problem with ${if } in nested and {} condition
On 2010-02-18 at 23:32 +0100, Marten Lehmann wrote:
> The final logic in exim would be something like this:
>
> ${if  and { \
>     { \
>         ${if eq{}{} \
>             {true} \
>             { ${if eq{}{} \
>                 {true} \
>                 {false} \
>             } } \
>         } } \
>     } \
>     { \
>         ${if eq{}{} \
>             {true} \
>             { ${if eq{}{} \
>                 {true} \
>                 {false} \
>             } } \
>         } } \
>     } \
>     } \
> }

>
> Since the above code does not work, I'm really interessed to see how
> else I can "and" these if conditions.


The ${if ...} construct is:
${if CONDITION {TRUTH-BRANCH}{FALSE-BRANCH}}
(loosely speaking, ignoring ability to omit branches or force failure).

After the "${if " you're in Condition parsing mode. You need to provide
lexical conditions.

"and" is the name of a condition. For "and", it's:
and{{COND1}{COND2}{COND3}}

The contents of COND1 must be a lexical condition. An arbitrary string
expansion is not a condition.

"${if " is how you introduce conditionals into a string expansion
context. Your problem is that you're using it too freely. You need it
for the textual branches but not for the condition locations.

Note that with or{{COND1}{COND2}} the COND2 is parsed but is not
executed unless COND1 fails, so it short-circuits. This is what lets
you implement the nested else.

This should work:

  ${if  and {\
      {or{\
        {eq{}{}}\
        {eq{}{}}\
    }}\
    {or{\
        {eq{}{}}\
        {eq{}{}}\
    }}\
    }}



Further, as of Exim 4.70, there's a bool{} expansion condition,
which takes an arbitrary string and turns it into a condition. So if
you truly need to take an arbitrary ${if ...} string you *could* nest it
inside a bool{} condition. For the simple case shown, you can reduce
this to proper combinations of and{} and or{} conditions though.

  ${if  and {\
        {or{\
                {eq{}{}}\
                {bool{${if eq{}{} \
                        {true}\
                        {false}\
                }}}\
        }}\
        {or{\
                {eq{}{}}\
                {eq{}{}}\
        }}\
        }}



On a separate note, you can use repeated "condition" rules in an ACL but
not on a Router. (If memory serves).

Regards,
-Phil