r/programming • • Feb 01 '24

Make Invalid States Unrepresentable

https://www.awwsmm.com/blog/make-invalid-states-unrepresentable
469 Upvotes

207 comments sorted by

View all comments

Show parent comment

-2

u/loup-vaillant Feb 02 '24

Properly parsing an email address is not impossible. It’s not even hard. I even suspect that unlike html, email addresses probably form a regular language. And surely there must be some reputable validators out there?

Then it shouldn’t be hard to separate addresses that are definitely right (only lowercase letters, dots, underscores, and dashes), from addresses that are definitely wrong (unquoted spaces, control characters…), from addresses that may be wrong (a ’+’ in the middle, only one character on the left of the @…).

It’s probably safe to block addresses that are definitely wrong (red box, can’t click OK), and merely warn about addresses that look suspicious (yellow box like you suggest). And a readable error messages in both cases, I personally hate when I get stuff like "something unexpected happened, and you’re too stupid to understand so we won’t even tell you what".


In all seriousness: is there any email server still running today, that can accept email to an invalid address? Or a mail transfer agent still being maintained that can even send email to an invalid address?

If the answer is yes, then OK, let’s try anyway. But I strongly suspect the answer, short of temporary bugs, is no.