sayan751 / email-address-parser Goto Github PK
View Code? Open in Web Editor NEWAn RFC 5322, and RFC 6532 compliant email address parser.
License: MIT License
An RFC 5322, and RFC 6532 compliant email address parser.
License: MIT License
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."),
))
}
}
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
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.
Marked as invalid, should be valid
"[email protected]"
Marked as valid, should be invalid
"1234567890123456789012345678901234567890123456789012345678901234+x@example.com"
"i_like_underscore@but_its_not_allowed_in_this_part.example.com"
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
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?
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.
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)
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. :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.