From d8b84425c2b69841eeea88a9eda7f7d80008fc06 Mon Sep 17 00:00:00 2001 From: Sean Whalen Date: Thu, 18 Jul 2019 23:05:46 -0400 Subject: [PATCH] 6.5.1 --- _modules/index.html | 4 +- _modules/parsedmarc.html | 123 +++++++++++++++++++++---------- _modules/parsedmarc/elastic.html | 4 +- _modules/parsedmarc/splunk.html | 4 +- _modules/parsedmarc/utils.html | 4 +- _static/documentation_options.js | 2 +- genindex.html | 12 ++- index.html | 41 ++++++++++- objects.inv | Bin 748 -> 760 bytes py-modindex.html | 4 +- search.html | 4 +- searchindex.js | 2 +- 12 files changed, 145 insertions(+), 59 deletions(-) diff --git a/_modules/index.html b/_modules/index.html index de07085..d8fd418 100644 --- a/_modules/index.html +++ b/_modules/index.html @@ -8,7 +8,7 @@ - Overview: module code — parsedmarc 6.5.0 documentation + Overview: module code — parsedmarc 6.5.1 documentation @@ -58,7 +58,7 @@
- 6.5.0 + 6.5.1
diff --git a/_modules/parsedmarc.html b/_modules/parsedmarc.html index 5103bad..502b5c2 100644 --- a/_modules/parsedmarc.html +++ b/_modules/parsedmarc.html @@ -8,7 +8,7 @@ - parsedmarc — parsedmarc 6.5.0 documentation + parsedmarc — parsedmarc 6.5.1 documentation @@ -58,7 +58,7 @@
- 6.5.0 + 6.5.1
@@ -178,7 +178,7 @@ from parsedmarc.utils import timestamp_to_human, human_timestamp_to_datetime from parsedmarc.utils import parse_email -__version__ = "6.5.0" +__version__ = "6.5.1" logging.basicConfig( format='%(levelname)8s:%(filename)s:%(lineno)d:' @@ -548,38 +548,27 @@ parallel=parallel) -
[docs]def parsed_aggregate_reports_to_csv(reports): +
[docs]def parsed_aggregate_reports_to_csv_rows(reports): """ - Converts one or more parsed aggregate reports to flat CSV format, including - headers + Converts one or more parsed aggregate reports to list of dicts in flat CSV + format Args: reports: A parsed aggregate report or list of parsed aggregate reports Returns: - str: Parsed aggregate report data in flat CSV format, including headers + list: Parsed aggregate report data as a list of dicts in flat CSV + format """ def to_str(obj): return str(obj).lower() - fields = ["xml_schema", "org_name", "org_email", - "org_extra_contact_info", "report_id", "begin_date", "end_date", - "errors", "domain", "adkim", "aspf", "p", "sp", "pct", "fo", - "source_ip_address", "source_country", "source_reverse_dns", - "source_base_domain", "count", "disposition", "dkim_alignment", - "spf_alignment", "policy_override_reasons", - "policy_override_comments", "envelope_from", "header_from", - "envelope_to", "dkim_domains", "dkim_selectors", "dkim_results", - "spf_domains", "spf_scopes", "spf_results"] - - csv_file_object = StringIO(newline="\n") - writer = DictWriter(csv_file_object, fields) - writer.writeheader() - if type(reports) == OrderedDict: reports = [reports] + rows = [] + for report in reports: xml_schema = report["xml_schema"] org_name = report["report_metadata"]["org_name"] @@ -651,9 +640,42 @@ row["spf_domains"] = ",".join(map(to_str, spf_domains)) row["spf_scopes"] = ",".join(map(to_str, spf_scopes)) row["spf_results"] = ",".join(map(to_str, dkim_results)) + rows.append(row) - writer.writerow(row) - csv_file_object.flush() + return rows
+ + +
[docs]def parsed_aggregate_reports_to_csv(reports): + """ + Converts one or more parsed aggregate reports to flat CSV format, including + headers + + Args: + reports: A parsed aggregate report or list of parsed aggregate reports + + Returns: + str: Parsed aggregate report data in flat CSV format, including headers + """ + + fields = ["xml_schema", "org_name", "org_email", + "org_extra_contact_info", "report_id", "begin_date", "end_date", + "errors", "domain", "adkim", "aspf", "p", "sp", "pct", "fo", + "source_ip_address", "source_country", "source_reverse_dns", + "source_base_domain", "count", "disposition", "dkim_alignment", + "spf_alignment", "policy_override_reasons", + "policy_override_comments", "envelope_from", "header_from", + "envelope_to", "dkim_domains", "dkim_selectors", "dkim_results", + "spf_domains", "spf_scopes", "spf_results"] + + csv_file_object = StringIO(newline="\n") + writer = DictWriter(csv_file_object, fields) + writer.writeheader() + + rows = parsed_aggregate_reports_to_csv_rows(reports) + + for row in rows: + writer.writerow(row) + csv_file_object.flush() return csv_file_object.getvalue()
@@ -777,30 +799,22 @@ "Unexpected error: {0}".format(error.__str__()))
-
[docs]def parsed_forensic_reports_to_csv(reports): +
[docs]def parsed_forensic_reports_to_csv_rows(reports): """ - Converts one or more parsed forensic reports to flat CSV format, including - headers + Converts one or more parsed forensic reports to a list of dicts in flat CSV + format Args: reports: A parsed forensic report or list of parsed forensic reports Returns: - str: Parsed forensic report data in flat CSV format, including headers - """ - fields = ["feedback_type", "user_agent", "version", "original_envelope_id", - "original_mail_from", "original_rcpt_to", "arrival_date", - "arrival_date_utc", "subject", "message_id", - "authentication_results", "dkim_domain", "source_ip_address", - "source_country", "source_reverse_dns", "source_base_domain", - "delivery_result", "auth_failure", "reported_domain", - "authentication_mechanisms", "sample_headers_only"] - + list: Parsed forensic report data as a list of dicts in flat CSV format + """ if type(reports) == OrderedDict: reports = [reports] - csv_file = StringIO() - csv_writer = DictWriter(csv_file, fieldnames=fields) - csv_writer.writeheader() + + rows = [] + for report in reports: row = report.copy() row["source_ip_address"] = report["source"]["ip_address"] @@ -815,6 +829,37 @@ authentication_mechanisms) del row["sample"] del row["parsed_sample"] + rows.append(row) + + return rows
+ + +
[docs]def parsed_forensic_reports_to_csv(reports): + """ + Converts one or more parsed forensic reports to flat CSV format, including + headers + + Args: + reports: A parsed forensic report or list of parsed forensic reports + + Returns: + str: Parsed forensic report data in flat CSV format, including headers + """ + fields = ["feedback_type", "user_agent", "version", "original_envelope_id", + "original_mail_from", "original_rcpt_to", "arrival_date", + "arrival_date_utc", "subject", "message_id", + "authentication_results", "dkim_domain", "source_ip_address", + "source_country", "source_reverse_dns", "source_base_domain", + "delivery_result", "auth_failure", "reported_domain", + "authentication_mechanisms", "sample_headers_only"] + + csv_file = StringIO() + csv_writer = DictWriter(csv_file, fieldnames=fields) + csv_writer.writeheader() + + rows = parsed_forensic_reports_to_csv_rows(reports) + + for row in rows: csv_writer.writerow(row) return csv_file.getvalue()
diff --git a/_modules/parsedmarc/elastic.html b/_modules/parsedmarc/elastic.html index f49f4aa..135f287 100644 --- a/_modules/parsedmarc/elastic.html +++ b/_modules/parsedmarc/elastic.html @@ -8,7 +8,7 @@ - parsedmarc.elastic — parsedmarc 6.5.0 documentation + parsedmarc.elastic — parsedmarc 6.5.1 documentation @@ -58,7 +58,7 @@
- 6.5.0 + 6.5.1
diff --git a/_modules/parsedmarc/splunk.html b/_modules/parsedmarc/splunk.html index 7c33b97..d3cb6a6 100644 --- a/_modules/parsedmarc/splunk.html +++ b/_modules/parsedmarc/splunk.html @@ -8,7 +8,7 @@ - parsedmarc.splunk — parsedmarc 6.5.0 documentation + parsedmarc.splunk — parsedmarc 6.5.1 documentation @@ -58,7 +58,7 @@
- 6.5.0 + 6.5.1
diff --git a/_modules/parsedmarc/utils.html b/_modules/parsedmarc/utils.html index 927dd90..04dc877 100644 --- a/_modules/parsedmarc/utils.html +++ b/_modules/parsedmarc/utils.html @@ -8,7 +8,7 @@ - parsedmarc.utils — parsedmarc 6.5.0 documentation + parsedmarc.utils — parsedmarc 6.5.1 documentation @@ -58,7 +58,7 @@
- 6.5.0 + 6.5.1
diff --git a/_static/documentation_options.js b/_static/documentation_options.js index 6ccafe5..19e5695 100644 --- a/_static/documentation_options.js +++ b/_static/documentation_options.js @@ -1,6 +1,6 @@ var DOCUMENTATION_OPTIONS = { URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'), - VERSION: '6.5.0', + VERSION: '6.5.1', LANGUAGE: 'None', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', diff --git a/genindex.html b/genindex.html index dcfd4b9..f29eb5e 100644 --- a/genindex.html +++ b/genindex.html @@ -9,7 +9,7 @@ - Index — parsedmarc 6.5.0 documentation + Index — parsedmarc 6.5.1 documentation @@ -59,7 +59,7 @@
- 6.5.0 + 6.5.1
@@ -289,11 +289,15 @@
  • parse_report_file() (in module parsedmarc)
  • - - +