Skip to main content

Crate mailrs_sieve

Crate mailrs_sieve 

Source
Expand description

Clean delivery-action wrapper over Stalwart’s sieve crate (RFC 5228 Sieve email filtering language + the common extensions: fileinto, vacation, reject, redirect, …).

Stalwart’s sieve crate exposes a low-level event-loop API (Runtime::filter(msg).run(input) returning a stream of sieve::Event variants the caller has to translate into their own delivery actions). That’s powerful but every consumer ends up writing the same translation layer. This crate IS that translation layer, plus the small extras a real MTA needs:

  • created_messages tracking so vacation / notify reply bodies are matched to their SendMessage events
  • Envelope (From / To) injection for :envelope tests and vacation auto-reply addressing
  • One SieveAction enum the caller pattern-matches against in its delivery loop

Pure compile + evaluate: no I/O, no async. Plug into any script-storage layer (PG, file, in-memory) and any delivery backend (Maildir, IMAP, JMAP).

§Quick start

use mailrs_sieve::{compile_sieve, evaluate_sieve_with_envelope, SieveAction};

let script = "fileinto \"INBOX/spam\";";
let compiled = compile_sieve(script).unwrap();
let message = b"From: a@b.c\r\nSubject: t\r\n\r\nbody";
let actions = evaluate_sieve_with_envelope(
    &compiled, message, Some("a@b.c"), Some("me@d.e")
);
assert!(matches!(actions[0], SieveAction::FileInto(ref f) if f == "INBOX/spam"));

Enums§

SieveAction
One delivery decision produced by evaluate_sieve_with_envelope. The caller’s delivery loop pattern-matches and executes the corresponding storage / forwarding / DSN action.

Functions§

compile_sieve
compile a Sieve script, returning the compiled form
evaluate_sieve
evaluate a compiled Sieve script against a message
evaluate_sieve_with_envelope
evaluate a compiled Sieve script against a message with envelope information for vacation/auto-reply support