jmap-sieve-action

JMAP Sieve Action

Deploy a Sieve script to a JMAP server implementing RFC 9661, including Stalwart. The root action deploys and verifies the stored bytes and activation; the optional verify/ action only checks existing remote state. No external Go dependencies.

- uses: actions/checkout@v4
- uses: arran4/jmap-sieve-action@main
  with:
    server: https://mail.example.com
    username: ${{ secrets.JMAP_USER }}
    password: ${{ secrets.JMAP_PASSWORD }}
    script: filters.sieve

For read-only drift detection, use arran4/jmap-sieve-action/verify@main with the same inputs. Pin a reviewed commit for production. Use either username/password or token, not both. The optional name defaults to the local filename. The optional account-id overrides the primary account. Activation defaults to true; activate: false preserves existing activation state. For verify, require-active: false checks only contents.

Session discovery starts at /.well-known/jmap and uses the advertised upload, API and download URLs. TLS validation is mandatory. GET redirects are allowed only between the configured server origin and an explicitly trusted origin; mutation redirects are rejected. If the server advertises a different HTTPS origin, explicitly authorize it using trusted-origin. Credentials are sent only to those origins. Do not trust a hostname you do not control. No automatic retries of mutation requests. Re-running reconciles against current state, and unchanged scripts are not uploaded again. Deployment uses ifInState to avoid overwriting concurrent changes. A failed post-write verification does not roll back the server; rerun with a known-good script to recover. Activating one script deactivates the prior active script.

Stalwart setup

You must create a credential on the mailbox account that owns the Sieve script, not on an unrelated administrator account.

  1. Open the Stalwart Account Manager at the canonical HTTPS hostname configured for your installation. Sign in as the target mailbox owner.
  2. Open Account → Credentials → App Passwords for HTTP Basic authentication, or Account → Credentials → API Keys for Bearer authentication.
  3. Choose Create, set a descriptive name such as GitHub Actions Sieve deployment, and select Replace all permissions (rather than inheriting the account’s full permissions).
  4. Grant the permissions in the table below. Leave the allowed IP list empty if using GitHub-hosted runners, unless you have an appropriate fixed egress address. Choose an expiry and rotation schedule suitable for your deployment.
  5. Create the credential and copy the generated secret immediately. Store it in GitHub Actions repository or environment secrets (Settings → Secrets and variables → Actions). Never commit the secret or include it in logs.
  6. Use the matching authentication inputs below. Do not provide a token and username/password together.

Use the account’s self-service credential screen, not the administrator’s account-editing credential list. Stalwart creates secondary credentials through separate objects.

Required credential permissions

Stalwart permission label Identifier Deploy Verify only
Sign in to the server authenticate Yes Yes
Sign in using email alias addresses authenticateWithAlias If using an alias If using an alias
JMAP: Retrieve Sieve filter script details jmapSieveScriptGet Yes Yes
JMAP: Create new Sieve filter scripts jmapSieveScriptCreate Yes No
JMAP: Modify existing Sieve filter scripts jmapSieveScriptUpdate Yes No
JMAP: Upload new blob data jmapBlobUpload Yes No
JMAP: Download blob data jmapBlobGet Yes Yes

Do not grant arbitrary blob access, blob store administration, mail import, or script deletion. These actions do not require those permissions. Permission labels can vary by Stalwart version. See the permission reference, app passwords and API keys.

GitHub secrets and workflow

For an app password, set JMAP_USER and JMAP_PASSWORD using gh secret set JMAP_USER and gh secret set JMAP_PASSWORD in your consuming repository. Each command prompts for its value.

For an API key, run gh secret set JMAP_TOKEN and paste the generated API key when prompted. The action uses Bearer authentication:

- uses: arran4/jmap-sieve-action@main
  with:
    server: https://mail.example.com
    token: ${{ secrets.JMAP_TOKEN }}
    script: filters.sieve

A separate read-only verification job may use a second, more restricted credential and arran4/jmap-sieve-action/verify@main with the same server and script inputs. Use immutable reviewed commits for production until releases are available.

Troubleshooting

Inputs

Input Deploy Verify Default
server Required Required HTTPS server origin (a /jmap suffix is accepted)
script Required Required Local script file path
username Basic auth Basic auth None
password Basic auth Basic auth None
token Bearer auth Bearer auth None
name Optional Optional Local filename
account-id Optional Optional Primary Sieve account from the session
rewrite-origin Optional Optional None; map an explicitly named advertised HTTPS origin to the configured server origin
trusted-origin Optional Optional None; extra explicitly trusted HTTPS origin
activate Optional Not applicable true
require-active Not applicable Optional true

Provide exactly one authentication method. The action uses Go 1.23.x via setup-go and works on GitHub-hosted Linux, macOS and Windows runners. It needs repository read permission to access the checked-out script, not GitHub write permission. The mail credential is independent of GITHUB_TOKEN.

Testing before deployment

Run the local interpreter action first, using fixture pairs as described in the Stalwart Sieve Test Action documentation. The example below gates deployment on the fixture tests and never exposes deployment credentials to pull-request code.

name: Test and deploy filters
on:
  push:
    branches: [main]
    paths: ['filters.sieve', 'testcases/**', '.github/workflows/sieve.yml']
  pull_request:
  workflow_dispatch:
permissions:
  contents: read
concurrency:
  group: sieve-deployment
  cancel-in-progress: false
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: arran4/stalwart-sieve-test-action@main
        with:
          script: filters.sieve
          cases: testcases
  deploy:
    if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: arran4/jmap-sieve-action@main
        with:
          server: https://mail.example.com
          username: ${{ secrets.JMAP_USER }}
          password: ${{ secrets.JMAP_PASSWORD }}
          script: filters.sieve

Pin reviewed versions or commit SHAs before using this workflow with production credentials. Use a dedicated staging mailbox to check a new deployment: deploy a synthetic script, deploy it again to check idempotence, then use the read-only verify action. Finally, exercise representative live deliveries. The local interpreter does not model all SMTP envelope or server-side routing behavior.

Local execution and contributor tests

Run go test ./... and go vet ./... in this repository. TLS mock-server tests cover different temporary and permanent blob IDs, idempotent deployment, content mismatches, trusted GET redirects, untrusted endpoints and mutation redirect rejection. CI runs the tests on Linux, Windows and macOS. Real-server interoperability is a separate check; a green mock test does not establish it.

You can also run the client directly: set JMAP_SERVER, JMAP_USERNAME and JMAP_PASSWORD (or JMAP_TOKEN), JMAP_SCRIPT, and optionally JMAP_NAME and JMAP_TRUSTED_ORIGIN in the environment, then run go run .. Set JMAP_MODE=verify for read-only verification; JMAP_REQUIRE_ACTIVE=false permits an inactive matching script. Do not put secrets into shell history.

Reverse proxies

If a server advertises an internal or direct HTTPS origin but a public reverse proxy serves the same JMAP paths, prefer fixing the server’s public URL. Alternatively, set rewrite-origin to the exact advertised HTTPS origin (for example https://mail-internal.example.com) and set server to the HTTPS proxy origin. Only URLs matching that exact origin are rewritten; paths and query strings are preserved. Credentials go to the configured proxy, and TLS remains mandatory. Use this only when both origins refer to the same JMAP service. This does not change discovery or redirect policy. Unlike trusted-origin, it does not grant permission to contact the advertised origin. The direct client equivalent is JMAP_REWRITE_ORIGIN.

Certificate errors

An unknown certificate authority on any advertised endpoint means that endpoint’s certificate chain is not trusted by the runner. Configure the server to advertise its intended publicly trusted HTTPS origin, or install the correct trusted CA on a controlled runner. An extra trusted-origin does not bypass certificate validation. Check the certificate and advertised JMAP URLs before retrying; do not use insecure TLS flags.

License

MIT.