Jim's Depository

this code is not yet written

I wrote swift-sieve, a dependency-free Swift implementation of the email-filtering language from RFC 5228.

I’m ambivalent about Sieve itself. It feels fairly user-hostile, and I’m not convinced many people should write it directly. It may be more useful as an internal representation of a user’s wishes—something generated by a friendlier rules editor. But here this is.

The package compiles a Sieve script once, then evaluates it against an application’s semantic description of a message. The result is an atomic action plan; swift-sieve does not deliver, redirect, reject, or otherwise touch the mail itself.

import Sieve

let source = #"if header :contains "Subject" "meeting" { keep; }"#
let program = try Sieve.compile(source)
let actions = try program.execute(message: message)

It implements the core language, including keep, discard, redirect, header and address tests, plus the fileinto, envelope, and encoded-character extensions. It also supports environment tests, relational comparisons and counts, subaddresses, spam and virus scores, and reject/ereject.

It does not parse raw email or MIME, run spam scanners, deliver messages, speak ManageSieve, or implement the large tail of Sieve extensions. Among the omissions are body, variables, vacation, IMAP flags, date tests, header editing, notifications, include, duplicate detection, and calendar processing. The README has the complete list.

It requires Swift 6.2 and is currently lightly used and experimental. The source is on GitHub.