News for hackers. Stuff that matters.
Re:Stop Validating Email Addresses with Regex (2012) by hathawsh on Wednesday April 20, 2022 @01:37AM (#31093235)
I tried using that expression for a while, but then a user with a valid email address containing upper unicode characters showed up. I switched to a simpler expression:

    ^[^@\s\x00-\x1f]+@[^@\s\x00-\x1f.]+(:?\.[^@\s\x00-\x1f.]+)*$
It requires exactly one "@", disallows whitespace and control characters, prevents repeated dots in the domain name, and ensures the domain doesn't end with a dot. It catches a few typos and I think it allows every real email address I've heard of.
Re:Stop Validating Email Addresses with Regex (2012) by easrng on Wednesday April 20, 2022 @01:43AM (#31093273)
Domains ending with a dot are valid though, and it's needed sometimes. For example, someone@ai. (ai. is a TLD) is a different email than someone@ai (ai is a local hostname)
Re:Stop Validating Email Addresses with Regex (2012) by Biganon on Wednesday April 20, 2022 @08:00AM (#31095637)
I'm pretty sure the one guy behind ai. doesn't justify that you change your regex for him. Let's not be overly pedantic.
Re:Stop Validating Email Addresses with Regex (2012) by Beltalowda on Wednesday April 20, 2022 @06:15AM (#31094779)
> it's needed sometimes

When is this needed in the context of a Rails app? You never want to send emails to local hosts, and emails directly on the TLD is possible, but very little will work with them in practice.

Re:Stop Validating Email Addresses with Regex (2012) by turminal on Wednesday April 20, 2022 @08:02AM (#31095646)
> You never want to send emails to local hosts

That's not entirely true, it depends on how your mailing infrastructure is set up.

Re:Stop Validating Email Addresses with Regex (2012) by Beltalowda on Wednesday April 20, 2022 @08:32AM (#31095912)
But in the context of a web app though? That's the key part: you're taking in email addresses from myapp.example.com. For other cases: sure, local email addresses can be useful (not often these days, but sometimes still are). But in this context I'm not really seeing any use case.
Re:Stop Validating Email Addresses with Regex (2012) by bbatha on Wednesday April 20, 2022 @09:57AM (#31097015)
At previous $work, I wrote a rails app that managed releases. On the app you could sign up for email notifications when your change was released. These went through the unix local email system. So yes there is very much a use case
Re:Stop Validating Email Addresses with Regex (2012) by lolinder on Wednesday April 20, 2022 @11:27AM (#31098326)
It's still a bit silly to tell every SaaS developer that they shouldn't validate that they have a normal-looking domain because some people's use cases call for sending emails to local addresses or to TLDs directly. If a developer needs to handle those cases, they know already, and they're in a vanishingly small minority.
Re:Stop Validating Email Addresses with Regex (2012) by hathawsh on Wednesday April 20, 2022 @01:44AM (#31093287)
Good to know. I guess I'll simplify again. Besides, I wonder whether the expression is vulnerable to catastrophic backtracking.
Re:Stop Validating Email Addresses with Regex (2012) by Supermancho on Thursday April 21, 2022 @12:35PM (#31111671)
> Domains ending with a dot are valid though,

That doesn't mean you have to support their use. I have never seen a company support an email ending in a period and the world seems to continue along.

Re:Stop Validating Email Addresses with Regex (2012) by campital on Wednesday April 20, 2022 @11:05AM (#31098003)
Re:Stop Validating Email Addresses with Regex (2012) by daurnimator on Wednesday April 20, 2022 @08:15AM (#31095759)
Re:Stop Validating Email Addresses with Regex (2012) by qwerty456127 on Wednesday April 20, 2022 @09:30AM (#31096642)
> containing upper unicode characters

Are e-mail addresses case-sensitive? I would always lowercase&trim a string meant to represent an e-mail address (or a domain name) before doing anything else with it.

Re:Stop Validating Email Addresses with Regex (2012) by electroly on Wednesday April 20, 2022 @09:45AM (#31096863)
The local-part before the @ can be case-sensitive, yes. I've never heard of a mail server that treats it as such, but the RFC says it's case sensitive.
Re:Stop Validating Email Addresses with Regex (2012) by hathawsh on Wednesday April 20, 2022 @02:53PM (#31101306)
To be clear, by "upper" unicode characters I mean non-ASCII international characters, not uppercase characters. For example, 我買@屋企.香港 is now a valid email address. [1]

1. https://en.wikipedia.org/wiki/Email_address#Internationaliza...

Re:Stop Validating Email Addresses with Regex (2012) by jeroenhd on Wednesday April 20, 2022 @02:03PM (#31100712)
Not all uppercase characters have just one lowercase representation, and not all lowercase characters have an uppercase character. If you try to make the addresses case insensitive, you're bound to run into unnecessary complexities at some point.

Email addresses aren't case insensitive in nature, but many commercial mail services (and misguided developers) assume they are.

Re:Stop Validating Email Addresses with Regex (2012) by bobbylarrybobby on Wednesday April 20, 2022 @12:23PM (#31099301)
I'm pretty sure email addresses are allowed to have multiple @'s. I believe everything after the first is (supposed to be) considered part of the domain.
Re:Stop Validating Email Addresses with Regex (2012) by chrismorgan on Wednesday April 20, 2022 @01:12PM (#31100012)
Domain labels cannot contain @. If you support comments or quoted strings (e.g. (@)."@"@example) then you can get multiple at signs in an address, but in practice their only use these days is attacks where you confuse a badly-written server, which is part of why the web actively decided to disallow them.
Re:Stop Validating Email Addresses with Regex (2012) by eadmund on Wednesday April 20, 2022 @02:44PM (#31101190)
> in practice their only use these days is attacks where you confuse a badly-written server

Or, you know, if you actually want to use an at sign in the manner allowed by the RFCs. That's the point of standards: if something is allowed, then … it is allowed.

Refusing to accept behaviour permitted by the standard is just broken.

Re:Stop Validating Email Addresses with Regex (2012) by chrismorgan on Wednesday April 20, 2022 @04:30PM (#31102587)
Usage is what matters. Standards documents only have value as long as people follow them; once enough people deviate, they cease to have meaning. This is thoroughly the case with a lot of stuff pertaining to email: if you want to parse arbitrary emails, for example, the relevant MIME RFCs are altogether insufficient, because too many people have done it incorrectly de jure, often to the point where it’s no longer incorrect de facto because everyone supports the deviation. (This is a deviation from spec in the direction of permission.)

By hearsay alone, I say: comments and quoted strings in email addresses are, de facto, more or less dead. Comments especially, which were intended just as a compatibility measure for stuff from over forty years ago (when this was being developed organically, before there was any real spec). Most software whose direct business is email (that is, MUAs and MTAs) will more or less support them for historical reasons, but newer MUAs are likely not to support them in full (again especially comments), and I suspect the considerable majority of other software that deals in email addresses won’t support one or both of them. (This is a deviation from spec in the direction of restriction.)