mailidator 0.1.0

A lightweight Rust library for checking email address misspellings
Documentation
# Mailidator

A lightweight Rust library for checking email address misspellings and suggesting corrections.

## Installation

Add this to your `Cargo.toml`:

```toml
[dependencies]
mailidator = "0.1.0"

# If you need Serde support
mailidator = { version = "0.1.0", features = ["serde"] }
```

## Basic Usage

```rust
use mailidator::Mailidator;

fn main() {
    let checker = Mailidator::default();
    
    // Common Gmail typos
    if let Some(suggestion) = checker.check("user@gmaik.com") {
        println!("Did you mean: {}?", suggestion.full());
        println!("User: {}", suggestion.address());
        println!("Domain: {}", suggestion.domain());
        // Output: Did you mean: user@gmail.com?
    }
    
    // No suggestion for correct email addresses
    assert!(checker.check("user@gmail.com").is_none());
}
```

## Custom Configuration

```rust
use mailidator::{Mailidator, Config};

fn main() {
    let mut config = Config::default();
    
    // Add organization-specific domains
    config.domains.extend(vec![
        "company.org".to_string(),
        "internal.local".to_string(),
    ]);
    
    // Stricter matching settings
    config.threshold = 0.3;
    
    let checker = Mailidator::new(config);
    
    if let Some(suggestion) = checker.check("user@compny.org") {
        println!("Suggestion: {}", suggestion.full());
        // Output: Suggestion: user@company.org
    }
}
```

## Practical Example

```rust
use mailidator::Mailidator;

fn validate_email_with_suggestion(email: &str) -> Result<String, String> {
    let checker = Mailidator::default();
    
    // Basic format validation
    if !email.contains('@') || email.starts_with('@') || email.ends_with('@') {
        return Err("Invalid email format".to_string());
    }
    
    // Check for typos
    match checker.check(email) {
        Some(suggestion) => {
            Err(format!("Did you mean '{}'?", suggestion.full()))
        }
        None => {
            Ok(email.to_string())
        }
    }
}

fn main() {
    let test_emails = vec![
        "user@gmail.com",       // Valid
        "user@gmaik.com",       // Typo
        "invalid-email",        // Invalid format
    ];

    for email in test_emails {
        match validate_email_with_suggestion(email) {
            Ok(valid_email) => {
                println!("✓ '{}' is valid", valid_email);
            }
            Err(error) => {
                println!("✗ '{}': {}", email, error);
            }
        }
    }
}
```

## Supported Domains

This library supports the following popular domains:

### Major Providers
- Gmail (gmail.com)
- Yahoo (yahoo.com, yahoo.co.jp, yahoo.co.uk, etc.)
- Outlook/Hotmail (outlook.com, hotmail.com)
- iCloud (icloud.com)
- AOL (aol.com)

### Other Providers
- ProtonMail, Zoho, Fastmail, Tutanota
- Regional variations (.co.uk, .co.jp, etc.)
- Corporate and educational domains

## API Reference

### `Mailidator`

```rust
impl Mailidator {
    // Create checker with default settings
    pub fn default() -> Self
    
    // Create checker with custom settings
    pub fn new(config: Config) -> Self
    
    // Check email address and return suggestion if available
    pub fn check(&self, email: &str) -> Option<Suggestion>
}
```

### `Suggestion`

```rust
impl Suggestion {
    // Get the local part (before @)
    pub fn address(&self) -> &str
    
    // Get the suggested domain
    pub fn domain(&self) -> &str
    
    // Get the complete corrected email address
    pub fn full(&self) -> String
}
```

### `Config`

```rust
pub struct Config {
    pub domains: Vec<String>,              // Popular domains list
    pub second_level_domains: Vec<String>, // Second-level domains
    pub top_level_domains: Vec<String>,    // Top-level domains
    pub threshold: f64,                    // String distance threshold (0.0-1.0)
}
```

## License

Apache-2.0 License

## Contributing

Bug reports, feature requests, and pull requests are welcome!

## References

- [Sift3 Algorithm]https://siderite.com/blog/super-fast-and-accurate-string-distance.html