infrastructure capa

infrastructure-mail-headers

Header field extraction and classification (noreply/system-sender detection) over foundation-mail-message::Email

Header field extraction and classification (noreply/system-sender detection) over foundation-mail-message::Email

Tierinfrastructure
Roleunclassified (baselined)
Pathcrates/infrastructure/mail-headers
Edition2021
Targetsinfrastructure_mail_headers, oq4_provider_evidence
Public items5 across 2 modules
Tests28

What it is for

# infrastructure-mail-headers

Header field extraction and classification (noreply/system-sender detection) over foundation_mail_message::Email.

Refactored, not ported, from rust-gmail-manager/src/headers/{service, classify,parser}.rs (Gate 4.5 provenance — see CHANGELOG.md). The source's parser.rs::parse_from_gmail_headers walked a raw Vec<(String, String)> of Gmail API header pairs (From, Message-ID, In-Reply-To, List-Id, List-Unsubscribe, Precedence, Auto-Submitted) pulled straight from infrastructure_adapters_google_gmail::Message's JSON. This crate never touches that shape or IMAP's raw RFC5322 bytes — it reads only foundation_mail_message::Email, the provider-agnostic type both infrastructure-adapters-google-gmail and infrastructure-imap already convert into.

OQ4 finding (sprint 3.45 doc), resolved 2026-08-10

Email (crate 1, crates/foundation/mail-message) used to be deliberately flat — id, thread_id, folders, from, to, cc, bcc, subject, date, parts only, no arbitrary RFC5322 headers. Concretely, neither infrastructure-adapters-google-gmail::email_from_message nor infrastructure-imap's rfc822_to_email copied Message-ID, In-Reply-To, List-Id, List-Unsubscribe, Precedence, or Auto-Submitted into the Email they built, despite both providers' raw sources carrying them. TD-MAIL-EMAIL-NO-RAW-HEADERS (docs/TECH-DEBT.md) tracked this as debt rather than a bug in crate 1 — Gate 4.5's first-consumer rule wanted a second consumer to ratify widening Email before it landed. An independent Gate 4 review of this crate ratified the fix: Email gained six Option<String> fields for those exact headers, and both real converters now populate them from the raw headers they already parse.

Consequence: mm's original classify_mail_type scored five signals (list_unsubscribe, list_id, precedence, auto_submitted, in_reply_to) plus subject keywords plus noreply-sender detection to produce five classes (personal/transactional/promotional/system/unknown). All five signals now survive through Email, and classify restores mm's exact scoring and precedence rules — see classify.rs's module doc comment for the full breakdown. MailClass::Promotional is back.

tests/oq4_provider_evidence.rs runs this crate's real Gmail-shaped and IMAP-shaped Email values (not hand-built stand-ins) through from_address::parse_email_from and classify::classify to prove the full signal set — including the six restored headers — parses and classifies identically across both real providers.

Capabilities

MailClass

Mail class classification (personal / transactional / promotional /

Item
pub enum MailClass
fn classify(email : & Email) -> MailClass

ParsedFrom

From address parsing: display name / local part / domain extraction,

Item
pub struct ParsedFrom
fn parse_from_address(raw : & str) -> Option <ParsedFrom>
fn parse_email_from(email : & Email) -> Option <ParsedFrom>

How to use it

No examples/ target and no doctest in this crate's rustdoc. The tests listed under Verification are the closest executable usage.

Module structure

infrastructure_mail_headers

flowchart TD
  n_infrastructure_mail_headers["infrastructure_mail_headers"]
  n_infrastructure_mail_headers --> n_classify["classify"]
  n_infrastructure_mail_headers --> n_from_address["from_address"]

Public surface

`classify`

ItemWhat it is
pub enum MailClassA mail's inferred class.
fn classify(email : & Email) -> MailClassClassify an Email using mm's original five-signal scoring (List-Unsubscribe/List-Id/Precedence for promotional, Auto-Submitted/In-Reply-To/subject keywords for transactional, plus noreply-sender detection) — see the module doc comment for the exact score contributions and final precedence rules.

`from_address`

ItemWhat it is
pub struct ParsedFromA parsed From address: display name / local part / domain, plus noreply and machine-sender classification.
fn parse_from_address(raw : & str) -> Option <ParsedFrom>Parse a raw From header value ("Name <email@domain>", a bare email@domain, or a quoted-name variant) into its parts
fn parse_email_from(email : & Email) -> Option <ParsedFrom>Convenience: parse the from field straight off an Email.

Re-exports. Exported here, defined elsewhere.

ExportDefined in
{classify,MailClass}classify::{classify,MailClass}
{parse_email_from,parse_from_address,ParsedFrom}from_address::{parse_email_from,parse_from_address,ParsedFrom}

Boundary

Reaches into foundation.

Shares tier infrastructure with 82 other crates: infrastructure-acquire, infrastructure-adapters-google-calendar, infrastructure-adapters-google-gmail, infrastructure-adapters-google-places, infrastructure-adapters-google-trends, infrastructure-adapters-shodan, infrastructure-adapters-yelp, infrastructure-agent, … (82 total).

_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._

Where it sits

Tier (ontology)infrastructure
Architectural role (taxonomy)unclassified (baselined)
Locationcrates/infrastructure/mail-headers
Vocabulary in force (lexicon)current

Tier flow. Which tiers this crate's own edges cross.

flowchart LR
  n_infrastructure["infrastructure"] --> n_foundation["foundation"]

Dependencies

Runtime, in this workspace.

CrateTierOptionalOnly on
`foundation-mail-message`foundationnoalways

Development, in this workspace.

CrateTierOptionalOnly on
`infrastructure-adapters-google-gmail`infrastructurenoalways

Development, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
chrono^0.4serdenoalways
mailparse^0.15noalways

Build. None.

Depended on by. Nothing in this workspace.

Signal flow — what reaches this crate, and what it reaches.

flowchart LR
  SELF["infrastructure-mail-headers"]
  SELF -->|development| n_infrastructure_adapters_google_gmail["infrastructure-adapters-google-gmail"]
  SELF -->|runtime| n_foundation_mail_message["foundation-mail-message"]
  classDef self fill:#1f883d,stroke:#1f883d,color:#fff;
  class SELF self;

Feature flags

No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.

Targets

KindNameSource
libinfrastructure_mail_headers`src/lib.rs`
testoq4_provider_evidence`tests/oq4_provider_evidence.rs`

Error model

No public error type was detected: no public item declares a type named *Error, and no public signature returns one.

Operational characteristics

PropertyEvidence
async public surfacenone detected
async runtimenone detected
database accessnone detected
network I/Onone detected
unsafe codenone detected
environment variablesnone detected

No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.

Configuration

No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.

No workspace crate depends on this one.

Verification

KindCount
Unit tests24
Integration tests4
Examples0
Doctests0

Evidence by module. How often each public module is named by something executable.

ModuleTestsExamplesConsumers
classify200
from_address300

What the tests establish, by name:

Documentation coverage

MeasureDocumentedTotal
Public items with rustdoc55
Public modules with a //! block22
pie showData
    title Public items with rustdoc
    "Documented" : 5
    "No rustdoc detected" : 0

Metrics

MetricValue
Rust source files3
Source lines552
Code lines335
Public API items5
Public modules2
Tests28
Examples0
Cargo features0
Direct runtime dependencies1
Workspace reverse dependencies0
pie showData
    title Public API by kind
    "enum" : 1
    "function" : 3
    "struct" : 1
pie showData
    title Rust source composition
    "Code" : 335
    "Blank or comment" : 217

Generation

Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.

Todas las infrastructure · Manual