stalwart-sieve-test-action

Stalwart Sieve Test Action

Run Sieve filters against sample email messages using the Stalwart sieve-rs interpreter. No running mail server, account, API key, app password or network access to a mailbox is needed. This is a local behavior test, not a deployment or remote drift check. For deployment use JMAP Sieve Action.

Getting started

Create a Sieve script and a directory containing paired UTF-8 .eml messages and .json expectations. Use the same basename for both files. GitHub-hosted runners provide Rust/Cargo; self-hosted runners must install a compatible stable Rust toolchain before using the action.

permissions:
  contents: read
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: arran4/stalwart-sieve-test-action@v0.1.0
        with:
          script: filters.sieve
          cases: testcases

Use a version tag or pin the reviewed commit SHA. The workflow only requires repository read access. No secrets are necessary.

Example filters.sieve:

require ["fileinto", "imap4flags"];
if header :contains "Subject" "Newsletter" {
    fileinto "News";
} else {
    keep;
}

Example testcases/newsletter.eml:

From: sender@example.org
To: recipient@example.net
Subject: Newsletter

Example message.

Example testcases/newsletter.json:

{"fileinto":["News"],"seen":false}

For a message that does not match, use {"fileinto":[],"seen":false}. For a message expected to be marked as read, set seen to true and ensure the script sets the \\Seen flag. The seen field defaults to false. fileinto is required.

Both folder order and presence of the Seen flag are checked. Missing expectations, invalid scripts, execution errors, mismatches and empty test directories fail the action. Includes resolve relative to the main script directory; paths outside that directory are rejected.

Local execution

Clone this repository and run cargo run --locked -- /path/to/filter.sieve /path/to/testcases. No mail is delivered and no mailbox is changed. The action downloads Rust dependencies from crates.io during its build.

Limitations

The interpreter simulates messages, not a full SMTP or Stalwart server. Mailbox existence, list membership and duplicate checks return false; other external effects are not performed. SMTP envelope and server-side rewriting are not modeled. The assertions currently cover fileinto and Seen only; they do not prove delivery, rejection, redirects or other side effects. Use synthetic fixtures, not private email in public repositories.

Testing and troubleshooting

Run cargo test --locked and cargo run --locked -- examples/filter.sieve examples/testcases to exercise the supplied examples. The CI matrix runs the composite action on Linux, Windows and macOS and checks that mismatched expectations and empty fixture directories fail. A failing assertion prints the case name; fix either the script or its expected JSON and run the tests again. If Cargo is missing, install a stable Rust toolchain. The lockfile pins the interpreter to 0.7.0 for compatibility; results may differ from a newer server version.

License

AGPL-3.0-only. Uses the Stalwart Sieve interpreter, copyright Stalwart Labs, under its AGPLv3 licensing terms. Source code and locked dependencies are available in this repository.