Ignore records missing spaces.
This commit is contained in:
@@ -47,6 +47,9 @@ For news, bugfixes, etc. visit the home page for this implementation at
|
|||||||
# Terrence is not responding to email.
|
# Terrence is not responding to email.
|
||||||
#
|
#
|
||||||
# $Log$
|
# $Log$
|
||||||
|
# Revision 1.14 2005/08/12 17:36:51 customdesigned
|
||||||
|
# Trean non-existant include as no match in "lax" mode.
|
||||||
|
#
|
||||||
# Revision 1.13 2005/07/22 16:00:23 customdesigned
|
# Revision 1.13 2005/07/22 16:00:23 customdesigned
|
||||||
# Limit CNAME chains independently of DNS lookup limit
|
# Limit CNAME chains independently of DNS lookup limit
|
||||||
#
|
#
|
||||||
@@ -285,6 +288,10 @@ def DNSLookup(name,qtype):
|
|||||||
except DNS.DNSError,x:
|
except DNS.DNSError,x:
|
||||||
raise TempError,'DNS ' + str(x)
|
raise TempError,'DNS ' + str(x)
|
||||||
|
|
||||||
|
def isSPF(txt):
|
||||||
|
"Return True if txt has SPF record signature."
|
||||||
|
return txt.startswith('v=spf1 ') or txt == 'v=spf1'
|
||||||
|
|
||||||
# 32-bit IPv4 address mask
|
# 32-bit IPv4 address mask
|
||||||
MASK = 0xFFFFFFFFL
|
MASK = 0xFFFFFFFFL
|
||||||
|
|
||||||
@@ -590,7 +597,11 @@ class query(object):
|
|||||||
|
|
||||||
# split string by whitespace, drop the 'v=spf1'
|
# split string by whitespace, drop the 'v=spf1'
|
||||||
#
|
#
|
||||||
spf = spf.split()[1:]
|
spf = spf.split()
|
||||||
|
#Catch case where SPF record has no spaces
|
||||||
|
if spf[0] != 'v=spf1':
|
||||||
|
raise PermError('Invalid SPF record in', self.d)
|
||||||
|
spf = spf[1:]
|
||||||
|
|
||||||
# copy of explanations to be modified by exp=
|
# copy of explanations to be modified by exp=
|
||||||
exps = self.exps
|
exps = self.exps
|
||||||
@@ -815,11 +826,11 @@ class query(object):
|
|||||||
is found.
|
is found.
|
||||||
"""
|
"""
|
||||||
# for performance, check for most common case of TXT first
|
# for performance, check for most common case of TXT first
|
||||||
a = [t for t in self.dns_txt(domain) if t.startswith('v=spf1')]
|
a = [t for t in self.dns_txt(domain) if isSPF(t)]
|
||||||
if len(a) == 1 and self.strict < 2:
|
if len(a) == 1 and self.strict < 2:
|
||||||
return a[0]
|
return a[0]
|
||||||
# check official SPF type first when it becomes more popular
|
# check official SPF type first when it becomes more popular
|
||||||
b = [t for t in self.dns_99(domain) if t.startswith('v=spf1')]
|
b = [t for t in self.dns_99(domain) if isSPF(t)]
|
||||||
if len(b) == 1:
|
if len(b) == 1:
|
||||||
# FIXME: really must fully parse each record
|
# FIXME: really must fully parse each record
|
||||||
# and compare with appropriate parts case insensitive.
|
# and compare with appropriate parts case insensitive.
|
||||||
@@ -832,7 +843,7 @@ class query(object):
|
|||||||
if DELEGATE: # use local record if neither found
|
if DELEGATE: # use local record if neither found
|
||||||
a = [t
|
a = [t
|
||||||
for t in self.dns_txt(domain+'._spf.'+DELEGATE)
|
for t in self.dns_txt(domain+'._spf.'+DELEGATE)
|
||||||
if t.startswith('v=spf1')
|
if isSPF(t)
|
||||||
]
|
]
|
||||||
if len(a) == 1: return a[0]
|
if len(a) == 1: return a[0]
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user