Skip to content

Commit 19dca17

Browse files
committed
Fix parsing of ani include with a macro value
1 parent 76d8773 commit 19dca17

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

.vscode/launch.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,18 @@
225225
],
226226
"console": "integratedTerminal",
227227
"justMyCode": true
228+
},
229+
{
230+
"name": "checkdmarc --skip-tls wellforce.com",
231+
"type": "debugpy",
232+
"request": "launch",
233+
"module": "checkdmarc._cli",
234+
"args": [
235+
"--skip-tls",
236+
"wellforce.com",
237+
],
238+
"console": "integratedTerminal",
239+
"justMyCode": true
228240
},
229241
{
230242
"name": "checkdmarc --skip-tls wellforce.org",

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#### 1. SPF Record Parsing Structure
88

99
- **Before**: The `parse_spf_record()` function returned a `parsed` dictionary with top-level keys like `"pass"`, `"neutral"`, `"softfail"`, `"fail"`, along with `"include"`, `"redirect"`, `"exp"`, and `"all"`.
10-
- **After**: The `parsed` structure now contains a list of dictionaries under the `"mechanisms"` key. Each entry describes a mechanism (e.g., `mx`, `a`, `include`), and includes additional data such as DNS lookup counts and associated addresses.
10+
- **After**: The `parsed` structure now contains a list of dictionaries under the `"mechanisms"` key. Each entry describes a mechanism (e.g., `mx`, `a`, `include`), and includes additional data such as DNS lookup counts and associated addresses. `"redirect"`, `"exp"`, and `"all"` remain unchanged.
1111

1212
**Example:**
1313

checkdmarc/spf.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,11 @@ def parse_spf_record(
414414
if cidr:
415415
a_records[i] = f"{a_records[i]}/{cidr}"
416416
pairs = [
417+
("action", action),
417418
("mechanism", mechanism),
418419
("value", value),
419420
("dns_lookups", mechanism_dns_lookups),
420421
("void_dns_lookups", mechanism_void_dns_lookups),
421-
("action", action),
422422
("addresses", a_records),
423423
]
424424
parsed["mechanisms"].append(OrderedDict(pairs))
@@ -502,11 +502,11 @@ def parse_spf_record(
502502
)
503503
raise _SPFWarning(str(error))
504504
pairs = [
505+
("action", action),
505506
("mechanism", mechanism),
506507
("value", value),
507508
("dns_lookups", mechanism_dns_lookups),
508509
("void_dns_lookups", mechanism_void_dns_lookups),
509-
("action", action),
510510
]
511511
pairs.append(("hosts", host_ips))
512512
parsed["mechanisms"].append(OrderedDict(pairs))
@@ -516,6 +516,7 @@ def parse_spf_record(
516516
total_dns_lookups += 1
517517
pairs = OrderedDict(
518518
[
519+
("action", action),
519520
("mechanism", mechanism),
520521
("value", value),
521522
("dns_lookups", mechanism_dns_lookups),
@@ -615,10 +616,14 @@ def parse_spf_record(
615616
seen.append(value.lower())
616617

617618
if "%{" in value:
618-
include = OrderedDict(
619-
[("domain", value), ("dns_lookups", 1), ("dns_void_lookups", 0)]
620-
)
621-
parsed["include"].append(include)
619+
include = OrderedDict([
620+
("action", action),
621+
("mechanism", mechanism),
622+
("value", value),
623+
("dns_lookups", mechanism_dns_lookups),
624+
("void_dns_lookups", mechanism_void_dns_lookups),
625+
])
626+
parsed["mechanisms"].append(include)
622627
continue
623628
try:
624629
include_record = query_spf_record(
@@ -698,11 +703,11 @@ def parse_spf_record(
698703
parsed["mechanisms"].append(
699704
OrderedDict(
700705
[
706+
("action", action),
701707
("mechanism", mechanism),
702708
("value", value),
703709
("dns_lookups", mechanism_dns_lookups),
704710
("mechanism_void_dns_lookups", mechanism_void_dns_lookups),
705-
("action", action),
706711
]
707712
)
708713
)

0 commit comments

Comments
 (0)