Skip to content

Commit 7fa7c24

Browse files
committed
2 parents 972237a + 6e5333a commit 7fa7c24

File tree

6 files changed

+57
-75
lines changed

6 files changed

+57
-75
lines changed

parsedmarc/__init__.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def _parse_smtp_tls_failure_details(failure_details):
272272
return new_failure_details
273273

274274
except KeyError as e:
275-
raise InvalidSMTPTLSReport(f"Missing required failure details field:" f" {e}")
275+
raise InvalidSMTPTLSReport(f"Missing required failure details field: {e}")
276276
except Exception as e:
277277
raise InvalidSMTPTLSReport(str(e))
278278

@@ -284,7 +284,7 @@ def _parse_smtp_tls_report_policy(policy):
284284
policy_type = policy["policy"]["policy-type"]
285285
failure_details = []
286286
if policy_type not in policy_types:
287-
raise InvalidSMTPTLSReport(f"Invalid policy type " f"{policy_type}")
287+
raise InvalidSMTPTLSReport(f"Invalid policy type {policy_type}")
288288
new_policy = OrderedDict(policy_domain=policy_domain, policy_type=policy_type)
289289
if "policy-string" in policy["policy"]:
290290
if isinstance(policy["policy"]["policy-string"], list):
@@ -332,9 +332,7 @@ def parse_smtp_tls_report_json(report):
332332
raise Exception(f"Missing required field: {required_field}]")
333333
if not isinstance(report["policies"], list):
334334
policies_type = type(report["policies"])
335-
raise InvalidSMTPTLSReport(
336-
f"policies must be a list, " f"not {policies_type}"
337-
)
335+
raise InvalidSMTPTLSReport(f"policies must be a list, not {policies_type}")
338336
for policy in report["policies"]:
339337
policies.append(_parse_smtp_tls_report_policy(policy))
340338

@@ -1246,11 +1244,11 @@ def parse_report_email(
12461244
field_name = match[0].lower().replace(" ", "-")
12471245
fields[field_name] = match[1].strip()
12481246

1249-
feedback_report = "Arrival-Date: {}\n" "Source-IP: {}" "".format(
1247+
feedback_report = "Arrival-Date: {}\nSource-IP: {}".format(
12501248
fields["received-date"], fields["sender-ip-address"]
12511249
)
12521250
except Exception as e:
1253-
error = "Unable to parse message with " 'subject "{0}": {1}'.format(
1251+
error = 'Unable to parse message with subject "{0}": {1}'.format(
12541252
subject, e
12551253
)
12561254
raise InvalidDMARCReport(error)
@@ -1297,7 +1295,7 @@ def parse_report_email(
12971295
raise InvalidDMARCReport(error)
12981296

12991297
except Exception as e:
1300-
error = "Unable to parse message with " 'subject "{0}": {1}'.format(
1298+
error = 'Unable to parse message with subject "{0}": {1}'.format(
13011299
subject, e
13021300
)
13031301
raise ParserError(error)
@@ -1331,7 +1329,7 @@ def parse_report_email(
13311329
return result
13321330

13331331
if result is None:
1334-
error = 'Message with subject "{0}" is ' "not a valid report".format(subject)
1332+
error = 'Message with subject "{0}" is not a valid report'.format(subject)
13351333
raise InvalidDMARCReport(error)
13361334

13371335

@@ -1666,7 +1664,7 @@ def get_dmarc_reports_from_mailbox(
16661664
aggregate_reports.append(parsed_email["report"])
16671665
else:
16681666
logger.debug(
1669-
"Skipping duplicate aggregate report " f"with ID: {report_id}"
1667+
f"Skipping duplicate aggregate report with ID: {report_id}"
16701668
)
16711669
aggregate_report_msg_uids.append(msg_uid)
16721670
elif parsed_email["report_type"] == "forensic":
@@ -1708,7 +1706,7 @@ def get_dmarc_reports_from_mailbox(
17081706

17091707
except Exception as e:
17101708
message = "Error deleting message UID"
1711-
e = "{0} {1}: " "{2}".format(message, msg_uid, e)
1709+
e = "{0} {1}: {2}".format(message, msg_uid, e)
17121710
logger.error("Mailbox error: {0}".format(e))
17131711
else:
17141712
if len(aggregate_report_msg_uids) > 0:

parsedmarc/cli.py

+37-49
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
from parsedmarc.utils import is_mbox, get_reverse_dns
5050
from parsedmarc import SEEN_AGGREGATE_REPORT_IDS
5151

52-
http.client._MAXHEADERS = 200 # pylint:disable=protected-access
52+
http.client._MAXHEADERS = 200 # pylint:disable=protected-access
5353

5454
formatter = logging.Formatter(
5555
fmt="%(levelname)8s:%(filename)s:%(lineno)d:%(message)s",
@@ -399,15 +399,15 @@ def process_reports(reports_):
399399
arg_parser.add_argument(
400400
"-c",
401401
"--config-file",
402-
help="a path to a configuration file " "(--silent implied)",
402+
help="a path to a configuration file (--silent implied)",
403403
)
404404
arg_parser.add_argument(
405405
"file_path",
406406
nargs="*",
407407
help="one or more paths to aggregate or forensic "
408408
"report files, emails, or mbox files'",
409409
)
410-
strip_attachment_help = "remove attachment payloads from forensic " "report output"
410+
strip_attachment_help = "remove attachment payloads from forensic report output"
411411
arg_parser.add_argument(
412412
"--strip-attachment-payloads", help=strip_attachment_help, action="store_true"
413413
)
@@ -450,14 +450,14 @@ def process_reports(reports_):
450450
arg_parser.add_argument(
451451
"-t",
452452
"--dns_timeout",
453-
help="number of seconds to wait for an answer " "from DNS (default: 2.0)",
453+
help="number of seconds to wait for an answer from DNS (default: 2.0)",
454454
type=float,
455455
default=2.0,
456456
)
457457
arg_parser.add_argument(
458458
"--offline",
459459
action="store_true",
460-
help="do not make online queries for geolocation " " or DNS",
460+
help="do not make online queries for geolocation or DNS",
461461
)
462462
arg_parser.add_argument(
463463
"-s", "--silent", action="store_true", help="only print errors"
@@ -734,7 +734,7 @@ def process_reports(reports_):
734734
if "host" in imap_config:
735735
opts.imap_host = imap_config["host"]
736736
else:
737-
logger.error("host setting missing from the " "imap config section")
737+
logger.error("host setting missing from the imap config section")
738738
exit(-1)
739739
if "port" in imap_config:
740740
opts.imap_port = imap_config.getint("port")
@@ -750,14 +750,12 @@ def process_reports(reports_):
750750
if "user" in imap_config:
751751
opts.imap_user = imap_config["user"]
752752
else:
753-
logger.critical("user setting missing from the " "imap config section")
753+
logger.critical("user setting missing from the imap config section")
754754
exit(-1)
755755
if "password" in imap_config:
756756
opts.imap_password = imap_config["password"]
757757
else:
758-
logger.critical(
759-
"password setting missing from the " "imap config section"
760-
)
758+
logger.critical("password setting missing from the imap config section")
761759
exit(-1)
762760
if "reports_folder" in imap_config:
763761
opts.mailbox_reports_folder = imap_config["reports_folder"]
@@ -826,21 +824,20 @@ def process_reports(reports_):
826824
opts.graph_user = graph_config["user"]
827825
else:
828826
logger.critical(
829-
"user setting missing from the " "msgraph config section"
827+
"user setting missing from the msgraph config section"
830828
)
831829
exit(-1)
832830
if "password" in graph_config:
833831
opts.graph_password = graph_config["password"]
834832
else:
835833
logger.critical(
836-
"password setting missing from the " "msgraph config section"
834+
"password setting missing from the msgraph config section"
837835
)
838836
if "client_secret" in graph_config:
839837
opts.graph_client_secret = graph_config["client_secret"]
840838
else:
841839
logger.critical(
842-
"client_secret setting missing from the "
843-
"msgraph config section"
840+
"client_secret setting missing from the msgraph config section"
844841
)
845842
exit(-1)
846843

@@ -853,7 +850,7 @@ def process_reports(reports_):
853850
opts.graph_tenant_id = graph_config["tenant_id"]
854851
else:
855852
logger.critical(
856-
"tenant_id setting missing from the " "msgraph config section"
853+
"tenant_id setting missing from the msgraph config section"
857854
)
858855
exit(-1)
859856

@@ -862,24 +859,23 @@ def process_reports(reports_):
862859
opts.graph_client_secret = graph_config["client_secret"]
863860
else:
864861
logger.critical(
865-
"client_secret setting missing from the "
866-
"msgraph config section"
862+
"client_secret setting missing from the msgraph config section"
867863
)
868864
exit(-1)
869865

870866
if "client_id" in graph_config:
871867
opts.graph_client_id = graph_config["client_id"]
872868
else:
873869
logger.critical(
874-
"client_id setting missing from the " "msgraph config section"
870+
"client_id setting missing from the msgraph config section"
875871
)
876872
exit(-1)
877873

878874
if "mailbox" in graph_config:
879875
opts.graph_mailbox = graph_config["mailbox"]
880876
elif opts.graph_auth_method != AuthMethod.UsernamePassword.name:
881877
logger.critical(
882-
"mailbox setting missing from the " "msgraph config section"
878+
"mailbox setting missing from the msgraph config section"
883879
)
884880
exit(-1)
885881

@@ -897,7 +893,7 @@ def process_reports(reports_):
897893
opts.elasticsearch_hosts = _str_to_list(elasticsearch_config["hosts"])
898894
else:
899895
logger.critical(
900-
"hosts setting missing from the " "elasticsearch config section"
896+
"hosts setting missing from the elasticsearch config section"
901897
)
902898
exit(-1)
903899
if "timeout" in elasticsearch_config:
@@ -935,7 +931,7 @@ def process_reports(reports_):
935931
opts.opensearch_hosts = _str_to_list(opensearch_config["hosts"])
936932
else:
937933
logger.critical(
938-
"hosts setting missing from the " "opensearch config section"
934+
"hosts setting missing from the opensearch config section"
939935
)
940936
exit(-1)
941937
if "timeout" in opensearch_config:
@@ -971,21 +967,21 @@ def process_reports(reports_):
971967
opts.hec = hec_config["url"]
972968
else:
973969
logger.critical(
974-
"url setting missing from the " "splunk_hec config section"
970+
"url setting missing from the splunk_hec config section"
975971
)
976972
exit(-1)
977973
if "token" in hec_config:
978974
opts.hec_token = hec_config["token"]
979975
else:
980976
logger.critical(
981-
"token setting missing from the " "splunk_hec config section"
977+
"token setting missing from the splunk_hec config section"
982978
)
983979
exit(-1)
984980
if "index" in hec_config:
985981
opts.hec_index = hec_config["index"]
986982
else:
987983
logger.critical(
988-
"index setting missing from the " "splunk_hec config section"
984+
"index setting missing from the splunk_hec config section"
989985
)
990986
exit(-1)
991987
if "skip_certificate_verification" in hec_config:
@@ -998,9 +994,7 @@ def process_reports(reports_):
998994
if "hosts" in kafka_config:
999995
opts.kafka_hosts = _str_to_list(kafka_config["hosts"])
1000996
else:
1001-
logger.critical(
1002-
"hosts setting missing from the " "kafka config section"
1003-
)
997+
logger.critical("hosts setting missing from the kafka config section")
1004998
exit(-1)
1005999
if "user" in kafka_config:
10061000
opts.kafka_username = kafka_config["user"]
@@ -1015,29 +1009,28 @@ def process_reports(reports_):
10151009
opts.kafka_aggregate_topic = kafka_config["aggregate_topic"]
10161010
else:
10171011
logger.critical(
1018-
"aggregate_topic setting missing from the " "kafka config section"
1012+
"aggregate_topic setting missing from the kafka config section"
10191013
)
10201014
exit(-1)
10211015
if "forensic_topic" in kafka_config:
10221016
opts.kafka_forensic_topic = kafka_config["forensic_topic"]
10231017
else:
10241018
logger.critical(
1025-
"forensic_topic setting missing from the " "kafka config section"
1019+
"forensic_topic setting missing from the kafka config section"
10261020
)
10271021
if "smtp_tls_topic" in kafka_config:
10281022
opts.kafka_smtp_tls_topic = kafka_config["smtp_tls_topic"]
10291023
else:
10301024
logger.critical(
1031-
"forensic_topic setting missing from the "
1032-
"splunk_hec config section"
1025+
"forensic_topic setting missing from the splunk_hec config section"
10331026
)
10341027

10351028
if "smtp" in config.sections():
10361029
smtp_config = config["smtp"]
10371030
if "host" in smtp_config:
10381031
opts.smtp_host = smtp_config["host"]
10391032
else:
1040-
logger.critical("host setting missing from the " "smtp config section")
1033+
logger.critical("host setting missing from the smtp config section")
10411034
exit(-1)
10421035
if "port" in smtp_config:
10431036
opts.smtp_port = smtp_config.getint("port")
@@ -1049,23 +1042,21 @@ def process_reports(reports_):
10491042
if "user" in smtp_config:
10501043
opts.smtp_user = smtp_config["user"]
10511044
else:
1052-
logger.critical("user setting missing from the " "smtp config section")
1045+
logger.critical("user setting missing from the smtp config section")
10531046
exit(-1)
10541047
if "password" in smtp_config:
10551048
opts.smtp_password = smtp_config["password"]
10561049
else:
1057-
logger.critical(
1058-
"password setting missing from the " "smtp config section"
1059-
)
1050+
logger.critical("password setting missing from the smtp config section")
10601051
exit(-1)
10611052
if "from" in smtp_config:
10621053
opts.smtp_from = smtp_config["from"]
10631054
else:
1064-
logger.critical("from setting missing from the " "smtp config section")
1055+
logger.critical("from setting missing from the smtp config section")
10651056
if "to" in smtp_config:
10661057
opts.smtp_to = _str_to_list(smtp_config["to"])
10671058
else:
1068-
logger.critical("to setting missing from the " "smtp config section")
1059+
logger.critical("to setting missing from the smtp config section")
10691060
if "subject" in smtp_config:
10701061
opts.smtp_subject = smtp_config["subject"]
10711062
if "attachment" in smtp_config:
@@ -1078,7 +1069,7 @@ def process_reports(reports_):
10781069
if "bucket" in s3_config:
10791070
opts.s3_bucket = s3_config["bucket"]
10801071
else:
1081-
logger.critical("bucket setting missing from the " "s3 config section")
1072+
logger.critical("bucket setting missing from the s3 config section")
10821073
exit(-1)
10831074
if "path" in s3_config:
10841075
opts.s3_path = s3_config["path"]
@@ -1103,9 +1094,7 @@ def process_reports(reports_):
11031094
if "server" in syslog_config:
11041095
opts.syslog_server = syslog_config["server"]
11051096
else:
1106-
logger.critical(
1107-
"server setting missing from the " "syslog config section"
1108-
)
1097+
logger.critical("server setting missing from the syslog config section")
11091098
exit(-1)
11101099
if "port" in syslog_config:
11111100
opts.syslog_port = syslog_config["port"]
@@ -1156,17 +1145,17 @@ def process_reports(reports_):
11561145
if "host" in gelf_config:
11571146
opts.gelf_host = gelf_config["host"]
11581147
else:
1159-
logger.critical("host setting missing from the " "gelf config section")
1148+
logger.critical("host setting missing from the gelf config section")
11601149
exit(-1)
11611150
if "port" in gelf_config:
11621151
opts.gelf_port = gelf_config["port"]
11631152
else:
1164-
logger.critical("port setting missing from the " "gelf config section")
1153+
logger.critical("port setting missing from the gelf config section")
11651154
exit(-1)
11661155
if "mode" in gelf_config:
11671156
opts.gelf_mode = gelf_config["mode"]
11681157
else:
1169-
logger.critical("mode setting missing from the " "gelf config section")
1158+
logger.critical("mode setting missing from the gelf config section")
11701159
exit(-1)
11711160

11721161
if "webhook" in config.sections():
@@ -1192,8 +1181,7 @@ def process_reports(reports_):
11921181
try:
11931182
fh = logging.FileHandler(opts.log_file, "a")
11941183
formatter = logging.Formatter(
1195-
"%(asctime)s - "
1196-
"%(levelname)s - [%(filename)s:%(lineno)d] - %(message)s"
1184+
"%(asctime)s - %(levelname)s - [%(filename)s:%(lineno)d] - %(message)s"
11971185
)
11981186
fh.setFormatter(formatter)
11991187
logger.addHandler(fh)
@@ -1301,7 +1289,7 @@ def process_reports(reports_):
13011289

13021290
if opts.hec:
13031291
if opts.hec_token is None or opts.hec_index is None:
1304-
logger.error("HEC token and HEC index are required when " "using HEC URL")
1292+
logger.error("HEC token and HEC index are required when using HEC URL")
13051293
exit(1)
13061294

13071295
verify = True
@@ -1464,7 +1452,7 @@ def process_reports(reports_):
14641452
try:
14651453
if opts.imap_user is None or opts.imap_password is None:
14661454
logger.error(
1467-
"IMAP user and password must be specified if" "host is specified"
1455+
"IMAP user and password must be specified ifhost is specified"
14681456
)
14691457

14701458
ssl = True

0 commit comments

Comments
 (0)