text
stringlengths 1
93.6k
|
|---|
>>> q.check(spf='v=spf1 ip4:192.0.0.0/8 ~all')
|
('pass', 250, 'sender SPF authorized')
|
>>> q.get_header('pass')
|
'Pass (abuse@kitterman.com: domain of email.example.com designates 192.0.2.3 as permitted sender) client-ip=192.0.2.3; envelope-from="strong-bad@email.example.com"; helo=mx.example.org; receiver=abuse@kitterman.com; mechanism="ip4:192.0.0.0/8"; identity=mailfrom'
|
>>> q.check(spf='v=spf1 ?all')
|
('neutral', 250, 'access neither permitted nor denied')
|
>>> q.get_header('neutral', header_type = 'authres', aid='bmsi.com')
|
'Authentication-Results: bmsi.com; spf=neutral (abuse@kitterman.com: 192.0.2.3 is neither permitted nor denied by domain of email.example.com) smtp.mailfrom=email.example.com (sender=strong-bad@email.example.com; helo=mx.example.org; client-ip=192.0.2.3; receiver=abuse@kitterman.com; mechanism=?all)'
|
>>> p = query(s='strong-bad@email.example.com', h='mx.example.org',
|
... i='192.0.2.3')
|
>>> p.r='abuse@kitterman.com'
|
>>> p.check(spf='v=spf1 redirect=controlledmail.com exp=_exp.controlledmail.com')
|
('fail', 550, 'SPF fail - not authorized')
|
>>> p.ident = 'helo'
|
>>> p.get_header('fail', header_type = 'authres', aid='bmsi.com')
|
'Authentication-Results: bmsi.com; spf=fail (abuse@kitterman.com: domain of email.example.com does not designate 192.0.2.3 as permitted sender) smtp.helo=mx.example.org (sender=strong-bad@email.example.com; client-ip=192.0.2.3; receiver=abuse@kitterman.com; mechanism=-all)'
|
>>> q.check(spf='v=spf1 ?all')
|
('neutral', 250, 'access neither permitted nor denied')
|
>>> try: q.get_header('neutral', header_type = 'dkim')
|
... except SyntaxError as x: print(x)
|
Unknown results header type: dkim
|
"""
|
# If type is Authentication Results header (spf/authres)
|
if header_type == 'authres':
|
if not aid:
|
raise SyntaxError('authserv-id missing for Authentication Results header type, see RFC5451 2.3')
|
import authres
|
if not receiver:
|
receiver = self.r
|
client_ip = self.c
|
helo = quote_value(self.h)
|
resmap = { 'pass': 'Pass', 'neutral': 'Neutral', 'fail': 'Fail',
|
'softfail': 'SoftFail', 'none': 'None',
|
'temperror': 'TempError', 'permerror': 'PermError' }
|
identity = self.ident
|
if identity == 'helo':
|
envelope_from = None
|
else:
|
envelope_from = quote_value(self.s)
|
tag = resmap[res]
|
if res == 'permerror' and self.mech:
|
problem = quote_value(' '.join(self.mech))
|
else:
|
problem = None
|
mechanism = quote_value(self.mechanism)
|
if hasattr(self,'comment'):
|
comment = self.comment
|
else:
|
comment = '%s: %s' % (receiver,self.get_header_comment(res))
|
res = ['%s (%s)' % (tag,comment)]
|
if header_type == 'spf':
|
for k in ('client_ip','envelope_from','helo','receiver',
|
'problem','mechanism'):
|
v = locals()[k]
|
if v: res.append('%s=%s;'%(k.replace('_','-'),v))
|
for k,v in sorted(list(kv.items())):
|
if v: res.append('x-%s=%s;'%(k.replace('_','-'),quote_value(v)))
|
# do identity last so we can easily drop the trailing ';'
|
res.append('%s=%s'%('identity',identity))
|
return ' '.join(res)
|
elif header_type == 'authres':
|
if envelope_from:
|
return str(authres.AuthenticationResultsHeader(authserv_id = aid, \
|
results = [authres.SPFAuthenticationResult(result = tag, \
|
result_comment = comment, smtp_mailfrom = self.d, \
|
smtp_mailfrom_comment = \
|
'sender={0}; helo={1}; client-ip={2}; receiver={3}; mechanism={4}'.format(self.s, \
|
self.h, self.c, self.r, mechanism))]))
|
else:
|
return str(authres.AuthenticationResultsHeader(authserv_id = aid, \
|
results = [authres.SPFAuthenticationResult(result = tag, \
|
result_comment = comment, smtp_helo = self.h, \
|
smtp_helo_comment = \
|
'sender={0}; client-ip={1}; receiver={2}; mechanism={3}'.format(self.s, \
|
self.c, self.r, mechanism))]))
|
else:
|
raise SyntaxError('Unknown results header type: {0}'.format(header_type))
|
def get_header_comment(self, res):
|
"""Return comment for Received-SPF header. """
|
sender = self.o
|
if res == 'pass':
|
return \
|
"domain of %s designates %s as permitted sender" \
|
% (sender, self.c)
|
elif res == 'softfail': return \
|
"transitioning domain of %s does not designate %s as permitted sender" \
|
% (sender, self.c)
|
elif res == 'neutral': return \
|
"%s is neither permitted nor denied by domain of %s" \
|
% (self.c, sender)
|
elif res == 'none': return \
|
"%s is neither permitted nor denied by domain of %s" \
|
% (self.c, sender)
|
#"%s does not designate permitted sender hosts" % sender
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.