@@ -68,97 +68,105 @@ def main():
6868 args = docopt .docopt (__doc__ , version = trustymail .__version__ )
6969
7070 # Monkey patching trustymail to make it cache the PSL where we want
71- if args [' --psl-filename' ] is not None :
72- trustymail .PublicSuffixListFilename = args [' --psl-filename' ]
71+ if args [" --psl-filename" ] is not None :
72+ trustymail .PublicSuffixListFilename = args [" --psl-filename" ]
7373 # Monkey patching trustymail to make the PSL cache read-only
74- if args [' --psl-read-only' ]:
74+ if args [" --psl-read-only" ]:
7575 trustymail .PublicSuffixListReadOnly = True
7676 import trustymail .trustymail as tmail
7777
7878 log_level = logging .WARN
79- if args [' --debug' ]:
79+ if args [" --debug" ]:
8080 log_level = logging .DEBUG
81- logging .basicConfig (format = ' %(asctime)-15s %(message)s' , level = log_level )
81+ logging .basicConfig (format = " %(asctime)-15s %(message)s" , level = log_level )
8282
8383 # Allow for user to input a csv for many domain names.
84- if args [' INPUT' ][0 ].endswith (' .csv' ):
85- domains = tmail .domain_list_from_csv (open (args [' INPUT' ][0 ]))
84+ if args [" INPUT" ][0 ].endswith (" .csv" ):
85+ domains = tmail .domain_list_from_csv (open (args [" INPUT" ][0 ]))
8686 else :
87- domains = args [' INPUT' ]
87+ domains = args [" INPUT" ]
8888
89- if args [' --timeout' ] is not None :
90- timeout = int (args [' --timeout' ])
89+ if args [" --timeout" ] is not None :
90+ timeout = int (args [" --timeout" ])
9191 else :
9292 timeout = 5
9393
94- if args [' --smtp-timeout' ] is not None :
95- smtp_timeout = int (args [' --smtp-timeout' ])
94+ if args [" --smtp-timeout" ] is not None :
95+ smtp_timeout = int (args [" --smtp-timeout" ])
9696 else :
9797 smtp_timeout = 5
9898
99- if args [' --smtp-localhost' ] is not None :
100- smtp_localhost = args [' --smtp-localhost' ]
99+ if args [" --smtp-localhost" ] is not None :
100+ smtp_localhost = args [" --smtp-localhost" ]
101101 else :
102102 smtp_localhost = None
103103
104- if args [' --smtp-ports' ] is not None :
105- smtp_ports = {int (port ) for port in args [' --smtp-ports' ].split (',' )}
104+ if args [" --smtp-ports" ] is not None :
105+ smtp_ports = {int (port ) for port in args [" --smtp-ports" ].split ("," )}
106106 else :
107107 smtp_ports = _DEFAULT_SMTP_PORTS
108108
109- if args [' --dns' ] is not None :
110- dns_hostnames = args [' --dns' ].split (',' )
109+ if args [" --dns" ] is not None :
110+ dns_hostnames = args [" --dns" ].split ("," )
111111 else :
112112 dns_hostnames = None
113113
114114 # --starttls implies --mx
115- if args [' --starttls' ]:
116- args [' --mx' ] = True
115+ if args [" --starttls" ]:
116+ args [" --mx" ] = True
117117
118118 # User might not want every scan performed.
119119 scan_types = {
120- 'mx' : args [' --mx' ],
121- ' starttls' : args [' --starttls' ],
122- ' spf' : args [' --spf' ],
123- ' dmarc' : args [' --dmarc' ]
120+ "mx" : args [" --mx" ],
121+ " starttls" : args [" --starttls" ],
122+ " spf" : args [" --spf" ],
123+ " dmarc" : args [" --dmarc" ],
124124 }
125125
126126 domain_scans = []
127127 for domain_name in domains :
128- domain_scans .append (tmail .scan (domain_name , timeout ,
129- smtp_timeout , smtp_localhost ,
130- smtp_ports , not args ['--no-smtp-cache' ],
131- scan_types , dns_hostnames ))
128+ domain_scans .append (
129+ tmail .scan (
130+ domain_name ,
131+ timeout ,
132+ smtp_timeout ,
133+ smtp_localhost ,
134+ smtp_ports ,
135+ not args ["--no-smtp-cache" ],
136+ scan_types ,
137+ dns_hostnames ,
138+ )
139+ )
132140
133141 # Default output file name is results.
134- if args [' --output' ] is None :
135- output_file_name = ' results'
142+ if args [" --output" ] is None :
143+ output_file_name = " results"
136144 else :
137- output_file_name = args [' --output' ]
145+ output_file_name = args [" --output" ]
138146
139147 # Ensure file extension is present in filename.
140- if args [' --json' ] and ' .json' not in output_file_name :
141- output_file_name += ' .json'
142- elif ' .csv' not in output_file_name :
143- output_file_name += ' .csv'
148+ if args [" --json" ] and " .json" not in output_file_name :
149+ output_file_name += " .json"
150+ elif " .csv" not in output_file_name :
151+ output_file_name += " .csv"
144152
145- if args [' --json' ]:
153+ if args [" --json" ]:
146154 json_out = tmail .generate_json (domain_scans )
147- if args [' --output' ] is None :
155+ if args [" --output" ] is None :
148156 print (json_out )
149157 else :
150158 write (json_out , output_file_name )
151- logging .warn (' Wrote results to %s.' % output_file_name )
159+ logging .warn (" Wrote results to %s." % output_file_name )
152160 else :
153161 tmail .generate_csv (domain_scans , output_file_name )
154162
155163
156164def write (content , out_file ):
157165 parent = os .path .dirname (out_file )
158- if parent is not '' :
166+ if parent != "" :
159167 mkdir_p (parent )
160168
161- f = open (out_file , 'w' ) # no utf-8 in python 2
169+ f = open (out_file , "w" ) # no utf-8 in python 2
162170 f .write (content )
163171 f .close ()
164172
@@ -175,5 +183,5 @@ def mkdir_p(path):
175183 raise
176184
177185
178- if __name__ == ' __main__' :
186+ if __name__ == " __main__" :
179187 main ()
0 commit comments