Re:Is_email()
by johannes1234321 on Wednesday February 22, 2023 @07:15PM
(#34905043)
I would filter out at least whitespaces and comma. Aside from catching typos this also protects against header injection or spam abusenby sending to multiple recipients.
And yes, those should be defended when constructing the mail, but checking early doesn't cost much.
White space and comma are allowed in the local part (left of @), as long as it's surrounded by quotes [https://en.wikipedia.org/wiki/Email_address#Local-part] [https://www.rfc-editor.org/rfc/rfc5322#section-3.2.4]
Has anyone ever seen a quoted local part though?
Honest question! I'd love to hear the details of any specific case where one has ever been used.
Nearly correct. You should also do a DNS lookup on $2 and check if it has either a MX record or an A record before trying to send it.
Re:Is_email()
by hn_throwaway_99 on Wednesday February 22, 2023 @07:31PM
(#34905171)
FWIW the linked library does that, https://github.com/dominicsayers/isemail/blob/master/is_emai...
It looks like it only check for a MX, but email could might be delivered with just an A record and without a MX record I think.
I do almost exactly that, but I replace the stars with plus. I don't think empty name or domain parts are legal?
Should be /^[^@]+@[^@]+$/ at least, because you need something before and after @
It's allowed to have @ as part of the local part if it's quoted. So that wouldn't match my email `"foo@bar"@example.org`
If you need anything more specific the best bet is to try send an email to it.