Clarification about sieve rules needed ... :contains with or without anyof/allof?

1

1

I started refining my sieve rules recently and became a bit unsure about how :contains actually works. I checked out http://sieve.mozdev.org/reference.html but it still didn't clear up the question I had.

Say I have the following rule:

if
    header :contains ["List-Id", "X-Mailinglist", "X-Mailing-List"] [
        "ros-dev.reactos.org",
        "ros-general.reactos.org"
    ]
{
    fileinto "Lists/ReactOS";
    stop;
}

does this mean (and that would be my idea of how I want it to work) automatically that any of the listed header fields ["List-Id", "X-Mailinglist", "X-Mailing-List"] should contain any of the given values ["ros-dev.reactos.org", "ros-general.reactos.org"] or need I say explicitly if anyof (...) like this?:

if anyof (
    header :contains ["List-Id", "X-Mailinglist", "X-Mailing-List"] [
        "ros-dev.reactos.org",
        "ros-general.reactos.org"
    ]
)
{
    fileinto "Lists/ReactOS";
    stop;
}

... for this desired outcome? Or do the two lists not match each element of the first against each element of the second list anyway?

NB: I know that the comma-separated conditions are affected by anyof and allof respectively. So if anyof (condition1, condition2) means (pseudo-code) if (condition1 or condition2) and if allof (condition1, condition2) means if (condition1 and condition2). Understanding this aspect is not my problem.

What I fail to understand, though, is whether anyof and allof respectively influence either or both of the lists in a :contains clause. In the above example there is a list for the header fields and a list of values to match against.


Essentially the question boils down to whether or not there is a semantic difference between the two above snippets. And if not, then whether the first one means this:

if anyof (
    header :contains ["List-Id", "X-Mailinglist", "X-Mailing-List"] "ros-dev.reactos.org",
    header :contains ["List-Id", "X-Mailinglist", "X-Mailing-List"] "ros-general.reactos.org"
)
{
    fileinto "Lists/ReactOS";
    stop;
}

... or this:

if allof (
    header :contains ["List-Id", "X-Mailinglist", "X-Mailing-List"] "ros-dev.reactos.org",
    header :contains ["List-Id", "X-Mailinglist", "X-Mailing-List"] "ros-general.reactos.org"
)
{
    fileinto "Lists/ReactOS";
    stop;
}

... or something else altogether.

0xC0000022L

Posted 2015-06-20T13:09:29.650

Reputation: 5 091

Answers

1

anyof means that if any single header contains one of the alternative values, then the whole condition become true, nevertheless the rest headers contains something else.

anyof ALSO becomes true when all the headers contains the predefined values. This is the relaxed condition.

allof ONLY becomes true when all the headers contains the predefined values. This is the strict condition.

Kondybas

Posted 2015-06-20T13:09:29.650

Reputation: 499

thanks for your time, but this is exactly the part that I understood already. I needed no clarification for that part. However, I added some more sentences in the hope that I can explain what I'm after. – 0xC0000022L – 2015-06-20T15:10:56.490

0

As the reference you indicated as well as the RFC 3028 specification says for the header test,

The "header" test evaluates to true if any header name matches any key.

That is, each header name is compared to each value, and if any of the cross-product is a match, then the test passes. The comparator specified (:contains in your case) is used for each individual comparison. Basically, your first re-write into anyof is correct.

The use of anyof and allof is when there are multiple tests that you want to use, but sometimes you can pack a lot of logic into one "test", as you have here.

user169501

Posted 2015-06-20T13:09:29.650

Reputation: