Sieve script execution problem

Your question

Hi there,
I’m using a Sieve script on my account to sort my incoming emails. It mostly works, but I have a very strange behavior with tag matching.

Sieve script (short version) :

require ["fileinto", "mailbox", "variables", "regex", "envelope"];


if header :is "X-Spam-Status" "Yes"
{
    fileinto :create "Quarantine";
    stop;
}

if anyof (
address :all :is "to" "[email protected]",
header :contains "subject" "SMART error"
)
{
    fileinto :create "Root";
    stop;
}

When I receive a mail on my address root and it has the header X-Spam-Status set to Yes, it’s stored in the Root inbox …
I have tested the script (the full version and the actual source of the received email) with https://sieve-tester.com/ , and the result is correct :

Email is kept in inbox

Performed actions:
 * store message in folder: Quarantine
        + create mailbox if it does not exist
Implicit keep:
  (none) 

Did I miss something ? Is it a bug ?

The likely cause is that Stalwart’s X-Spam-Status header does not just contain Yes or No, it also appends the numeric score, e.g. X-Spam-Status: Yes, score=13.45. Since your rule uses header :is "X-Spam-Status" "Yes", and :is requires an exact match of the whole header value, it will never match "Yes, score=13.45" in production. Your test on sieve-tester.com almost certainly used a raw email you crafted with a plain X-Spam-Status: Yes header (no score suffix), which is why it matched there but not on real Stalwart-delivered mail.

Fix by matching on a prefix or substring instead of exact equality, for example:

if header :contains "X-Spam-Status" "Yes"

or, to be safe with case/formatting, :matches "Yes*".

Reference: Overview | Stalwart

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.

I’ve already tried with :contains , same result.
And X-Spam-Status is only Yes or No. There is no score.

That seems to be the reason : Matching Spam header via user sieve script (managesieve) · stalwartlabs/stalwart · Discussion #2637 · GitHub

Unfortunately I don’t think it’s documented.
I can open a PR to fix documentation if it’s useful.