[exim] Expansion weirdness

Top Page
Delete this message
Reply to this message
Author: Sven Eschenberg
Date:  
To: exim-users
Subject: [exim] Expansion weirdness
Hi list,

Maybe I got something fundamentally wrong regarding expansions, but I am
seeing a behavior I consider a little inconsistent.

exim -oMi 127.0.0.1 -be '${extract{$received_ip_address}{10.0.0.1=hosta
127.0.0.1=local4 ::1=local6}{$value}fail}'
local4

(expected)

exim -oMi 127.0.0.2 -be '${extract{$received_ip_address}{10.0.0.1=hosta
127.0.0.1=local4 ::1=local6}{$value}fail}'
Failed: "extract" failed and "fail" requested

(expected)

exim -be '${extract{$received_ip_address}{10.0.0.1=hosta
127.0.0.1=local4 ::1=local6}{$value}fail}'
Failed: first argument of "extract" must not be empty

That was somewhat expected, the docs say the key must not consist of all
digits. There's no hint on what happens if the key is empty.

Anyhow using such an expansion on smtp_active_hostname yields a panic,
while a forced fail (second example) will result in smtp_active_hostname
being set to $primary_hostname (as documented)

Question is: Why do different failures yield different behavior? Does
exim assume that an empty key is an error state and thus handles the
expansion for smtp_active_hostname differently (as some type of hinting
for the user).

But let's go on, actually something else struck me in the first place.
Let's safeguard the extract:

exim -oMi 10.0.0.1 -be '${if def:received_ip_address{yes}fail}'
yes

(expected)

exim -be '${if def:received_ip_address{yes}fail}'
Failed: "if" failed and "fail" requested

(again expected)

Now let's put everything together:

exim -oMi 10.0.0.1 -be '${if
def:received_ip_address{${extract{$received_ip_address}{10.0.0.1=hosta
127.0.0.1=local4 ::1=local6}{$value}fail}}fail}'
hosta

(expected)

exim -oMi 10.0.0.2 -be '${if
def:received_ip_address{${extract{$received_ip_address}{10.0.0.1=hosta
127.0.0.1=local4 ::1=local6}{$value}fail}}fail}'
Failed: "extract" failed and "fail" requested

(expected)

exim -be '${if
def:received_ip_address{${extract{$received_ip_address}{10.0.0.1=hosta
127.0.0.1=local4 ::1=local6}{$value}fail}}fail}'
Failed: missing or misplaced { or }

Wait! What? Why?
I can not fail in the <true> branch of an if, or rather, if I make use
of forced fails in a <true> branch the <false> branch produces a syntax
error? This looks a little unreasonable, but let's look at a different case:

exim -oMi 10.0.0.1 -be '${if def:received_ip_address{${if
eq{10.0.0.1}{$received_ip_address}{hosta}fail}}fail}'
hosta

(again expected)

exim -oMi 10.0.0.2 -be '${if def:received_ip_address{${if
eq{10.0.0.1}{$received_ip_address}{hosta}fail}}fail}'
Failed: "if" failed and "fail" requested

(same as before, thus expected)

exim -be '${if def:received_ip_address{${if
eq{10.0.0.1}{$received_ip_address}{hosta}fail}}fail}'
Failed: "if" failed and "fail" requested

(same as ... eeerh .. hold on right there)

It does make a difference what type of expansion I use in the <true>
branch of an if when forcing failure in <true> with respect to the
result of the <false> branch's forced fail?

What am I missing here?


Thanks for your input

-Sven