New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Renamed error field and improved logging #35
Changes from 13 commits
4d9a948
8e3c80b
c365d29
8173729
cc6d3f8
11f6770
4e424c0
bf3c86d
bfad46c
b364d55
24e82e3
8835801
a1385d3
1b27451
2dd1d07
bea61f2
56abb03
7f50db1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ def __init__(self, domain_name, timeout, smtp_timeout, smtp_localhost, smtp_port | |
if self.base_domain_name != self.domain_name: | ||
if self.base_domain_name not in Domain.base_domains: | ||
# Populate DMARC for parent. | ||
domain = trustymail.scan(self.base_domain_name, timeout, smtp_timeout, smtp_localhost, smtp_ports, smtp_cache, {"mx": False, "starttls": False, "spf": False, "dmarc": True}, dns_hostnames) | ||
domain = trustymail.scan(self.base_domain_name, timeout, smtp_timeout, smtp_localhost, smtp_ports, smtp_cache, {'mx': False, 'starttls': False, 'spf': False, 'dmarc': True}, dns_hostnames) | ||
Domain.base_domains[self.base_domain_name] = domain | ||
self.base_domain = Domain.base_domains[self.base_domain_name] | ||
else: | ||
|
@@ -47,8 +47,8 @@ def __init__(self, domain_name, timeout, smtp_timeout, smtp_localhost, smtp_port | |
# 3. Whether or not the server supports STARTTLS | ||
self.starttls_results = {} | ||
|
||
# A list of any errors that occurred while scanning records. | ||
self.errors = [] | ||
# A list of any debugging information collected while scanning records. | ||
self.debug = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit leery of the name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I'll make the change. |
||
|
||
# A list of the ports tested for SMTP | ||
self.ports_tested = set() | ||
|
@@ -61,15 +61,15 @@ def has_supports_smtp(self): | |
Returns True if any of the mail servers associated with this | ||
domain are listening and support SMTP. | ||
""" | ||
return len(filter(lambda x: self.starttls_results[x]["supports_smtp"], | ||
return len(filter(lambda x: self.starttls_results[x]['supports_smtp'], | ||
self.starttls_results.keys())) > 0 | ||
|
||
def has_starttls(self): | ||
""" | ||
Returns True if any of the mail servers associated with this | ||
domain are listening and support STARTTLS. | ||
""" | ||
return len(filter(lambda x: self.starttls_results[x]["starttls"], | ||
return len(filter(lambda x: self.starttls_results[x]['starttls'], | ||
self.starttls_results.keys())) > 0 | ||
|
||
def has_spf(self): | ||
|
@@ -101,49 +101,49 @@ def parent_dmarc_results(self): | |
|
||
def get_dmarc_policy(self): | ||
# If the policy was never set, or isn't in the list of valid policies, check the parents. | ||
if self.dmarc_policy is None or self.dmarc_policy.lower() not in ["quarantine", "reject", "none"]: | ||
if self.dmarc_policy is None or self.dmarc_policy.lower() not in ['quarantine', 'reject', 'none']: | ||
if self.base_domain is None: | ||
return "" | ||
return '' | ||
else: | ||
return self.base_domain.get_dmarc_policy() | ||
return self.dmarc_policy | ||
|
||
def generate_results(self): | ||
mail_servers_that_support_smtp = [x for x in self.starttls_results.keys() if self.starttls_results[x]["supports_smtp"]] | ||
mail_servers_that_support_starttls = [x for x in self.starttls_results.keys() if self.starttls_results[x]["starttls"]] | ||
mail_servers_that_support_smtp = [x for x in self.starttls_results.keys() if self.starttls_results[x]['supports_smtp']] | ||
mail_servers_that_support_starttls = [x for x in self.starttls_results.keys() if self.starttls_results[x]['starttls']] | ||
domain_supports_smtp = bool(mail_servers_that_support_starttls) | ||
|
||
results = { | ||
"Domain": self.domain_name, | ||
"Base Domain": self.base_domain_name, | ||
"Live": self.is_live, | ||
|
||
"MX Record": self.has_mail(), | ||
"Mail Servers": self.format_list(self.mail_servers), | ||
"Mail Server Ports Tested": self.format_list([str(port) for port in self.ports_tested]), | ||
"Domain Supports SMTP Results": self.format_list(mail_servers_that_support_smtp), | ||
'Domain': self.domain_name, | ||
'Base Domain': self.base_domain_name, | ||
'Live': self.is_live, | ||
|
||
'MX Record': self.has_mail(), | ||
'Mail Servers': self.format_list(self.mail_servers), | ||
'Mail Server Ports Tested': self.format_list([str(port) for port in self.ports_tested]), | ||
'Domain Supports SMTP Results': self.format_list(mail_servers_that_support_smtp), | ||
# True if and only if at least one mail server speaks SMTP | ||
"Domain Supports SMTP": domain_supports_smtp, | ||
"Domain Supports STARTTLS Results": self.format_list(mail_servers_that_support_starttls), | ||
'Domain Supports SMTP': domain_supports_smtp, | ||
'Domain Supports STARTTLS Results': self.format_list(mail_servers_that_support_starttls), | ||
# True if and only if all mail servers that speak SMTP | ||
# also support STARTTLS | ||
"Domain Supports STARTTLS": domain_supports_smtp and all([self.starttls_results[x]["starttls"] for x in mail_servers_that_support_smtp]), | ||
'Domain Supports STARTTLS': domain_supports_smtp and all([self.starttls_results[x]['starttls'] for x in mail_servers_that_support_smtp]), | ||
|
||
"SPF Record": self.has_spf(), | ||
"Valid SPF": self.valid_spf, | ||
"SPF Results": self.format_list(self.spf), | ||
'SPF Record': self.has_spf(), | ||
'Valid SPF': self.valid_spf, | ||
'SPF Results': self.format_list(self.spf), | ||
|
||
"DMARC Record": self.has_dmarc(), | ||
"Valid DMARC": self.has_dmarc() and self.valid_dmarc, | ||
"DMARC Results": self.format_list(self.dmarc), | ||
'DMARC Record': self.has_dmarc(), | ||
'Valid DMARC': self.has_dmarc() and self.valid_dmarc, | ||
'DMARC Results': self.format_list(self.dmarc), | ||
|
||
"DMARC Record on Base Domain": self.parent_has_dmarc(), | ||
"Valid DMARC Record on Base Domain": self.parent_has_dmarc() and self.parent_valid_dmarc(), | ||
"DMARC Results on Base Domain": self.parent_dmarc_results(), | ||
"DMARC Policy": self.get_dmarc_policy(), | ||
'DMARC Record on Base Domain': self.parent_has_dmarc(), | ||
'Valid DMARC Record on Base Domain': self.parent_has_dmarc() and self.parent_valid_dmarc(), | ||
'DMARC Results on Base Domain': self.parent_dmarc_results(), | ||
'DMARC Policy': self.get_dmarc_policy(), | ||
|
||
"Syntax Errors": self.format_list(self.syntax_errors), | ||
"Errors": self.format_list(self.errors) | ||
'Syntax Errors': self.format_list(self.syntax_errors), | ||
'Debug': self.format_list(self.debug) | ||
} | ||
|
||
return results | ||
|
@@ -157,4 +157,4 @@ def format_list(self, record_list): | |
if not record_list: | ||
return None | ||
|
||
return ", ".join(record_list) | ||
return ', '.join(record_list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you're shuffling imports around, I would move this one to before the
from trustymail import trustymail
line below.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I'll make the change.