Sieve: setflag with a variable name is accepted without the variables extension

Issue Description

Hi,

RFC 5232 section 1: “When the “variables” extension is not enabled, the explicit variable name parameter to setflag/addflag/removeflag/hasflag MUST NOT be used and MUST cause an error according to [SIEVE].”

Expected Behavior

A compile error.

Actual Behavior

The script compiles and runs. parse_flag_action in crates/sieve/src/compiler/grammar/actions/action_flags.rs takes the first of two strings as a variable name without checking that variables is enabled; hasflag needs the same check.

Relevant Log Output

  1. docker run stalwartlabs/stalwart:v1.2.0 with a RocksDB data store and STALWART_RECOVERY_ADMIN set.
  2. Create domain lab.test and user [email protected]; activate the script below for that user.
  3. Deliver a plain text message to [email protected] over LMTP (MAIL FROM:<[email protected]>): the script runs and the message is stored in INBOX.

Script:

require "imap4flags";
setflag "myvar" "\\Seen";
keep;

Stalwart Version

v1.x

Installation Method

Docker

Database Backend

RocksDB

Blob Storage

RocksDB

Search Engine

Internal

Directory Backend

Internal

Additional Context

Found with a cross-implementation conformance test of JMAP and Sieve servers. Also seen on 1.1.1.

Thanks.

I have reviewed the documentation and FAQ and confirm that my issue is NOT addressed there.

on

I have searched this support forum (open and closed topics) and confirm this is not a duplicate.

on

I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.

on

The source you cited matches your description. I haven’t run your script, and I only read parse_flag_action. I didn’t look at hasflag or the rest of the compiler.

In crates/sieve/src/compiler/grammar/actions/action_flags.rs, parse_flag_action handles setflag, addflag and removeflag. When the first token is a string constant and the next token is a string constant, a string variable or [, it treats the first string as the variable name. It calls parse_variable_name(token_info, false) and builds EditFlags { name: Some(..) }. Nothing in that function checks whether the variables extension is in the script’s require list.

So setflag "myvar" "\\Seen"; with only require "imap4flags"; is accepted. RFC 5232 section 1 says that case MUST be an error.

You also say hasflag needs the same check. I didn’t open its parser, so I can’t confirm that from the source.

The fix would be to return a compile error in that branch when variables isn’t enabled. I don’t know how the compiler tracks enabled extensions, so I haven’t tried to say how to write that check. A staff member or community member will follow up on whether and when this gets changed.

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

Fixed for the next weekly release. The two-argument form of setflag, addflag, removeflag and hasflag now fails to compile unless the script requires variables. Your script gets an error saying the variables capability is not declared. Scripts that require both imap4flags and variables are unaffected.