Skip to main content

Crate structured_email_address

Crate structured_email_address 

Source
Expand description

§structured-email-address

RFC 5321/5322/6531 conformant email address parser, validator, and normalizer.

Unlike existing Rust crates that stop at RFC validation, this crate provides:

  • Subaddress extraction: user+tag@domain → separate user, tag, domain
  • Provider-aware normalization: Gmail dot-stripping, configurable case folding
  • PSL domain validation: verify domain against the Public Suffix List
  • Anti-homoglyph protection: detect Cyrillic/Latin lookalikes via Unicode skeleton
  • Configurable strictness: Strict (5321), Standard (5322), Lax (obs-* allowed)
  • Zero-copy parsing: internal spans into the input string

§Quick Start

use structured_email_address::{EmailAddress, Config};

// Simple: parse with defaults
let email: EmailAddress = "user+tag@example.com".parse().unwrap();
assert_eq!(email.local_part(), "user+tag");
assert_eq!(email.tag(), Some("tag"));
assert_eq!(email.domain(), "example.com");

// Configured: Gmail normalization pipeline
let config = Config::builder()
    .strip_subaddress()
    .dots_gmail_only()
    .lowercase_all()
    .build();

let email = EmailAddress::parse_with("A.L.I.C.E+promo@Gmail.COM", &config).unwrap();
assert_eq!(email.canonical(), "alice@gmail.com");
assert_eq!(email.tag(), Some("promo"));

Structs§

Config
Configuration for email address parsing and normalization.
ConfigBuilder
Builder for Config.
EmailAddress
A parsed, validated, and normalized email address.
Error
Error returned when parsing or validating an email address fails.

Enums§

CasePolicy
How to handle letter case.
DomainCheck
How to validate the domain.
DotPolicy
How to handle dots in the local part.
ErrorKind
The specific kind of error that occurred.
Strictness
How strictly to validate RFC grammar.
SubaddressPolicy
Whether to strip +subaddress tags.

Functions§

confusable_skeleton
Compute confusable skeleton for anti-homoglyph protection.