Writing Custom Sieve Scripts in Webmail and Account Admin

Created by Curtis Hammock, Modified on Sun, 15 Nov at 7:22 PM by Curtis Hammock

Purelymail supports the standard Sieve mail filtering language (RFC 5228), giving you programmatic control over how incoming messages are filed, flagged, redirected, or answered.


1. User Filters in Webmail (or ManageSieve)

To configure filters for an individual mailbox:

  1. Log into Webmail at https://inbox.purelymail.com.
  2. Go to Settings > Filters.
  3. Create filter rules using the visual rule builder (matching Subject, From, To, Size, or headers) or click Actions > Edit filter set to edit raw Sieve code directly.
  4. You can also connect third-party ManageSieve clients directly to mailserver.purelymail.com on port 4190 (STARTTLS; see Server Settings: IMAP, SMTP, POP3, and ManageSieve Protocols).

2. Supported Sieve Extensions

Purelymail supports the following 15 Sieve extensions:

Extension RFC Description
body RFC 5173 Search and match text inside the message body.
envelope RFC 5228 Test the SMTP envelope sender (MAIL FROM) or recipient (RCPT TO).
reject RFC 5429 Refuse delivery and send an automated MDN disposition report.
fileinto RFC 5228 Deliver a message into a specific IMAP mailbox folder.
vacation RFC 5230 Send automated out-of-office autoreplies (default 7-day repeat interval).
vacation-seconds RFC 6131 Configure vacation response intervals down to seconds (minimum 60 seconds).
comparator-i;ascii-numeric RFC 4790 Numeric ASCII comparisons for header and count values.
variables RFC 5229 Declare variables and perform pattern captures and string substitutions.
subaddress RFC 5233 Match :user and :detail parts of tagged subaddresses (user+tag@).
imap4flags RFC 5232 Set or modify IMAP message flags (such as \Seen or \Flagged).
mailbox RFC 5490 Test whether a folder exists (mailboxexists) or create folders on filing (:create).
copy RFC 3894 Add :copy to redirect or fileinto actions without cancelling implicit keep.
spamtest RFC 5235 Evaluate normalized spam scores (0 to 10).
relational RFC 5244 Relational operators (:count, :value with "gt", "ge", "lt", "le", "eq", "ne").
date RFC 5260 Extract and test date or time components from message headers.

3. Account-Wide vs. User-Level Sieve Scripts

Purelymail supports Sieve scripts at two distinct stages in the delivery pipeline (see How Email Routing Rules Combine):

  1. Per-Account Sieve: Configured in the Account Admin portal by clicking Routing and following the per-account Sieve scripts link (or going directly to https://purelymail.com/manage/accountSieve). Runs during domain routing before mail resolves to a specific user mailbox.
  2. User Sieve: Configured in Webmail > Settings > Filters (or via ManageSieve port 4190). Runs for a specific user mailbox right before final delivery.

Behavioral Differences Between User Sieve and Account Sieve

Capability User Sieve Account Sieve Technical Behavior
spamtest & X-Spam-Status Supported Always False / Unset SpamAssassin runs per user mailbox. In Account Sieve, user spam scoring has not run yet.
mailboxexists Supported Always False Account Sieve does not execute inside a specific user's mailbox store.
fileinto Supported Do Not Use with redirect If Account Sieve uses redirect to route an alias to a user, a new recipient object is created for the next routing round and any fileinto folder set in Account Sieve is discarded. Always use fileinto in User Sieve instead.
reject Sends MDN Report Sends MDN Report Runs after SMTP acceptance and sends an RFC 5429 MDN report (suppressed if sender authentication fails or for automated/system mail to prevent backscatter).
vacation Checks user Send-As Checks account Send-As Verifies that the user (or account) is authorized to send from the reply address and that the recipient appears in To/Cc headers.

4. Routing Pipeline & Subaddressing Interactions

  • Matching Subaddress Tags (user+tag@):
    • When Symbolic Subaddressing is enabled on a domain, the envelope recipient is normalized to user@domain.com before Account Sieve runs. In Account Sieve, envelope "to" therefore sees user@domain.com without +tag.
    • In User Sieve, Purelymail restores the pre-subaddressing envelope address (user+tag@domain.com) unless an Account Routing Rule rewrote the recipient in between.
    • Best Practice: To match subaddress tags reliably in both Account Sieve and User Sieve, test the message headers (header :contains "to" "+tag" or address :detail ["to", "cc"] "tag"). Note that Purelymail's :detail extractor supports any symbol delimiter (+, _, -).
  • Keeping a Local Copy When Forwarding: Account Routing Rules perform a pure redirect. To keep a copy in your Purelymail mailbox while forwarding a copy elsewhere, use User Sieve (redirect :copy "other@example.com";).
  • Sieve Runtime Error Notifications: If a Sieve script encounters a runtime error (such as an unauthorized :from address in vacation or exceeding 10 redirect/fileinto actions), Purelymail delivers the incoming email to your inbox normally so no mail is lost, and sends you a diagnostic email with subject [SIEVE ERROR] <original subject> and the original .eml attached.

5. Common Sieve Script Examples

Example 1: Filing Tagged Subaddresses into Folders

  • Location: User Sieve only (Webmail > Settings > Filters).
  • Why: Folder filing requires a user mailbox store. Account Sieve runs before a mailbox is resolved.

require ["fileinto", "subaddress"];

# File emails sent to user+newsletters@ into the Newsletters folder
if address :detail "to" "newsletters" {
    fileinto "Newsletters";
    stop;
}

Example 2: Forwarding a Copy While Keeping a Local Copy

  • Location: User Sieve (Webmail > Settings > Filters) or Account Sieve (Admin > Routing > per-account Sieve).
  • Why: redirect :copy forwards externally without cancelling normal delivery to the inbox.

require ["copy"];

# Forward a copy externally while keeping the message in your inbox
redirect :copy "backup@example.com";

Example 3: Vacation Out-of-Office Autoreply

  • Location: User Sieve (Webmail > Settings > Filters).
  • Why: Vacation replies are intended for individual mailboxes. Setting this in Account Sieve would reply on behalf of every address across the entire domain.

require ["vacation"];

# Send an automated vacation reply at most once every 3 days per sender
vacation
    :days 3
    :subject "Out of Office Notice"
    "Hello, I am currently out of the office and will respond upon my return.";

Example 4: Custom Spam Score Sensitivity

  • Location: User Sieve only (Webmail > Settings > Filters).
  • Why: Purelymail evaluates SpamAssassin scores per user mailbox. In Account Sieve, spam scoring has not run yet.

require ["fileinto", "spamtest", "relational", "comparator-i;ascii-numeric"];

# Purelymail automatically delivers scores of 5.0+ to Junk.
# This files messages scoring 3.0 to 4.9 into Junk as well.
# A SpamAssassin score of 3.0 corresponds to spamtest value "4" (floor(score) + 1).
if spamtest :value "ge" :comparator "i;ascii-numeric" "4" {
    fileinto "Junk";
    stop;
}

Alternatively, you can achieve the same result by matching the X-Spam-Status header directly:


require ["fileinto"];

if header :contains "X-Spam-Status" "score=3." {
    fileinto "Junk";
    stop;
}

Still Need Help?

If you've followed these steps and are still running into trouble, check our Purelymail Support guide.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article