Skip to main content

Crate sieve_kit

Crate sieve_kit 

Source
Expand description

sieve-kit — rule-based mail filtering engine.

Defines filter rules (conditions + actions), evaluates them against messages implementing the Filterable trait, and produces action plans for a mail engine to execute. This crate is synchronous and I/O-free: all rule evaluation is deterministic and testable without storage.

§Security

Regex evaluation is bounded (100 ms post-check). Invalid patterns are treated as non-matching (never panic). Actions are returned as values; executing them is the caller’s responsibility.

§Example

use sieve_kit::eval::{evaluate_rule, RegexCache};
use sieve_kit::types::{
    Condition, ConditionField, FilterRule, LogicOp, MailEnvelope, Operator,
};

let rule = FilterRule {
    id: "r1".into(),
    name: "Newsletters".into(),
    enabled: true,
    priority: 0,
    conditions: vec![Condition {
        field: ConditionField::Subject,
        operator: Operator::Contains,
        value: "digest".into(),
        negate: false,
    }],
    condition_logic: LogicOp::And,
    actions: vec![],
};
let msg = MailEnvelope {
    subject: "Weekly digest".into(),
    ..MailEnvelope::default()
};
assert!(evaluate_rule(&rule, &msg, &RegexCache::default()));

Re-exports§

pub use actions::FilterMatch;
pub use actions::PlannedAction;
pub use actions::collect_matches;
pub use error::FilterError;
pub use eval::RegexCache;
pub use types::Action;
pub use types::Condition;
pub use types::ConditionField;
pub use types::FieldValues;
pub use types::FilterRule;
pub use types::Filterable;
pub use types::Flag;
pub use types::LogicOp;
pub use types::MailEnvelope;
pub use types::Operator;

Modules§

actions
Action definitions and execution helpers. Actions are value types that describe what to do; the host application translates them into its own mail operations. Evaluation and planning here are pure: no I/O.
error
Error type for filter rule construction and validation.
eval
Rule evaluation engine. Synchronous, bounded, no I/O.
types
Filter rule types: conditions, operators, actions, and the composite rule structure. These types are domain-only (no storage/async dependencies) so they can be evaluated synchronously against any Filterable message.