On Mon, 3 Oct 2005, Marc Haber wrote:
> >I don't understand what you mean by "an exim string expansion" as a type
> >of query, I'm afraid. Can you give an example?
>
> |${lookup eximexp{/some/file eq{${extract{1}{:}{$line}fail}{some-string}}{found-string}{not-found-string}}
>
> which will return found_string (expanded with the values from the
> found line) if there was any line in /some/file for which the "eq"
> expression (or whatever else it might be) was true.
OK. I see. You want to invent a new variable called $line which is
instantiated with the contents of each line in the file in turn; an
expansion is then applied[*]; if it succeeds, the found-string is expanded
and returned. If the end of the file is reached, the not-found string is
expanded.
But I'm not sure how you specify "the values from the found line". The
only thing you have is $line, containing the whole line.
I must say that I think this is overly complicated, and at the moment I
can't see that it gains you anything compared with using a regex. I
think the equivalent of the above is
${lookup regex{/some/file ^some-string:}{found-string}{not-found-string}}
(which, with a small change or two, can be made into lsearch, so it
isn't actually very interesting!)
---------
[*] Actually, you haven't written an expansion; you've written a
condition from an ${if expansion. Using such a condition outside an ${if
is something new. This means that your new kind of lookup could not be
implemented as a separate module that just calls the existing expansion
functions. In fact, the whole thing would require a big re-write of the
expansion code, because the argument to this new query-style lookup is
NOT "a string that has been expanded". You want to delay expansion, and
do it inside the lookup (repeatedly). That would require some massive
re-writing of the expansion code, because at the moment, it does the
expansions of the lookup's argument (the "query") before it calls the
lookup. So all in all, compared with a simple regex, your proposal
implies a very big fundamental code change.
--
Philip Hazel University of Cambridge Computing Service,
ph10@??? Cambridge, England. Phone: +44 1223 334714.
Get the Exim 4 book: http://www.uit.co.uk/exim-book