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

Allowing whitespace according to RFC7489 #110

Merged
merged 2 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 12 additions & 4 deletions checkdmarc.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@

__version__ = "4.8.5"

DMARC_VERSION_REGEX_STRING = r"v *= *DMARC1;"
WSP_REGEX = "[ \t]"
DMARC_VERSION_REGEX_STRING = fr"v{WSP_REGEX}*={WSP_REGEX}*DMARC1{WSP_REGEX}*;"
BIMI_VERSION_REGEX_STRING = r"v=BIMI1;"
DMARC_TAG_VALUE_REGEX_STRING = r"([a-z]{1,5}) *= *([\w.:@/+!,_\- ]+)"
DMARC_TAG_VALUE_REGEX_STRING = (
fr"([a-z]{{1,5}}){WSP_REGEX}*={WSP_REGEX}*([\w.:@/+!,_\- ]+)"
)
BIMI_TAG_VALUE_REGEX_STRING = r"([a-z]{1}) *= *(.*)"
MAILTO_REGEX_STRING = r"^(mailto):" \
r"([\w\-!#$%&'*+-/=?^_`{|}~]" \
Expand Down Expand Up @@ -327,7 +330,12 @@ class _DMARCGrammar(Grammar):
"""Defines Pyleri grammar for DMARC records"""
version_tag = Regex(DMARC_VERSION_REGEX_STRING, IGNORECASE)
tag_value = Regex(DMARC_TAG_VALUE_REGEX_STRING, IGNORECASE)
START = Sequence(version_tag, List(tag_value, delimiter=";", opt=True))
START = Sequence(
version_tag,
List(
tag_value,
delimiter=Regex(f"{WSP_REGEX}*;{WSP_REGEX}*"),
opt=True))


class _BIMIGrammar(Grammar):
Expand Down Expand Up @@ -1399,7 +1407,7 @@ def parse_dmarc_record(
# Find explicit tags
for pair in pairs:
tags[pair[0].lower()] = OrderedDict(
[("value", str(pair[1])), ("explicit", True)])
[("value", str(pair[1].strip())), ("explicit", True)])

# Include implicit tags and their defaults
for tag in tag_values.keys():
Expand Down
2 changes: 2 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def testDMARCMixedFormatting(self):
examples = [
"v=DMARC1;p=ReJect",
"v = DMARC1;p=reject;",
"v = DMARC1\t;\tp=reject\t;",
"v = DMARC1\t;\tp\t\t\t=\t\t\treject\t;",
"V=DMARC1;p=reject;"
]

Expand Down
Loading