Giter Site home page Giter Site logo

Comments (3)

PascalSchumacher avatar PascalSchumacher commented on May 25, 2024 1

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.

RohanNagar avatar RohanNagar commented on May 25, 2024 1

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.

RohanNagar avatar RohanNagar commented on May 25, 2024

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)

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.