pydns driver did not join split TXT records. Try for Milter.dns which

follows CNAME (is this needed?)
This commit is contained in:
Stuart D. Gathman
2011-06-14 16:40:16 -04:00
parent 70c5b55dbf
commit 47fbf5a02b
2 changed files with 18 additions and 6 deletions
+1 -1
View File
@@ -348,7 +348,7 @@ class DKIM(object):
try: try:
pk = parse_public_key(base64.b64decode(pub[b'p'])) pk = parse_public_key(base64.b64decode(pub[b'p']))
except (TypeError,UnparsableKeyError) as e: except (TypeError,UnparsableKeyError) as e:
raise KeyFormatError("could not parse public key: %s" % e) raise KeyFormatError("could not parse public key (%s): %s" % (pub[b'p'],e))
include_headers = re.split(br"\s*:\s*", sig[b'h']) include_headers = re.split(br"\s*:\s*", sig[b'h'])
h = hasher() h = hasher()
+14 -2
View File
@@ -42,19 +42,31 @@ def get_txt_pydns(name):
response = DNS.DnsRequest(name, qtype='txt').req() response = DNS.DnsRequest(name, qtype='txt').req()
if not response.answers: if not response.answers:
return None return None
return response.answers[0]['data'][0] return b''.join(response.answers[0]['data'])
def get_txt_Milter_dns(name):
"""Return a TXT record associated with a DNS name."""
# Older pydns releases don't like a trailing dot.
if name.endswith('.'):
name = name[:-1]
sess = Session()
a = sess.dns(name,'TXT')
if a: return b''.join(a[0])
return None
# Prefer dnspython if it's there, otherwise use pydns. # Prefer dnspython if it's there, otherwise use pydns.
try: try:
import dns.resolver import dns.resolver
_get_txt = get_txt_dnspython _get_txt = get_txt_dnspython
except ImportError:
try:
from Milter.dns import Session
_get_txt = get_txt_Milter_dns
except ImportError: except ImportError:
import DNS import DNS
DNS.DiscoverNameServers() DNS.DiscoverNameServers()
_get_txt = get_txt_pydns _get_txt = get_txt_pydns
def get_txt(name): def get_txt(name):
"""Return a TXT record associated with a DNS name. """Return a TXT record associated with a DNS name.