Skip to main content

utopia_emails/
lib.rs

1//! Email addresses: split at the `@`, checked, made canonical per mail
2//! provider, and their domains classified as free or disposable.
3//!
4//! | PHP | Rust |
5//! |---|---|
6//! | `Utopia\Emails\Email` | [`Email`] |
7//! | `new Email($email)` | [`Email::new`] |
8//! | `get()`, `getLocal()`, `getDomain()` | [`Email::get`], [`Email::local`], [`Email::domain`] |
9//! | `isValid()`, `hasValidLocal()` | [`Email::is_valid`], [`Email::has_valid_local`] |
10//! | `hasValidDomain()` | [`Email::has_valid_domain_syntax`], then the domain's known suffix (`utopia-domains`) |
11//! | `isDisposable()`, `isFree()` | [`Lists::is_disposable`], [`Lists::is_on_free_list`] (`isFree()` also needs it not disposable) |
12//! | `getCanonical()`, `isCanonicalSupported()`, `getCanonicalDomain()` | [`Email::canonical`], [`Email::is_canonical_supported`], [`Email::canonical_domain`] |
13//! | `Email::LOCAL_MAX_LENGTH`, `DOMAIN_MAX_LENGTH` | [`LOCAL_MAX_LENGTH`], [`DOMAIN_MAX_LENGTH`] |
14//! | `data/free-domains.php`, `data/disposable-domains.php` | [`Lists`] ([`Lists::FREE`], [`Lists::DISPOSABLE`]) |
15//! | `Canonicals\Providers\{Gmail, Outlook, Yahoo, Icloud, Protonmail, Fastmail, Walla, Generic}` | [`Provider`] ([`PROVIDERS`], [`Provider::GENERIC`]) |
16//!
17//! What `Email` asks of its domain (`getProvider()`, `getSubdomain()`,
18//! `isKnown()`) is `Utopia\Domains\Domain`'s, which the extension calls
19//! as PHP does, so this crate does not parse domains.
20//!
21//! The lists are embedded in the crate (`data/*-domains.txt`, exported from
22//! the PHP package's `data/*-domains.php` by `data/export.php`) with hash
23//! tables of their lines built at compile time (`build.rs`), so a lookup
24//! allocates nothing and both live in the library's read-only pages, shared by
25//! every process. The PHP validators, providers and import task are not
26//! ported: `Email` is.
27
28#![warn(missing_docs)]
29
30mod canonicals;
31mod email;
32mod error;
33mod lists;
34
35pub use canonicals::{Canonical, PROVIDERS, Provider};
36pub use email::{DOMAIN_MAX_LENGTH, Email, LOCAL_MAX_LENGTH};
37pub use error::Error;
38pub use lists::{DomainList, Lists};
39
40/// The README, compiled and run with the doctests.
41#[cfg(doctest)]
42#[doc = include_str!("../README.md")]
43pub struct ReadMe;