Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MC-514] Parse dkim, spf and dmarc indicators from Authentication-Results header #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[MC-514] Add constants
  • Loading branch information
dsliwinski-r7 committed May 4, 2022
commit 97cb621d1e0bb8167a54b06b6e899f9d95826b85
8 changes: 8 additions & 0 deletions eml_parser/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
HEADERS = {
"authentication_results": "Authentication-Results"
}
INDICATORS = {
"dkim": "dkim",
"dmarc": "dmarc",
"spf": "spf"
}
15 changes: 8 additions & 7 deletions eml_parser/indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json

import eml_parser.helper as helper
from eml_parser.constants import HEADERS, INDICATORS


class Indicators(object):
Expand All @@ -12,9 +13,9 @@ def __init__(self, content: str, headers: list):
self.sha256 = hashlib.sha256(encoded_content).hexdigest()

auth_types = self.parse_auth_results_header(headers)
self.dkim = auth_types.get("dkim", None)
self.dmarc = auth_types.get("dmarc", None)
self.spf = auth_types.get("spf", None)
self.dkim = auth_types.get(INDICATORS.get("dkim"), None)
self.dmarc = auth_types.get(INDICATORS.get("dmarc"), None)
self.spf = auth_types.get(INDICATORS.get("spf"), None)

# May not need this
def make_serializable(self) -> dict:
Expand Down Expand Up @@ -54,7 +55,7 @@ def parse_auth_results_header(headers: list) -> dict:
if headers:
for header in headers:
name = header.get("name")
if name == "Authentication-Results":
if name == HEADERS.get("authentication_results"):
value = header.get("value")
break

Expand All @@ -63,10 +64,10 @@ def parse_auth_results_header(headers: list) -> dict:
for auth_type in split_header:
stripped_auth_type = auth_type.strip().replace("\n", "")
if stripped_auth_type.startswith("dkim"):
auth_types["dkim"] = stripped_auth_type
auth_types[INDICATORS.get("dkim")] = stripped_auth_type
elif stripped_auth_type.startswith("dmarc"):
auth_types["dmarc"] = stripped_auth_type
auth_types[INDICATORS.get("dmarc")] = stripped_auth_type
elif stripped_auth_type.startswith("spf"):
auth_types["spf"] = stripped_auth_type
auth_types[INDICATORS.get("spf")] = stripped_auth_type

return auth_types