email-validator-rfc5322 0.1.0

RFC 5322 compliant email address validator with detailed error reporting
Documentation
  • Coverage
  • 100%
    22 out of 22 items documented3 out of 4 items with examples
  • Size
  • Source code size: 43.14 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.88 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 26s Average build duration of successful builds.
  • all releases: 26s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • sderosiaux/email-validator-rfc5322
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • sderosiaux

email-validator-rfc5322

CI Crates.io Documentation License: MIT

RFC 5322 compliant email address validator for Rust with detailed error reporting.

Features

  • Full RFC 5322 Section 3.4.1 compliance
  • Quoted local parts ("john doe"@example.com)
  • IP literal domains (user@[192.168.1.1], user@[IPv6:2001:db8::1])
  • All RFC 5322 special characters in local parts
  • RFC 5321 length limits (64 local, 255 domain, 254 total)
  • Detailed error types for debugging

Installation

[dependencies]
email-validator-rfc5322 = "0.1"

Usage

use email_validator_rfc5322::{validate_email, is_valid_email};

// Simple boolean check
if is_valid_email("user@example.com") {
    println!("Valid!");
}

// With detailed error information
match validate_email("invalid..email@example.com") {
    Ok(()) => println!("Valid"),
    Err(e) => println!("Invalid: {}", e), // "consecutive dots not allowed"
}

Valid Email Examples

// Standard addresses
validate_email("user@example.com");
validate_email("user.name@domain.org");
validate_email("user+tag@example.com");

// Quoted strings
validate_email("\"john doe\"@example.com");
validate_email("\"user@domain\"@example.com");

// IP literals
validate_email("user@[192.168.1.1]");
validate_email("user@[IPv6:2001:db8::1]");

// Special characters
validate_email("user!#$%&'*+/=?^_`{|}~@example.com");

Error Types

Error Description
Empty Email string is empty
NoAtSymbol Missing @ symbol
MultipleAtSymbols Multiple @ outside quoted string
LocalPartEmpty Nothing before @
LocalPartTooLong Exceeds 64 characters
DomainEmpty Nothing after @
DomainTooLong Exceeds 255 characters
InvalidLocalPartCharacter Invalid character in local part
InvalidDomainCharacter Invalid character in domain
ConsecutiveDots Contains ..
LeadingDot Starts with .
TrailingDot Ends with .
InvalidQuotedString Malformed quoted string
UnbalancedQuotes Unmatched "
InvalidIPLiteral Invalid IP in [...]
DomainLabelTooLong Label exceeds 63 chars
TotalLengthExceeded Total exceeds 254 chars

RFC Compliance

  • RFC 5322: Internet Message Format (email address syntax)
  • RFC 5321: SMTP (length limits)
  • RFC 1035: DNS (domain label limits)

MSRV

Minimum supported Rust version: 1.80 (for std::sync::LazyLock)

License

MIT