Skip to content

Commit 7c7e8dd

Browse files
authored
Supporting ra=, rp= and rr= tags from RFC6652 (#158)
* Supporting ra=, rp= and rr= tags from RFC6652 * linter
1 parent 86177e4 commit 7c7e8dd

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

checkdmarc/spf.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
SPF_VERSION_TAG_REGEX_STRING = "v=spf1"
3939
SPF_MECHANISM_REGEX_STRING = (
4040
r"([+\-~?])?"
41-
r"(mx:?|ip4:?|ip6:?|exists:?|include:?|all:?|a:?|redirect=|exp:?|ptr:?)"
41+
r"(mx:?|ip4:?|ip6:?|exists:?|include:?|all:?|a:?|redirect=|exp:?|ptr:?|ra=|rp=|rr=)"
4242
r"([\w+/_.:\-{%}]*)"
4343
)
4444
AFTER_ALL_REGEX_STRING = r"([\s^][+\-~?]?all)\s+.*"
@@ -509,6 +509,27 @@ def parse_spf_record(
509509
"https://tools.ietf.org/html/rfc7208"
510510
"#section-5.5"
511511
)
512+
elif mechanism == "rr":
513+
tokens = value.split(":")
514+
515+
for token in tokens:
516+
if token not in ["all", "e", "f", "s", "n"]:
517+
raise SPFSyntaxError(
518+
f"{token} is not a valid token for the rr tag"
519+
)
520+
521+
parsed["rr"] = result
522+
elif mechanism == "rp":
523+
if not value.isdigit():
524+
raise SPFSyntaxError(
525+
f"{value} is not a valid ra tag value - should be a number"
526+
)
527+
if int(value) < 0 or int(value) > 100:
528+
raise SPFSyntaxError(
529+
f"{value} is not a valid ra tag value - should be a number between 0 and 100"
530+
)
531+
532+
parsed["rp"] = result
512533
else:
513534
parsed[result].append(
514535
OrderedDict([("value", value), ("mechanism", mechanism)])

0 commit comments

Comments
 (0)