Skip to Content

Save and activate filter rules.

Replaces the JSON filter rules for this mailbox, compiles them into a Sieve script, and activates them for incoming mail delivery.

openemail.rules.set(
  mailboxId: string,
  body: RulesDocument,
  options?: CallOptions,
): ApiPromise<FilterRulesPutResult>

It calls PUT /mailboxes/{mailboxId}/rules: Save and activate filter rules in the API reference.

Example

const filterRulesPutResult = await openemail.rules.set(mailboxId, { rules: [{ conditions: [], actions: [] }] })

Arguments

ArgumentTypeDescription
mailboxIdstringMailbox ULID identifier. The path's {mailboxId}.
bodyRulesDocumentThe request's body.

Options

It takes no options of its own. 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, FilterRulesPutResult. It is an ApiPromise: .withResponse() gives the same with the Response it came in, for its headers.

Errors

StatusWhat it means
400validation_failed — malformed rules document; 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 save 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
404Mailbox not found or not accessible to this principal
409too_many_scripts; or mailbox_is_group_persona — a group persona's archive runs no rules
413too_large — rules document exceeds size limit (48 KiB)
422invalid_script — rules compile to an oversized or invalid Sieve script
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

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