Look, your email validation logic is very, very likely wrong.

A few examples:
Email addresses can contain multiple '@'s.

Well, SMTP "RCPT TO" anyway, where this is valid:

@1st.relay,@2nd.relay:user@final.domain

MTAs generally don't relay them any more, but most seem to accept and deliver to user@final.domain.
Bang paths may be accepted.

No, not what you think, you pig. UUCP. This is valid:

relay.domain!user@domain

Your MTA will probably reject this as an attempt to relay, but, hey, it's valid, although RFC5321 does not tell you to treat "!" special.
Likewise, you can try to relay via the "%-hack":

user%final.domain@1st.relay

Try it out and see if your MTA will try to deliver to "final.domain" or "1st.relay"...
Hey, about that "!" and "%"... they are not special. RFC5321 allows all sorts of punctuation. For example, this is a valid email address:

'*+-/=?^_`{|}~#$@netmeister.org

(Though I don't know what Twitter turns this into.)
Plus signs aren't special, except when they are.

Gmail and Outlook decided to use "plus addressing" and deliver all of these to the same mailbox:

jdoe@domain
jdoe+whatever@domain
jdoe+somethingelse@domain

But nobody said you have to.
Dots, however, _are_ special.

Gmail ignores them, so "jdoe@gmail.com" and "j.d.o.e@gmail.com" end up in the same mailbox, but there's no reasin that has to be the case.

However, you can't start or end a local part with a "." or have multiple consecutive dots.
Unless, of course, you quote 'em.

Which makes the following all valid:

".jdoe"@domain
"jdoe."@domain
"jd..oe@domain"
Oh, hey, if we can quote things, then we can do all sorts of other shenanigans, and call these valid, too:

" "@netmeister.org
"<>"@netmeister.org
"put a literal escaped newline here\^M <--"@domain
The local part is case-sensitive.

These two are _different_ mailboxes:

jschauma@netmeister.org
JschauMa@netmeister.org
If your MTA supports SMTPUTF8, you can put non-Latin characters in the local part:

"josé.arrañoça"@domain
"сайт"@domain
"💩"@domain
"🍺🕺🎉"@domain
Your local part is limited to 64 octets (but the forward path allows for 256). These two are valid:

~@domain
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~@domain
The domain name does not need to resolve on the internet.

Use SMTP as a hidden service and use a .onion address, like:
local@gtfcy37qyzor7kb6blz2buwuu5u7qjkycasjdf3yaslibkbyhsxub4yd.onion
Hey, we now have internationalized domain names, so the following are valid:

poop@xn--ls8h.la
poop@💩.la
"🌮"@i❤️.ws
jschauma@شبكةمايستر..شبكة
Who needs a domain name at all when you can instead use an IP address literal? These are valid:

jschauma@[166.84.7.99]
jschauma@[IPv6:2001:470:30:84:e276:63ff:fe72:3900]
jschauma@[IPv6:::1]
"[IPv6:::1]"@[IPv6:::1]
Ok, so not all of these will be accepted by all mail servers, but according to the RFCs, they are all valid.

So your initial regex of (?<username>[a-z0-9.-]+)@(?<domain>[a-z0-9.-]+\.[a-z0-9]+) is, I'm afraid, not going to cut it.
This thread as single blog post (with just a little bit more detail):

netmeister.org/blog/email.html

If you have corrections, email me at ^_^@netmeister.org.

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Jan Schaumann

Jan Schaumann Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @jschauma

1 Apr
Oh, lol, looks like Azure DNS is busted right now. That's... gotta hurt.
How’d I notice? I didn’t receive an email to my @FollowStevens address, because my mail server doesn’t talk to MTAs that it can’t reverse the IP address for, which is a great lesson for my students, since we _just_ discussed SMTP and spam protections. 😂

So yeah, “there is no cloud, only other people’s computers” once again.
Read 4 tweets
10 Feb
10 Software Engineering Laws Everybody Loves to Ignore

A Twitter 🧵
1. Conway's Law

Also known as: "You will ship your org chart."

"Any organization that designs a system will produce a design whose structure is a copy of the organization's communication structure."
You may _think_ you can avoid it via cross-functional standup meetings and stakeholder updates and decision matrices, but eventually and inevitably conflicting or diverging priorities will lead to equally conflicting or divergent processes and outcomes.
Read 19 tweets
6 Aug 20
7 battles #infosec has lost but we keep wasting efforts on trying to fight again and again nonetheless:
1) Users will always click on links in emails.

Stop trying to teach them to distinguish "bad" and "good" links. Instead, focus on ensuring their computer cannot be compromised by visiting a website and phished credentials are time-limited or otherwise useless to the attacker.
2) Users will pick bad passwords that they then reuse.

You can get _some_ users to use a password manager, but you can't enforce good passwords and practices. The only real solution is multi-factor auth, preferably via FIDO U2F and/or biometrics.
Read 10 tweets
1 Apr 20
A Few Simple* Rules To Build Scalable Tools

🧵 👇

* "simple", yes, in nature; consistently applying them requires discipline
Don't assume you can write intermediate data to a temporary file. Avoid I/O where possible. Avoid state.

Don't try to read all input into memory. Process as a stream.

When implementing e.g., an HTTP API, don't generate all data in one go. Paginate results.
Don't hardcode assumptions and user- or environment- specific settings. Separate code and config.

Don't leak tokens or passwords. Separate config from secrets.

Don't trust input outside of your control. Assume a hostile environment.
Read 8 tweets
11 Mar 20
So You Have A Jira Queue...

A brief Twitter r̶a̶n̶t̶ 🧵 on responsible ticket management, born out of years of frustration:
There's few things as frustrating in a large organization as diligently filing a ticket or reporting a problem only for it to sit there without anybody looking at it until it's closed by some automated job marking it as stale because it hasn't seen any updates in a year.
If you have a product that warrants a ticket queue, then you owe it to your users to manage it just as you owe it to your team to manage their workload.

Proper ticket management helps you set expectations, drive metrics, gain insights, and allow others to rely on you.
Read 19 tweets
25 Jan 20
(A few) Ops Lessons We All Learn The Hard Way -- a Twitter 🧵:
1. Email is the worst monitoring and alerting mechanism except for all the others.

2. Absence of a signal is itself a signal.

3. The severity of an incident is measured by the number of rules broken in resolving it.
4. The mobile hotspot you're paying for so you can leave your house while you're oncall only works at home and in the office.

5. The only other person who knows how this works is also on vacation.
Read 51 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!