text
stringlengths
1
93.6k
mech = None
if not recursion: # record matching mechanism at base level
self.mechanism = mech
if result == 'fail':
return (result, 550, exps[result])
else:
return (result, 250, exps[result])
def check_lookups(self):
self.lookups = self.lookups + 1
if self.lookups > MAX_LOOKUP*4:
raise PermError('More than %d DNS lookups'%(MAX_LOOKUP*4))
if self.lookups > MAX_LOOKUP:
self.note_error('Too many DNS lookups')
def get_explanation(self, spec):
"""Expand an explanation."""
if spec:
try:
a = self.dns_txt(spec,ignore_void=True)
if len(a) == 1:
return str(self.expand(to_ascii(a[0]), stripdot=False))
except PermError:
# RFC4408 6.2/4 syntax errors cause exp= to be ignored
if self.strict > 1:
raise # but report in harsh mode for record checking tools
pass
elif self.strict > 1:
raise PermError('Empty domain-spec on exp=')
# RFC4408 6.2/4 empty domain spec is ignored
# (unless you give precedence to the grammar).
return None
def expand(self, s, stripdot=True): # macros='slodipvh'
"""Do SPF RFC macro expansion.
Examples:
>>> q = query(s='strong-bad@email.example.com',
... h='mx.example.org', i='192.0.2.3')
>>> q.p = 'mx.example.org'
>>> q.r = 'example.net'
>>> q.expand('%{d}')
'email.example.com'
>>> q.expand('%{d4}')
'email.example.com'
>>> q.expand('%{d3}')
'email.example.com'
>>> q.expand('%{d2}')
'example.com'
>>> q.expand('%{d1}')
'com'
>>> q.expand('%{p}')
'mx.example.org'
>>> q.expand('%{p2}')
'example.org'
>>> q.expand('%{dr}')
'com.example.email'
>>> q.expand('%{d2r}')
'example.email'
>>> q.expand('%{l}')
'strong-bad'
>>> q.expand('%{l-}')
'strong.bad'
>>> q.expand('%{lr}')
'strong-bad'
>>> q.expand('%{lr-}')
'bad.strong'
>>> q.expand('%{l1r-}')
'strong'
>>> q.expand('%{c}',stripdot=False)
'192.0.2.3'
>>> q.expand('%{r}',stripdot=False)
'example.net'
>>> q.expand('%{ir}.%{v}._spf.%{d2}')
'3.2.0.192.in-addr._spf.example.com'
>>> q.expand('%{lr-}.lp._spf.%{d2}')
'bad.strong.lp._spf.example.com'
>>> q.expand('%{lr-}.lp.%{ir}.%{v}._spf.%{d2}')
'bad.strong.lp.3.2.0.192.in-addr._spf.example.com'