From a57d6836aa0654af05c7780c8e712127d7b9c47c Mon Sep 17 00:00:00 2001 From: Sean Whalen Date: Sun, 14 Oct 2018 05:11:36 -0400 Subject: [PATCH] Fix error message formatting --- parsedmarc/elastic.py | 20 +++++++++++++------- parsedmarc/utils.py | 4 ++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/parsedmarc/elastic.py b/parsedmarc/elastic.py index f92897f..3ea65ed 100644 --- a/parsedmarc/elastic.py +++ b/parsedmarc/elastic.py @@ -322,15 +322,21 @@ def save_forensic_report_to_elasticsearch(forensic_report, search = Index(index).search() arrival_query = {"match": {"arrival_date": arrival_date}} q = Q(arrival_query) + + from_ = None + to_ = None + subject = None if "from" in headers: - from_query = {"match": {"sample.headers.from": headers["from"]}} + from_ = headers["from"] + from_query = {"match": {"sample.headers.from": from_}} q = q & from_query if "to" in headers: - to_query = {"match": {"sample.headers.to": headers["to"]}} + to_ = headers["to"] + to_query = {"match": {"sample.headers.to": to_}} q = q & Q(to_query) if "subject" in headers: - subject_query = {"match": {"sample.headers.subject": headers[ - "subject"]}} + subject = headers["subject"] + subject_query = {"match": {"sample.headers.subject": subject}} q = q & subject_query search.query = q @@ -340,9 +346,9 @@ def save_forensic_report_to_elasticsearch(forensic_report, raise AlreadySaved("A forensic sample to {0} from {1} " "with a subject of {2} and arrival date of {3} " "already exists in " - "Elasticsearch".format(headers["to"], - headers["from"], - headers["subject"], + "Elasticsearch".format(to_, + from_, + subject, arrival_date_human )) diff --git a/parsedmarc/utils.py b/parsedmarc/utils.py index 653f625..16c9847 100644 --- a/parsedmarc/utils.py +++ b/parsedmarc/utils.py @@ -405,8 +405,8 @@ def parse_email(data): " ") if "from" not in parsed_email: - if "From" in parsed_email["headers"]: - parsed_email["from"] = parsed_email["Headers"]["From"] + if "from" in parsed_email["headers"]: + parsed_email["from"] = parsed_email["Headers"]["from"] else: parsed_email["from"] = None