mailrs-intelligence
LLM-powered email analysis primitives for Rust — pluggable provider, OpenAI-compatible reference impl, with no-LLM heuristics included.
Extracted from mailrs so any Rust project that needs to classify, summarize, or embed email content can lean on the same primitives without dragging in the entire mail server.
Highlights
- Pluggable backend —
LlmProvidertrait keeps the choice of model visible at the call site, so small-core vs big-core decisions stay grep-auditable in your own code. - OpenAI-compatible reference impl —
OpenAiCompatibleProviderwrapsreqwestand works against any service speaking the standard{system, messages, temperature}shape (self-hosted vLLM, llama.cpp servers, etc.). - Five primitives, one shape — full email analysis (
analyze::analyze_email), spam classification with optional cache (spam::classify), structured-data extraction from JSON-LD (structured::extract_structured_data), heuristic importance scoring (importance::calculate_importance), and embeddings via the provider'sembedmethod. - No-LLM modules —
importanceandstructuredare pure heuristics — they don't need a provider, network, or async runtime. - Optional Redis cache —
RedisSpamCacheis included behind the defaultredis-cachefeature, butSpamCacheis a trait so you can plug in whatever store you have.
Quick start
use Arc;
use ;
# async
Feature flags
| Flag | Default | What it enables |
|---|---|---|
http |
yes | OpenAiCompatibleProvider (reqwest + rustls). Disable if you supply your own LlmProvider. |
redis-cache |
yes | RedisSpamCache for spam::classify. Disable if you cache yourself or run without a cache. |
Disable both default features (default-features = false) if you're plugging in your own backends:
[]
= { = "1", = false }
= "0.1"
Why a trait
Production mail servers tend to mix cheap inference (per-message spam classification, hot path) with rarer expensive calls (deep structured extraction, big context). Letting analysis functions take &dyn LlmProvider keeps the choice of model visible at the call site — you can grep your own code for "which provider does this path hand into analyze_email?" without diving into config or environment variables. That visibility is the whole point of carving the trait out instead of shipping the concrete config struct.
License
Licensed under either of Apache License 2.0 or MIT license at your option.