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//! # Security
9//!
10//! Regex evaluation is bounded (100 ms post-check). Invalid patterns are
11//! treated as non-matching (never panic). Actions are returned as values;
12//! executing them is the caller's responsibility.
13//!
14//! # Example
15//!
16//! ```
17//! use sieve_kit::eval::{evaluate_rule, RegexCache};
18//! use sieve_kit::types::{
19//! Condition, ConditionField, FilterRule, LogicOp, MailEnvelope, Operator,
20//! };
21//!
22//! let rule = FilterRule {
23//! id: "r1".into(),
24//! name: "Newsletters".into(),
25//! enabled: true,
26//! priority: 0,
27//! conditions: vec![Condition {
28//! field: ConditionField::Subject,
29//! operator: Operator::Contains,
30//! value: "digest".into(),
31//! negate: false,
32//! }],
33//! condition_logic: LogicOp::And,
34//! actions: vec![],
35//! };
36//! let msg = MailEnvelope {
37//! subject: "Weekly digest".into(),
38//! ..MailEnvelope::default()
39//! };
40//! assert!(evaluate_rule(&rule, &msg, &RegexCache::default()));
41//! ```
42
43#![forbid(unsafe_code)]
44#![deny(missing_docs)]
45
46pub mod actions;
47pub mod error;
48pub mod eval;
49pub mod types;
50
51pub use actions::{FilterMatch, PlannedAction, collect_matches};
52pub use error::FilterError;
53pub use eval::RegexCache;
54pub use types::{
55 Action, Condition, ConditionField, FieldValues, FilterRule, Filterable, Flag, LogicOp,
56 MailEnvelope, Operator,
57};