Skip to main content

sieve_kit/
lib.rs

1//! `sieve-kit` — rule-based mail filtering engine.
2//!
3//! Defines filter rules (conditions + actions), evaluates them against
4//! messages implementing the [`Filterable`] trait, and produces action plans
5//! for a mail engine to execute. This crate is synchronous and I/O-free: all
6//! rule evaluation is deterministic and testable without storage.
7//!
8//! Beyond the RFC 5228 core the typed model also covers the widely used
9//! extensions: SMTP `envelope` tests (RFC 5228 §5.1), IMAP flag mutations
10//! (RFC 5232), and evaluated-only `vacation` (RFC 5230) and `notify`
11//! (RFC 5436) actions — see the README feature table.
12//!
13//! # Security
14//!
15//! Regex evaluation is bounded (100 ms post-check). Invalid patterns are
16//! treated as non-matching (never panic). Actions are returned as values;
17//! executing them is the caller's responsibility. Vacation replies are
18//! *evaluated* (routed, deduped) but never sent.
19//!
20//! # Example
21//!
22//! ```
23//! use sieve_kit::eval::{evaluate_rule, RegexCache};
24//! use sieve_kit::types::{
25//!     Condition, ConditionField, FilterRule, LogicOp, MailEnvelope, Operator,
26//! };
27//!
28//! let rule = FilterRule {
29//!     id: "r1".into(),
30//!     name: "Newsletters".into(),
31//!     enabled: true,
32//!     priority: 0,
33//!     conditions: vec![Condition {
34//!         field: ConditionField::Subject,
35//!         operator: Operator::Contains,
36//!         value: "digest".into(),
37//!         negate: false,
38//!     }],
39//!     condition_logic: LogicOp::And,
40//!     actions: vec![],
41//! };
42//! let msg = MailEnvelope {
43//!     subject: "Weekly digest".into(),
44//!     ..MailEnvelope::default()
45//! };
46//! assert!(evaluate_rule(&rule, &msg, &RegexCache::default()));
47//! ```
48
49#![forbid(unsafe_code)]
50#![deny(missing_docs)]
51
52pub mod actions;
53pub mod error;
54pub mod eval;
55pub mod types;
56
57pub use actions::{
58    FilterMatch, PlannedAction, VacationReply, VacationTracker, apply_flag_plan, collect_matches,
59};
60pub use error::FilterError;
61pub use eval::{
62    EvalContext, EvalOutcome, EvalWarning, RegexCache, ascii_numeric_eq, evaluate_plan,
63    extract_address_part,
64};
65pub use types::{
66    Action, AddressPart, Condition, ConditionField, EnvelopePart, FieldValues, FilterRule,
67    Filterable, Flag, KNOWN_NOTIFY_SCHEMES, LogicOp, MailEnvelope, Notify, Operator, Vacation,
68};