Comments (3)
Thank you very much for the in-depth explanation.
I wasn't aware that white-space is allowed in some places. I noticed that email addresses like these are either rejected by Java Mail or by Apache James Mail Server.
I will use the rule you suggested and later update the code to use the build-in check when/if you add it to JMail.
Thanks again for the fast and detailed response.
from jmail.
Hi @PascalSchumacher this improvement was made and released in version v1.4.1.
You can use it like the following:
EmailValidator validator = JMail.strictValidator().disallowObsoleteWhitespace();
validator.isValid("a@b .com"); // returns false
from jmail.
Hi @PascalSchumacher! Thank you for the nice words 🙂
According to RFC 5322 and RFC 2822 those are valid (although unusual) email addresses.
Essentially, white-space is allowed between dot-separated parts of the local-part and the domain since RFC 822. This has been marked as obsolete in RFC 2822, which means that addresses should not be generated with whitespace, but they should be accepted as valid addresses by an email server, which is why JMail considers them as valid by default.
Appendix A.6.3 shows a valid example with the obsolete whitespace: jdoe@machine(comment). example
All that being said, in practice you may want to consider these addresses as invalid since the syntax is marked as obsolete. One way you could do that is by adding a rule to your validator that checks to make sure both the local-part and the domain do not contain whitespace:
JMail.strictValidator()
.withRule(email -> !email.localPart().matches("\\S+") && !email.domain().matches("\\S+"))
.isValid("a@b .com");
I think it would be a great idea for JMail to provide a rule which will do this kind of check so that you can add it like:
EmailValidator validator = JMail.strictValidator().disallowWhitespace();
I will keep this issue open as a to-do for that enhancement. Will probably not get around to it for another week or so.
from jmail.
Related Issues (20)
- When validation fails, provide a reason to the caller HOT 4
- E-Mail Address Validation on https://www.rohannagar.com/jmail/ broken HOT 4
- Valid email shown as invalid HOT 8
- Question: E-Mail Address with local part containing only slashes valid? HOT 3
- Please either make EmailValidator immutable or support clone() HOT 1
- Provide distinct failure reasons for each built-in rule and provide option for specifying custom failure reasons HOT 1
- Add ability to get the ASCII only version of an Email HOT 5
- Make timeout configurable for DNS MX record lookup HOT 2
- Support for configuring non-ascii characters to be invalid HOT 2
- Provide option to unquote localparts when normalising HOT 2
- Improve email address normalization HOT 1
- StringIndexOutOfBoundsException HOT 2
- My valid emoji email address in the format xyz@🚀.kz is not tested valid HOT 1
- IllegalArgumentException when validating email address ending with "High Octet Preset" control character HOT 5
- Feature request: some sort of email normalization? HOT 3
- Incorrect email HOT 1
- invalid address returning true HOT 2
- Option to validate MX record associated with email domains HOT 5
- Add documentation for all default validation rules HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jmail.