Re: [exim] Edge case - space separated list objects

Top Page
Delete this message
Reply to this message
Author: Jeremy Harris
Date:  
To: exim-users
Subject: Re: [exim] Edge case - space separated list objects
On 30/09/2019 16:54, Graeme Fowler via Exim-users wrote:
> I'm trying to do some manipulation of the From: field display name section in order to do matching against a remote data source.
>
> To do this, I want to take the name "Fred Bloggs" and turn that into "fredbloggs" and "bloggsfred". That bit is easy, using the sg operator with a match and the resulting $1, $2 item values.
>
> The edge case is that for entities of three or more words (well, actually for the two word case too) I don't want to have to hard-code a set of ever-longer matches and assignments using $3, $4 etc - I'd like to be able to use something to do this dynamically using the map operator. For this I'm trying to use the ${listcount: expansion to give me the number of elements.
>
> However... using a space separated list is proving to be a challenge. Bizarrely:
>
> ${listcount:Fred:Bloggs} == 2 (correct)
> ${listcount:Fred:J:Bloggs == 3 (correct)
>
> yet:
>
> ${listcount:<" "Fred J Bloggs} == 2, because it's taking the first double quote as the separator.
>
> Is there any way at all to specify a space separator for a list? I'm damned if I can work one out!


No; whitespace is special around list elements (Ch 6, section 20) so
there would be Issues in handling space as a separator.

If you're happy there won't be any adjacent spaces, just
${listcount:${tr {Fred J Bloggs}{ }{:}}}

- however, for this untrusted data, perhaps tidying it up by
taking the tr result and using filter with a condition for
nonempty, would be wise.
--
Cheers,
Jeremy