emails: ignore DNS errors (#36502)

This commit is contained in:
Benjamin Dauvergne 2019-09-28 10:28:02 +02:00
parent 1b98a8e952
commit 083658ee5a
1 changed files with 6 additions and 2 deletions

View File

@ -51,8 +51,12 @@ def validate_email_spf(value, strict=False):
if not allowed_records:
return
email_domain = value.split('@')[-1]
txt_records = sum([r.strings for r in dns.resolver.query(email_domain, 'TXT')], [])
spf_records = [x for x in txt_records if x.startswith('v=spf1 ')]
try:
txt_records = sum([r.strings for r in dns.resolver.query(email_domain, 'TXT')], [])
except dns.exception.DNSException:
spf_records = []
else:
spf_records = [x for x in txt_records if x.startswith('v=spf1 ')]
if not strict and not spf_records:
return
for spf_record in spf_records: