Skip to content

Commit

Permalink
SPFRecordNotFound includes domain name (#103)
Browse files Browse the repository at this point in the history
* SPFRecordNotFound includes domain name

* linter
  • Loading branch information
kazet authored Sep 11, 2023
1 parent 6927490 commit befbe44
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions checkdmarc.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,12 @@ def __init__(self, msg, data=None):
class SPFRecordNotFound(SPFError):
"""Raised when an SPF record could not be found"""

def __init__(self, error):
def __init__(self, error, domain):
if isinstance(error, dns.exception.Timeout):
error.kwargs["timeout"] = round(error.kwargs["timeout"], 1)

self.domain = domain


class MultipleSPFRTXTRecords(SPFError):
"""Raised when multiple TXT spf1 records are found"""
Expand Down Expand Up @@ -1634,15 +1636,23 @@ def query_spf_record(domain, nameservers=None, resolver=None, timeout=2.0):
if spf_record is None:
raise SPFRecordNotFound(
"{0} does not have a SPF TXT record{1}".format(
domain, warnings_str))
domain, warnings_str),
domain)
except dns.resolver.NoAnswer:
message = "{0} does not have a SPF TXT record{1}".format(
domain, warnings_str
)

raise SPFRecordNotFound(
"{0} does not have a SPF TXT record{1}".format(
domain, warnings_str))
message,
domain)
except dns.resolver.NXDOMAIN:
raise SPFRecordNotFound("The domain {0} does not exist".format(domain))
raise SPFRecordNotFound(
"The domain {0} does not exist".format(domain),
domain
)
except Exception as error:
raise SPFRecordNotFound(error)
raise SPFRecordNotFound(error, domain)

return OrderedDict([("record", spf_record), ("warnings", warnings)])

Expand Down

0 comments on commit befbe44

Please sign in to comment.