GithubHelp home page GithubHelp logo

sayan751 / email-address-parser Goto Github PK

View Code? Open in Web Editor NEW
18.0 4.0 3.0 350 KB

An RFC 5322, and RFC 6532 compliant email address parser.

License: MIT License

Rust 96.69% JavaScript 0.56% TypeScript 2.75%
parser email-address email-address-validator rfc5322 rfc6532

email-address-parser's Introduction

email-address-parser's People

Contributors

gnp avatar joshuaclayton avatar sayan751 avatar techhazard avatar touilleman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

email-address-parser's Issues

The library is not RFC 5322-compliant

More specifically, the RFC defines address as:

address         =   mailbox / group
mailbox         =   name-addr / addr-spec
name-addr       =   [display-name] angle-addr
angle-addr      =   [CFWS] "<" addr-spec ">" [CFWS] /
                       obs-angle-addr
group           =   display-name ":" [group-list] ";" [CFWS]

This library parses only the second case for mailbox - addr-spec, thus the "An RFC 5322, and RFC 6532 compliant email address parser" tagline is misleading

Possible missed test cases

Hi, thanks for creating this Rust crate, I started using it and I like it very much.

I was using these documents to examine intentional email addresses:
https://en.wikipedia.org/wiki/Email_address#Internationalization
https://en.wikipedia.org/wiki/International_email
and I found some cases that don't match.

  1. Marked as invalid, should be valid
    "[email protected]"

  2. Marked as valid, should be invalid
    "1234567890123456789012345678901234567890123456789012345678901234+x@example.com"
    "i_like_underscore@but_its_not_allowed_in_this_part.example.com"

  3. Suggestion: maybe non-trimmed emails should also be returned as invalid:
    " [email protected]"

Maybe these Wikipedia documents are irrelevant for your RFC 5322 and RFC 6532 definitions, but if they are - please double-check.

Thanks and keep up the great work

`is_strict` is ignored

Currently, the is_strict flag gets ignored because these conditionals:

https://github.com/Sayan751/email-address-parser/blob/master/rust-lib/src/email_address.rs#L261-L270

Are equivalent to:

if !RFC5322::parse(Rule::local_part_complete, local_part).is_ok()) {
    /* ... */
}

if !RFC5322::parse(Rule::domain_complete, domain).is_ok()) {
    /* ... */
}

I tried fixing this by changing it to:

if is_strict && !RFC5322::parse(Rule::local_part_complete, local_part).is_ok()) {
    /* ... */
}

if is_strict && !RFC5322::parse(Rule::domain_complete, domain).is_ok()) {
    /* ... */
}

but that caused a bunch of tests to fail that I don't know how to fix.

I suggest using grammar from RFC-5321 + RFC-6531 (specifically Mailbox) vs. RFC-5322

Since you're not attempting the validate email headers from the contents of messages (like From:) you probably want to validate using the SMTP grammar (RFC-5321) which would reject addresses with included white space and newlines, which I assume is what you (and most others) actually want.

You would also get better rules for the domain and IP address literal cases. And it would get rid of most of the obs_ stuff.

Why did you select RFC-5322 as the basis for your syntax? (vs. RFC-5321)

Domains without a dot are accepted in strict mode.

I believe domains without any dots (e.g. "foobar" instead of "foo.bar") are supposed to be illegal, but they are accepted by this library. If I'm wrong, please feel free to make fun of me and close this issue. :)

serde

Reference: #1
Can this be implemented? Current workaround:

use core::fmt;
use email_address_parser::EmailAddress;
use serde::{Deserializer, Serialize, Serializer};
use std::fmt::Debug;

#[derive(Debug, Clone)]
pub struct EmailAddressWrapped(pub EmailAddress);

impl fmt::Display for EmailAddressWrapped {
  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
    write!(f, "{}", self.0.to_string())
  }
}

impl From<String> for EmailAddressWrapped {
  fn from(x: String) -> Self {
    Self(EmailAddress::parse(&x, None).expect("EmailAddress failed to parse."))
  }
}

impl From<&str> for EmailAddressWrapped {
  fn from(x: &str) -> Self {
    Self(EmailAddress::parse(x, None).expect("EmailAddress failed to parse."))
  }
}

impl From<EmailAddress> for EmailAddressWrapped {
  fn from(x: EmailAddress) -> Self {
    Self(x)
  }
}

impl Serialize for EmailAddressWrapped {
  fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
  where
    S: Serializer,
  {
    serializer.serialize_str(&self.to_string())
  }
}

impl<'de> serde::Deserialize<'de> for EmailAddressWrapped {
  fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
    Ok(Self(
      EmailAddress::parse(&String::deserialize(d)?, None).expect("EmailAddress failed to parse."),
    ))
  }
}

Memory management

Hi! I like the design of this library, was going to look into using in a project but noticed the .free() method on the EmailAddress class. Not too familiar with the latest on wasm stuff but appears as though I might need to manually do memory management here and explicitly free an EmailAddress after I'm done with it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.