Mailing List Archive

Express list in reduce?
Hello,

If I’ve defined a domain list thus:

domainlist mydomains = foo.com : bar.com

… is there any way to pass that domain list to, e.g, ${reduce}?

For testing purposes I’d like to do something like:

-----
${reduce {+mydomains}{}{${if eq{$value}{}{}{$value,}}$item}}
-----

… and have it give me “mydomains”, joined with a comma.

Alternatively, is it possible to express a filter/grep of such a list?

Thank you in advance!

cheers,
-Felipe Gasper
--
## 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: Express list in reduce? [ In reply to ]
On 02/04/2021 17:08, Felipe Gasper via Exim-users wrote:
> domainlist mydomains = foo.com : bar.com
>
> … is there any way to pass that domain list to, e.g, ${reduce}?
>
> For testing purposes I’d like to do something like:
>
> -----
> ${reduce {+mydomains}{}{${if eq{$value}{}{}{$value,}}$item}}
> -----
>
> … and have it give me “mydomains”, joined with a comma.

${listnamed_d:mydomains} as source for your reduce.

Bear in mind that you a vulnerable to list elements
that already have an embedded comma, and ones with
an embedded colon may surprise you.


It'd be nicer if listnamed had a way of getting a
custom output separator, and/or if reduce did full
list expansion, of course.
--
Cheers,
Jeremy

--
## 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: Express list in reduce? [ In reply to ]
> On Apr 2, 2021, at 2:02 PM, Jeremy Harris via Exim-users <exim-users@exim.org> wrote:
>
> On 02/04/2021 17:08, Felipe Gasper via Exim-users wrote:
>> domainlist mydomains = foo.com : bar.com
>> … is there any way to pass that domain list to, e.g, ${reduce}?
>> For testing purposes I’d like to do something like:
>> -----
>> ${reduce {+mydomains}{}{${if eq{$value}{}{}{$value,}}$item}}
>> -----
>> … and have it give me “mydomains”, joined with a comma.
>
> ${listnamed_d:mydomains} as source for your reduce.
>
> Bear in mind that you a vulnerable to list elements
> that already have an embedded comma, and ones with
> an embedded colon may surprise you.
>
>
> It'd be nicer if listnamed had a way of getting a
> custom output separator, and/or if reduce did full
> list expansion, of course.

So, the list in question is defined thus:

domainlist manualmx_domains = ${if exists {/etc/manualmx} {lsearch;/etc/manualmx} {} }

When I expand ${listnamed_d:manualmx_domains}, I get just the definition part of the above. So that doesn’t help.

I also tried expanding:

${if forany{${listnamed:manualmx_domains}}{eq {$item}{domain.tld}}{yes}{no}}

… where “domain.tld” is the domain I’m looking for, but still no dice.

I also tried:

${if inlist{domain.tld}{${listnamed:manualmx_domains}}{yes}{no}}

… but that doesn’t work, either.

I assume the issue is that the list is defined as dynamic … is there any expansion string that handles that?

Thank you!

cheers,
-Felipe
--
## 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: Express list in reduce? [ In reply to ]
On 05/04/2021 16:34, Felipe Gasper via Exim-users wrote:
> domainlist manualmx_domains = ${if exists {/etc/manualmx} {lsearch;/etc/manualmx} {} }

That's not a valid definition for a named list.

I suspect you've misread "lists are (string-) expanded before use" as meaning
that list *definitions* can have string-expansions. Not so. The string-expansion
is done on the text that should be a list, when some text is arrived at in the
context of a list being needed.

> I assume the issue is that the list is defined as dynamic … is there any expansion string that handles that?

Dynamic? What?

--
Cheers,
Jeremy

--
## 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: Express list in reduce? [ In reply to ]
> On Apr 5, 2021, at 11:44 AM, Jeremy Harris via Exim-users <exim-users@exim.org> wrote:
>
> On 05/04/2021 16:34, Felipe Gasper via Exim-users wrote:
>> domainlist manualmx_domains = ${if exists {/etc/manualmx} {lsearch;/etc/manualmx} {} }
>
> That's not a valid definition for a named list.
>
> I suspect you've misread "lists are (string-) expanded before use" as meaning
> that list *definitions* can have string-expansions. Not so. The string-expansion
> is done on the text that should be a list, when some text is arrived at in the
> context of a list being needed.

Hrm. It … works for us? Is this something that happens to work but is undocumented?

The router that uses that list, at least, seems to work as we intend:

manualmx:
driver = manualroute
domains = +manualmx_domains
transport = remote_smtp
route_data = ${lookup{$domain}lsearch{/etc/manualmx}}

Or am I misunderstanding?

-F
--
## 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: Express list in reduce? [ In reply to ]
On 05/04/2021 18:51, Felipe Gasper via Exim-users wrote:
>> On Apr 5, 2021, at 11:44 AM, Jeremy Harris via Exim-users <exim-users@exim.org> wrote:
>>
>> On 05/04/2021 16:34, Felipe Gasper via Exim-users wrote:
>>> domainlist manualmx_domains = ${if exists {/etc/manualmx} {lsearch;/etc/manualmx} {} }
>>
>> That's not a valid definition for a named list.
>>
>> I suspect you've misread "lists are (string-) expanded before use" as meaning
>> that list *definitions* can have string-expansions. Not so. The string-expansion
>> is done on the text that should be a list, when some text is arrived at in the
>> context of a list being needed.
>
> Hrm. It … works for us? Is this something that happens to work but is undocumented?

Indeed, hrm. Turns out I was wrong, having been speaking without
actually reading through the code to check.

Most uses of lists get a string-expansion first, handled by the
routine that does a search in a list. But the "listnamed" operator
is doing something different, expanding a possibly-nested list, and
uses different code which does neither a string-expansion step
nor any lookup-equivalent expansions.

The string-expansion step could be regarded as a bug, because two uses
of a list object behave differently (anyone volunteering for doing the devel work?)
- but it seem infeasible to do a generic expansion for all possible
types of lookup which could be embedded as list elements.

So no, there's no way to re-cast the keys content of an lsearch file
as a comma-sep list. Perhaps you could write some custom perl
and use the ${perl} expansion.

--
Cheers,
Jeremy

--
## 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/