# email-validator-rfc5322
[](https://github.com/sderosiaux/email-validator-rfc5322/actions/workflows/ci.yml)
[](https://crates.io/crates/email-validator-rfc5322)
[](https://docs.rs/email-validator-rfc5322)
[](https://opensource.org/licenses/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
```toml
[dependencies]
email-validator-rfc5322 = "0.1"
```
## Usage
```rust
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
```rust
// 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
| `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