email validation: verify only MX, with a 7s timeout (#43422)

This commit is contained in:
Thomas NOËL 2020-05-28 16:14:43 +02:00
parent 2122f9d955
commit ee2adbbf49
1 changed files with 7 additions and 14 deletions

View File

@ -44,7 +44,6 @@ except ImportError:
try:
import DNS
DNS.ParseResolvConf()
except (ImportError, IOError):
DNS = None
@ -900,21 +899,15 @@ class EmailWidget(StringWidget):
except UnicodeError:
self.error = _('invalid address domain')
return
# simply lookup host name; note it will fail if hostname
# doesn't have an A entry
try:
socket.gethostbyname(domain)
except socket.error:
# will fail on lack of DNS module or MX lookup failure
if domain == 'localhost':
return
if DNS is not None:
DNS.ParseResolvConf()
try:
l = len(DNS.mxlookup(force_str(domain)))
except:
l = 0
if l == 0:
if not DNS.mxlookup(force_str(domain), timeout=7):
self.error = _('invalid address domain')
except DNS.DNSError:
self.error = _('invalid address domain')
else:
# and then, localpart could be tested
pass
class ValidationCondition(Condition):