Re: [exim] Weird errors with conditions

Pàgina inicial
Delete this message
Reply to this message
Autor: Jakob Hirsch
Data:  
A: 'Exim-users'
Assumpte: Re: [exim] Weird errors with conditions
Yves Goergen wrote:

>>${if and { \
>>    {eq {$recipients_count} {1}} \
>>    {eq {lookup...} {1}}}}
> Why is that 'and' unnecessary when I want to check for 'A and B'?


ok, trying once more. This whole stuff is a constant source of confusion
for new Eximians. The spec is very clear aboout it, I think, but maybe
it has to be even more clear...

Exim's string expansion works not like C, where "if (a)" means "if
(a!=0)". In Exim, more like a BOOLEAN with strict type checking, so
there is well defined set of condition operators you can use with "if"
(and "and"/"or"). If you want to check inside ${if...} if a lookup
returned "1", you have to do that with a condition operator (like "eq").
Even "if" itself is not a condition, i.e. you cannot do something like
${if {$if eq{1}{1}}}.

And there is a "condition" statement in ACLs and routers, which expects
a string (like "yes", which makes not much sense of course) or a string
expansion (like "${lookup ... {true}}" or "${if ... {yes}}", but you can
use a simple "${if eq{some}{thing}}" since 4.50).

So what I did up there is (in your preferred C syntax)

if (recipients == 1)
    return lookup(...);


where lookup() returns 1 or 0. This would be bad style in C, but Exim
invites to do that, because, as I said, you cannot use lookup as a
condition there.

It would have probably been easier (not necessarily better) if Phil
omitted the whole "${if ...}" thing and implemented the conditions as
expansion operators (like "${eq {$a}{$b} {yes}{no}}") instead. But there
are always people having a hard time to understand these things.

> According to the documentation, 'eq' only takes 2 parameters, not 3.


That's right. But your implication is wrong, there are only two
parameters for every "eq" at the top.