User sieve script

Hello,

I want to specify a user sieve script using the json file. Unfortunately, i havent been to find a way to do that.

Here is my workaround,

SIEVE_SCRIPT='require ["fileinto", "mailbox", "imap4flags"];
if header :contains "X-Spam-Status" "Yes" {
    fileinto :create "Junk Mail";
    setflag "\\Seen";
    stop;
}'

# Upload Sieve script content as a blob (binary content)
BLOB_RESPONSE=$(curl -s -u "[email protected]:$STALWART_CONTACT_PASSWORD" \
  -X POST "$STALWART_URL/jmap/upload/$CONTACT_ACCOUNT_ID/" \
  -H 'Content-Type: application/sieve' \
  --data-binary "$SIEVE_SCRIPT")
  
  
SIEVE_RESULT=$(curl -s -u "[email protected]:$STALWART_CONTACT_PASSWORD" \
  -X POST "$STALWART_URL/jmap" \
  -H 'Content-Type: application/json' \
  -d '{
    "methodCalls": [
      [
        "SieveScript/set",
        {
          "create": {
            "spam-filter": {
              "name": "spam-filter",
              "blobId": "'"$BLOB_ID"'",
              "isActive": true
            }
          }
        },
        "c1"
      ]
    ],
    "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:sieve"]
  }')

if echo "$SIEVE_RESULT" | grep -q '"created"'; then
  echo "Spam filter Sieve script created and activated"
else
  echo "Warning: Sieve script creation may have failed"
  echo "Response: $SIEVE_RESULT"
fi

Is it possible to specify in the json file, so i can use stalwart-cli apply to upload it instead of using a script?

Let me look into what the CLI supports for Sieve scripts.

stalwart-cli apply works with JMAP settings/configuration objects — it is not designed to upload Sieve scripts or binary blobs. Sieve scripts live in the mail data layer (uploaded via JMAP SieveScript/set), not in the server configuration layer, so there is no NDJSON representation that stalwart-cli apply can handle for them.

Your current approach — uploading the blob via the JMAP upload endpoint and then calling SieveScript/set — is the correct, supported way to provision per-user Sieve scripts programmatically. This isn’t covered in the current docs as a stalwart-cli workflow.

A community member or staff member may be able to confirm whether a future CLI path for Sieve script provisioning is planned.

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong. If you found it useful, mention @helpbot in any reply to ask follow-up questions and the bot will respond again.

The cli does not support uploading blobs. You’ll have to upload the Sieve blob using curl or with a script.