#address #string-parser #validation #newtype

email_address

A Rust crate providing an implementation of an RFC-compliant EmailAddress newtype

11 releases

0.2.9 Jul 31, 2024
0.2.8 Jul 31, 2024
0.2.4 Nov 2, 2022
0.2.3 Aug 9, 2022
0.1.0 Mar 24, 2020

#2 in Email

Download history 49766/week @ 2024-08-02 49258/week @ 2024-08-09 44674/week @ 2024-08-16 49499/week @ 2024-08-23 57061/week @ 2024-08-30 65587/week @ 2024-09-06 54057/week @ 2024-09-13 65260/week @ 2024-09-20 69705/week @ 2024-09-27 74457/week @ 2024-10-04 70155/week @ 2024-10-11 92064/week @ 2024-10-18 97326/week @ 2024-10-25 94107/week @ 2024-11-01 97649/week @ 2024-11-08 90233/week @ 2024-11-15

396,005 downloads per month
Used in 300 crates (53 directly)

MIT license

66KB
1.5K SLoC

Crate email_address

A Rust crate providing an implementation of an RFC-compliant EmailAddress newtype.

MIT License Minimum Rust Version crates.io docs.rs Build Audit GitHub stars

Primarily for validation, the EmailAddress type is constructed with FromStr::from_str which will raise any parsing errors. Prior to constructions the functions is_valid, is_valid_local_part, and is_valid_domain may also be used to test for validity without constructing an instance.

Status

Currently, it supports all the RFC ASCII and UTF-8 character set rules as well as quoted and unquoted local parts but does not yet support all the productions required for SMTP headers; folding whitespace, comments, etc.

Example

use email_address::*;

assert!(EmailAddress::is_valid("user.name+tag+sorting@example.com"));

assert_eq!(
    EmailAddress::from_str("Abc.example.com"),
    Error::MissingSeparator.into()
);

Specifications

  1. RFC 1123: Requirements for Internet Hosts -- Application and Support, IETF,Oct 1989.
  2. RFC 3629: UTF-8, a transformation format of ISO 10646, IETF, Nov 2003.
  3. RFC 3696: Application Techniques for Checking and Transformation of Names, IETF, Feb 2004.
  4. RFC 4291 IP Version 6 Addressing Architecture, IETF, Feb 2006.
  5. RFC 5234: Augmented BNF for Syntax Specifications: ABNF, IETF, Jan 2008.
  6. RFC 5321: Simple Mail Transfer Protocol, IETF, Oct 2008.
  7. RFC 5322: Internet Message Format, I ETF, Oct 2008.
  8. RFC 5890: Internationalized Domain Names for Applications (IDNA): Definitions and Document Framework, IETF, Aug 2010.
  9. RFC 6531: SMTP Extension for Internationalized Email, IETF, Feb 2012
  10. RFC 6532: Internationalized Email Headers, IETF, Feb 2012.

Changes

Version 0.2.9

  • Fixed bug #21: Invalid Unicode characters accepted.

Version 0.2.8

  • Fixed bug #29: Put back implementation of Eq.

Version 0.2.7

  • Feature: added builder functions to the Option type.
  • Documentation: added examples to the Option type documentation.

Version 0.2.6

  • Fix: merge issues.

Version 0.2.5

  • Feature: Pull Request #15 -- Potential enhancement to add any free-text as display name.
  • Feature: Pull Request #17 -- Check for non-alphanumeric character starting or ending domain parts.
  • Feature: Pull Request #18 -- Error with SubDomainEmpty when empty instead of InvalidCharacter.
  • Feature: Pull Request #19 -- Allow configuring minimum number of subdomains.
  • Feature: Pull Request #20 -- Add option to disallow domain literals.
  • Feature: Pull Request #22 -- Handle a single qoute in local part of email

Thanks to ghandic, blaine-arcjet, Thomasdezeeuw.

Version 0.2.4

  • Fixed bug #11:
    1. Add manual implementation of PartialEq with case insensitive comparison for domain part.
    2. Add manual implementation of Hash, because above.
  • Change signature for new_unchecked to be more flexible.
  • Add as_str helper method.

Version 0.2.3

  • Added new EmailAddress::new_unchecked function (Sören Meier).

Version 0.2.2

  • Removed manual Send and Sync implementation, and fixed documentation bug (Sören Meier).

Version 0.2.1

  • Added From<EmailAddress> for String.
  • Added AsRef<str for EmailAddress.
  • Added local_part and domain accessors.
  • More unit tests, especially for the list above.
  • Added more conditions to the warning and deny list.
  • Fixed some Clippy warnings.
  • Fixed a bug in encoding the mailto URI scheme.

Version 0.2.0

  • Added UTF-8 support.
  • Added more test cases, fixing defects in parsing.
  • Method to_uri now supports URI encoding the address as a part of the URI.
  • Added is_valid_local_part and is_valid_domain methods.

Version 0.1.0

  • Basic type implementation and structure based on RFC 5322.
  • See TODO.

TODO

  1. Support comments.
  2. Support line-feed and whitespace rules.
  3. Does not parse into domain-literal values, only does surface syntax check.

Dependencies

~160KB