From 445e3cdf9d7731892cf1a7a68917c0e5abbff4fc Mon Sep 17 00:00:00 2001 From: Nathan Thorpe Date: Sun, 3 Apr 2022 21:49:27 -0700 Subject: [PATCH] add try except block to get_dmarc_reports call --- README.rst | 2 +- parsedmarc/cli.py | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/README.rst b/README.rst index 868a02b..9afbf1a 100644 --- a/README.rst +++ b/README.rst @@ -29,7 +29,7 @@ Features * Parses draft and 1.0 standard aggregate/rua reports * Parses forensic/failure/ruf reports -* Can parse reports from an inbox over IMAP +* Can parse reports from an inbox over IMAP or Microsoft Graph * Transparently handles gzip or zip compressed reports * Consistent data structures * Simple JSON and/or CSV output diff --git a/parsedmarc/cli.py b/parsedmarc/cli.py index 4f07f15..9dee52e 100644 --- a/parsedmarc/cli.py +++ b/parsedmarc/cli.py @@ -787,21 +787,26 @@ def _main(): exit(1) if mailbox_connection: - reports = get_dmarc_reports_from_mailbox( - connection=mailbox_connection, - delete=opts.mailbox_delete, - batch_size=opts.mailbox_batch_size, - reports_folder=opts.mailbox_reports_folder, - archive_folder=opts.mailbox_archive_folder, - ip_db_path=opts.ip_db_path, - offline=opts.offline, - nameservers=opts.nameservers, - test=opts.mailbox_test, - strip_attachment_payloads=opts.strip_attachment_payloads, - ) + try: + reports = get_dmarc_reports_from_mailbox( + connection=mailbox_connection, + delete=opts.mailbox_delete, + batch_size=opts.mailbox_batch_size, + reports_folder=opts.mailbox_reports_folder, + archive_folder=opts.mailbox_archive_folder, + ip_db_path=opts.ip_db_path, + offline=opts.offline, + nameservers=opts.nameservers, + test=opts.mailbox_test, + strip_attachment_payloads=opts.strip_attachment_payloads, + ) - aggregate_reports += reports["aggregate_reports"] - forensic_reports += reports["forensic_reports"] + aggregate_reports += reports["aggregate_reports"] + forensic_reports += reports["forensic_reports"] + + except Exception as error: + logger.error("Mailbox Error: {0}".format(error.__str__())) + exit(1) results = OrderedDict([("aggregate_reports", aggregate_reports), ("forensic_reports", forensic_reports)])