Header field extraction and classification (noreply/system-sender detection) over foundation-mail-message::Email
| Tier | infrastructure |
| Role | unclassified (baselined) |
| Path | crates/infrastructure/mail-headers |
| Edition | 2021 |
| Targets | infrastructure_mail_headers, oq4_provider_evidence |
| Public items | 5 across 2 modules |
| Tests | 28 |
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
classifyfrom_address
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`
| Item | What it is |
|---|---|
pub enum MailClass | A mail's inferred class. |
fn classify(email : & Email) -> MailClass | Classify 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`
| Item | What it is |
|---|---|
pub struct ParsedFrom | A 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.
| Export | Defined 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) |
| Location | crates/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.
| Crate | Tier | Optional | Only on |
|---|---|---|---|
| `foundation-mail-message` | foundation | no | always |
Development, in this workspace.
| Crate | Tier | Optional | Only on |
|---|---|---|---|
| `infrastructure-adapters-google-gmail` | infrastructure | no | always |
Development, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
chrono | ^0.4 | serde | no | always |
mailparse | ^0.15 | — | no | always |
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
| Kind | Name | Source |
|---|---|---|
| lib | infrastructure_mail_headers | `src/lib.rs` |
| test | oq4_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
| Property | Evidence |
|---|---|
| async public surface | none detected |
| async runtime | none detected |
| database access | none detected |
| network I/O | none detected |
| unsafe code | none detected |
| environment variables | none 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.
Related capabilities
No workspace crate depends on this one.
Verification
| Kind | Count |
|---|---|
| Unit tests | 24 |
| Integration tests | 4 |
| Examples | 0 |
| Doctests | 0 |
Evidence by module. How often each public module is named by something executable.
| Module | Tests | Examples | Consumers |
|---|---|---|---|
classify | 2 | 0 | 0 |
from_address | 3 | 0 | 0 |
What the tests establish, by name:
gmail_and_imap_shaped_email_classify_identically_for_the_same_logical_message—tests/oq4_provider_evidence.rsgmail_and_imap_shaped_promotional_newsletter_classify_identically—tests/oq4_provider_evidence.rsgmail_shaped_personal_message_classifies_as_personal—tests/oq4_provider_evidence.rsimap_shaped_personal_message_classifies_as_personal—tests/oq4_provider_evidence.rshuman_sender_with_transactional_subject_is_transactional_not_system—src/classify.rsin_reply_to_is_a_transactional_signal—src/classify.rslist_unsubscribe_alone_is_enough_for_promotional—src/classify.rsmissing_subject_and_human_sender_is_personal—src/classify.rsnoreply_with_no_transactional_signal_is_unknown_not_personal—src/classify.rspersonal_no_markers—src/classify.rspromotional_bulk_newsletter_with_list_unsubscribe—src/classify.rspromotional_precedence_is_case_insensitive—src/classify.rssystem_noreply_with_transactional_subject—src/classify.rstied_auto_submitted_and_list_id_signals_land_unknown—src/classify.rstransactional_receipt_keyword—src/classify.rsunparseable_from_address_is_treated_as_not_noreply—src/classify.rsdetects_noreply—src/from_address.rsextracts_domain_and_root_domain—src/from_address.rsextracts_from_angle_brackets—src/from_address.rshuman_sender_is_not_machine—src/from_address.rsinvalid_email_returns_none—src/from_address.rslowercases_email—src/from_address.rsmachine_sender_matches_hyphen_and_plus_suffixes—src/from_address.rsparse_email_from_none_on_empty_from—src/from_address.rsparse_email_from_reads_the_from_field—src/from_address.rspreserves_plus_alias—src/from_address.rsquoted_sender—src/from_address.rstrims_whitespace—src/from_address.rs
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 5 | 5 |
Public modules with a //! block | 2 | 2 |
pie showData
title Public items with rustdoc
"Documented" : 5
"No rustdoc detected" : 0
Metrics
| Metric | Value |
|---|---|
| Rust source files | 3 |
| Source lines | 552 |
| Code lines | 335 |
| Public API items | 5 |
| Public modules | 2 |
| Tests | 28 |
| Examples | 0 |
| Cargo features | 0 |
| Direct runtime dependencies | 1 |
| Workspace reverse dependencies | 0 |
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.