Mailing List Archive

Stumped on router conditions
Hi there,

I have been trying to have one router act when a condition is true, and
the other act when that same condition is not true. The conditions are
LDAP lookups. I'm omitting the specific lookup for privacy reasons. ;)

| > ${lookup ldap{...}{true}{false}}
| true

The lookup is defined as a macro in exim4.conf:
| HAS_FORWARDS = ${lookup ldap{...}{true}{false}}

I tried to have my router like this:
| routerWhenNoForwards:
| debug_print = "routerWhenNoForwards HAS_FORWARDS"
| condition = ! HAS_FORWARDS
| [..]
| no_more
|
| routerWhenForwards:
| debug_print "routerWhenForwards HAS_FORWARDS"
| condition = HAS_FORWARDS
| [..]
|
| otherRouter:
| ...

The lookup works and in '-be' testing yields 'true'.
In '-bt' testing, debug_print also shows that 'true':
| routerWhenNoForwards true

The address tested does indeed have forwards.
So, "! true" must mean "false", right?
That router should not run?
Yet, that routerWhenNoForwards router runs.

I made it work by duplicating the condition LDAP lookup macro and
negating it in the LDAP query. I am now using the 'HAS_NO_FORWARDS'
lookup on the 'WhenNoForwards' router and life is good again, but i
wonder what i am doing wrong?

Am i being bitten by the situation described in the 'Historical note' as
can be found at [1] in the docs? Is there a nicer way to do this than
having two lookups like i have now? That section isn't really clear on
not being able to negate a lookup like i tried...

Actually having two macros might be cleaner / more human readable, and i
think it doesn't really bother me, but still, this cost me a few minutes
before i gave in to having two lookups. ;)

Regards,
-Sander.

[1] https://www.exim.org/exim-html-current/doc/html/spec_html/ch-generic_options_for_routers.html
--
| 42.7 percent of all statistics are made up on the spot.
| 4096R/20CC6CD2 - 6D40 1A20 B9AA 87D4 84C7 FBD6 F3A9 9442 20CC 6CD2

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Stumped on router conditions [ In reply to ]
Ahoj,

D?a Tue, 29 Nov 2022 17:46:42 +0100 Sander Smeenk via Exim-users
<exim-users@exim.org> napísal:

> So, "! true" must mean "false", right?

No, "! true" is just string, not Boolean negation.

From router's condition docs:

The string is expanded, and if the result is a forced failure, or an
empty string, or one of the strings “0” or “no” or “false” (checked
without regard to the case of the letters)...

As "! true" is not "empty string", nor "0", nor "no", nor "false" =>
result is true...

You have to flip results string for negate it in lookup, eg.:

${lookup ldap{...}{true}{false}}

and then

${lookup ldap{...}{false}{true}}

(define your makro only for lookup part)

Or make more detailed expansion, eg.:

${if eq{{YOUR_MACRO}{true} {true}{false}}

regards

--
Slavko
https://www.slavino.sk
Re: Stumped on router conditions [ In reply to ]
Quoting Slavko via Exim-users (exim-users@exim.org):

> > So, "! true" must mean "false", right?
> No, "! true" is just string, not Boolean negation.

Well, yes, if you take that literally.
As aparently 'condition' checks in routers do. ;)

With my programmer mindset it should "expand" to False (0).
Router conditions literally test for the string '', '0' or 'false'.

> You have to flip results string for negate it in lookup, eg.:
> ${lookup ldap{...}{true}{false}}
> and then
> ${lookup ldap{...}{false}{true}}
> Or make more detailed expansion, eg.:
> ${if eq{{YOUR_MACRO}{true} {true}{false}}

Thanks for your time, Slavko. This is what i ended up using!!

Do you think usage of '!' in router conditions should trigger a warning?

Regards,
-Sander.
--
| If I melted dry ice, can I swim without getting wet?
| 4096R/20CC6CD2 - 6D40 1A20 B9AA 87D4 84C7 FBD6 F3A9 9442 20CC 6CD2

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Stumped on router conditions [ In reply to ]
Even simpler -

router1:
condition = ${if ...

router1:
!condition = ${if ...

It's the exact same condition test, but in the first it'll run if the
condition returns true, and in the second if it's false.

Graeme
--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/