Background information:
I need to make a system that lets users log in by identifying themselves with an email address/password combination. So I'm trying to find a way to check that the login matches something in the database, when the two may be the same address that's typed differently.
So the initial steps for the domain verification are:
- Convert the entered text to NFC
- Strip comments with a recursive descent parser
- split the local part from the domain.
run the domain through this:
nslookup -type=mx $DOMAIN | awk '{ if($2 =="mail" && $3 == "exchanger") { print substr($6, 0, length($6)-1) } else if($2 == "internet" || $2 == "has") { print $1 } }' | sort | uniq'
Which for both
me.com
andiCloud.com
returns:mx1.mail.icloud.com mx2.mail.icloud.com mx3.mail.icloud.com mx4.mail.icloud.com mx5.mail.icloud.com mx6.mail.icloud.com
And
gmail.com
andgooglemail.com
both return:alt1.gmail-smtp-in.l.google.com alt2.gmail-smtp-in.l.google.com alt3.gmail-smtp-in.l.google.com alt4.gmail-smtp-in.l.google.com gmail-smtp-in.l.google.com
So I thought I would enter this into a table so that all the gmail servers have id 1, and all the iCloud servers have id 2, etc. in whatever order people try to register them in.
This doesn't work if all the servers are in one varchar unit, because servers could be added or removed at a later date. And it doesn't really work if the servers are all given their own row because there's no way to manipulate them as if they were a single logical unit.
If I get the longest common postfix of each server name would that indicate that these all use one mail server? or would it be possible for that to actually serve two servers separated by subdomains?