text
stringlengths 1
93.6k
|
|---|
elif res == 'permerror': return \
|
"permanent error in processing domain of %s: %s" \
|
% (sender, self.prob)
|
elif res == 'temperror': return \
|
"temporary error in processing during lookup of %s" % sender
|
elif res == 'fail': return \
|
"domain of %s does not designate %s as permitted sender" \
|
% (sender, self.c)
|
raise ValueError("invalid SPF result for header comment: "+res)
|
def split_email(s, h):
|
"""Given a sender email s and a HELO domain h, create a valid tuple
|
(l, d) local-part and domain-part.
|
Examples:
|
>>> split_email('', 'wayforward.net')
|
('postmaster', 'wayforward.net')
|
>>> split_email('foo.com', 'wayforward.net')
|
('postmaster', 'foo.com')
|
>>> split_email('terry@wayforward.net', 'optsw.com')
|
('terry', 'wayforward.net')
|
"""
|
if not s:
|
return 'postmaster', h
|
else:
|
parts = s.split('@', 1)
|
if parts[0] == '':
|
parts[0] = 'postmaster'
|
if len(parts) == 2:
|
return tuple(parts)
|
else:
|
return 'postmaster', s
|
def quote_value(s):
|
"""Quote the value for a key-value pair in Received-SPF header field
|
if needed. No quoting needed for a dot-atom value.
|
Examples:
|
>>> quote_value('foo@bar.com')
|
'"foo@bar.com"'
|
>>> quote_value('mail.example.com')
|
'mail.example.com'
|
>>> quote_value('A:1.2.3.4')
|
'"A:1.2.3.4"'
|
>>> quote_value('abc"def')
|
'"abc\\\\"def"'
|
>>> quote_value(r'abc\\def')
|
'"abc\\\\\\\\def"'
|
>>> quote_value('abc..def')
|
'"abc..def"'
|
>>> quote_value('')
|
'""'
|
>>> quote_value(None)
|
"""
|
if s is None or RE_DOT_ATOM.match(s):
|
return s
|
return '"' + s.replace('\\',r'\\').replace('"',r'\"'
|
).replace('\x00',r'\x00') + '"'
|
def parse_mechanism(str, d):
|
"""Breaks A, MX, IP4, and PTR mechanisms into a (name, domain,
|
cidr,cidr6) tuple. The domain portion defaults to d if not present,
|
the cidr defaults to 32 if not present.
|
Examples:
|
>>> parse_mechanism('a', 'foo.com')
|
('a', 'foo.com', None, None)
|
>>> parse_mechanism('exists','foo.com')
|
('exists', None, None, None)
|
>>> parse_mechanism('a:bar.com', 'foo.com')
|
('a', 'bar.com', None, None)
|
>>> parse_mechanism('a/24', 'foo.com')
|
('a', 'foo.com', 24, None)
|
>>> parse_mechanism('A:foo:bar.com/16//48', 'foo.com')
|
('a', 'foo:bar.com', 16, 48)
|
>>> parse_mechanism('-exists:%{i}.%{s1}.100/86400.rate.%{d}','foo.com')
|
('-exists', '%{i}.%{s1}.100/86400.rate.%{d}', None, None)
|
>>> parse_mechanism('mx:%%%_/.Claranet.de/27','foo.com')
|
('mx', '%%%_/.Claranet.de', 27, None)
|
>>> parse_mechanism('mx:%{d}//97','foo.com')
|
('mx', '%{d}', None, 97)
|
>>> parse_mechanism('iP4:192.0.0.0/8','foo.com')
|
('ip4', '192.0.0.0', 8, None)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.