Understanding matches in sieve
Robert L Mathews
lists at tigertech.com
Thu Oct 22 03:04:02 EEST 2020
On 10/21/20 11:15 AM, @lbutlr wrote:
> RFC 5229 gives the following example:
>
> if address :matches ["To", "Cc"] ["coyote@**.com",
> "wile@**.com"] {
> # ${0} is the matching address
> # ${1} is always the empty string
> # ${2} is part of the domain name ("ACME.Example")
> fileinto "INBOX.business.${2}"; stop;
>
> And I do not understand why ${1} is always the empty string.
This is because of the text above that: "The wildcards match as little
as possible (non-greedy matching)."
This example has two wildcards in a row (""**" doesn't mean anything
special beyond that) -- and because the first "*" matches as little as
possible, it matches nothing (the empty string). The second "*" matches
everything between "@" and ".com".
The same thing happens with real regexps:
#!/usr/bin/perl
$x = 'coyote at ACME.Example.COM';
$x =~ /coyote\@(.*?)(.*?)\.COM/;
printf '$1 is "%s"; $2 is "%s"', $1, $2;
This will print:
$1 is ""; $2 is "ACME.Example"
> I am laso not sure why the first example used **.com instead of *.com (or is that the reason $1 doesn't contain anything because it is the first * of **?).
Yes. The example is confusing because it makes it look like "**" is some
magic thing you might want to use. It's not.
--
Robert L Mathews, Tiger Technologies, http://www.tigertech.net/
More information about the dovecot
mailing list