email-validator-rfc5322
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
[]
= "0.1"
Usage
use ;
// Simple boolean check
if is_valid_email
// With detailed error information
match validate_email
Valid Email Examples
// Standard addresses
validate_email;
validate_email;
validate_email;
// Quoted strings
validate_email;
validate_email;
// IP literals
validate_email;
validate_email;
// Special characters
validate_email;
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