Skip to Content

Upload or replace a Sieve filter script.

Uploads or updates a Sieve script. The script is validated for syntax before saving. Returns error 422 if compilation fails.

openemail.sieve.putScript(
  mailboxId: string,
  scriptName: string,
  body: SievePutScriptBody,
  options?: SievePutScriptOptions,
): ApiPromise<SievePutResult>

It calls PUT /mailboxes/{mailboxId}/sieve/scripts/{scriptName}: Upload or replace a Sieve filter script in the API reference.

Example

const sievePutResult = await openemail.sieve.putScript(mailboxId, scriptName, { script: '…' })

Arguments

ArgumentTypeDescription
mailboxIdstringMailbox ULID identifier. The path's {mailboxId}.
scriptNamestringSieve script name. The path's {scriptName}.
bodySievePutScriptBodyThe request's body.

Options

The last argument, options, a SievePutScriptOptions, takes:

OptionTypeSent asDescription
ifNoneMatchstringheader if-none-matchSet to "*" for create-only: prevents overwriting an existing script of the same name

Every call also takes signal, timeout, retry and headers, which say how that one call is sent (call options).

Answer

Awaited, it is the API's JSON, SievePutResult. It is an ApiPromise: .withResponse() gives the same with the Response it came in, for its headers.

Errors

StatusWhat it means
400validation_failed — malformed name or body; or destination_is_self / destination_loops / destination_chain_too_long when a redirect target routes back to this mailbox; or destination_unverified when a redirect target this write introduces has not been confirmed as a forwarding destination
401unauthorized: the bearer credential is missing, malformed, expired, or revoked. Carries a WWW-Authenticate: Bearer challenge
403reserved — this script name is reserved for JSON rules
404Mailbox not found or not accessible to this principal
409too_many_scripts, name_exists, or mailbox_is_group_persona (a group persona's archive runs no script)
413too_large: JSON request body exceeds 1 MiB or 500,000 values (object keys included), checked before parsing
422invalid_script — Sieve syntax error with line and column
503temporary_failure: the mailbox or account is in transition while its store is being adopted; retry after Retry-After

A failed call rejects with a RequestError: its status, and its code, the API's error. Decide on the code: one status covers several.

Types

SievePutScriptBody

/** The body of `sieve.putScript`. */
type SievePutScriptBody = {
  /** Sieve script source code */
  script: string
}

It names these types of the API, each on a page of its own: SievePutResult.