text
stringlengths
1
93.6k
RE_TOPLAB = re.compile(
r'\.(?:[0-9a-z]*[a-z][0-9a-z]*|[0-9a-z]+-[0-9a-z-]*[0-9a-z])\.?$|%s'
% PAT_CHAR, re.IGNORECASE)
RE_DOT_ATOM = re.compile(r'%(atext)s+([.]%(atext)s+)*$' % {
'atext': r"[0-9a-z!#$%&'*+/=?^_`{}|~-]" }, re.IGNORECASE)
# Derived from RFC 3986 appendix A
RE_IP6 = re.compile( '(?:%(hex4)s:){6}%(ls32)s$'
'|::(?:%(hex4)s:){5}%(ls32)s$'
'|(?:%(hex4)s)?::(?:%(hex4)s:){4}%(ls32)s$'
'|(?:(?:%(hex4)s:){0,1}%(hex4)s)?::(?:%(hex4)s:){3}%(ls32)s$'
'|(?:(?:%(hex4)s:){0,2}%(hex4)s)?::(?:%(hex4)s:){2}%(ls32)s$'
'|(?:(?:%(hex4)s:){0,3}%(hex4)s)?::%(hex4)s:%(ls32)s$'
'|(?:(?:%(hex4)s:){0,4}%(hex4)s)?::%(ls32)s$'
'|(?:(?:%(hex4)s:){0,5}%(hex4)s)?::%(hex4)s$'
'|(?:(?:%(hex4)s:){0,6}%(hex4)s)?::$'
% {
'ls32': r'(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|%s)'%PAT_IP4,
'hex4': r'[0-9a-f]{1,4}'
}, re.IGNORECASE)
# Local parts and senders have their delimiters replaced with '.' during
# macro expansion
#
JOINERS = {'l': '.', 's': '.'}
RESULTS = {'+': 'pass', '-': 'fail', '?': 'neutral', '~': 'softfail',
'pass': 'pass', 'fail': 'fail', 'permerror': 'permerror',
'error': 'temperror', 'neutral': 'neutral', 'softfail': 'softfail',
'none': 'none', 'local': 'local', 'trusted': 'trusted',
'ambiguous': 'ambiguous', 'unknown': 'permerror' }
EXPLANATIONS = {'pass': 'sender SPF authorized',
'fail': 'SPF fail - not authorized',
'permerror': 'permanent error in processing',
'temperror': 'temporary DNS error in processing',
'softfail': 'domain owner discourages use of this host',
'neutral': 'access neither permitted nor denied',
'none': '',
#Note: The following are not formally SPF results
'local': 'No SPF result due to local policy',
'trusted': 'No SPF check - trusted-forwarder.org',
#Ambiguous only used in harsh mode for SPF validation
'ambiguous': 'No error, but results may vary'
}
DELEGATE = None
# standard default SPF record for best_guess
DEFAULT_SPF = 'v=spf1 a/24 mx/24 ptr'
#Whitelisted forwarders here. Additional locally trusted forwarders can be
#added to this record.
TRUSTED_FORWARDERS = 'v=spf1 ?include:spf.trusted-forwarder.org -all'
# maximum DNS lookups allowed
MAX_LOOKUP = 10 #RFC 4408 Para 10.1/RFC 7208 4.6.4
MAX_MX = 10 #RFC 4408 Para 10.1/RFC 7208 4.6.4
MAX_PTR = 10 #RFC 4408 Para 10.1/RFC 7208 4.6.4
MAX_CNAME = 10 # analogous interpretation to MAX_PTR
MAX_RECURSION = 20
MAX_PER_LOOKUP_TIME = 20 # Per RFC 7208 4.6.4
MAX_VOID_LOOKUPS = 2 # RFC 7208 4.6.4
ALL_MECHANISMS = ('a', 'mx', 'ptr', 'exists', 'include', 'ip4', 'ip6', 'all')
COMMON_MISTAKES = {
'prt': 'ptr', 'ip': 'ip4', 'ipv4': 'ip4', 'ipv6': 'ip6', 'all.': 'all'
}
#If harsh processing, for the validator, is invoked, warn if results
#likely deviate from the publishers intention.
class AmbiguityWarning(Exception):
"SPF Warning - ambiguous results"
def __init__(self, msg, mech=None, ext=None):
Exception.__init__(self, msg, mech)
self.msg = msg
self.mech = mech
self.ext = ext
def __str__(self):
if self.mech:
return '%s: %s' %(self.msg, self.mech)
return self.msg
class TempError(Exception):
"Temporary SPF error"
def __init__(self, msg, mech=None, ext=None):
Exception.__init__(self, msg, mech)
self.msg = str(msg)
self.mech = mech
self.ext = ext
def __str__(self):
if self.mech:
return '%s: %s'%(self.msg, self.mech)
return self.msg
class PermError(Exception):
"Permanent SPF error"
def __init__(self, msg, mech=None, ext=None):