FA-76476 / Email MIME structure / Open access
Resolve cid: references inside multipart/related: percent decoding · case 01
A reference with percent-encoded characters never matches its part.
ROOT CAUSE
The percent decoding decision evaluates `ref[4:]` where the contract requires `unquote(ref[4:])`.
VERIFIED REPAIR
Use `unquote(ref[4:])` for the percent decoding decision and keep every other rule of the model unchanged.
Unsuccessful approach: Decoding only the at-sign leaves other escapes such as %2B undecoded. The attempted `ref[4:].replace('%40', '@')` still disagrees with a fixture.
Case contract
related has params (optional start, with angle brackets) and parts with optional cid values such as " <img@x> ". Content ids are compared after trimming spaces and angle brackets. The root is the part whose id equals the start id, else the first part. Each reference is a URL; the "cid:" scheme is case-insensitive and the rest is percent-decoded. A reference resolves to the first non-root part with an equal id, else None. Result {root, resolved [[ref, index]...], unused: non-root indexes nobody referenced}.
Why this case matters
Inline images and style sheets in HTML mail are located through Content-ID references.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
from urllib.parse import unquote
N = 1
observations = []
def solve(related, html_refs):
def norm(c):
return (c or '').strip().strip('<>').strip()
ids = [norm(p.get('cid')) for p in related['parts']]
start = norm(related.get('params', {}).get('start'))
root = ids.index(start) if start and start in ids else 0
resolved = []
used = set()
for ref in html_refs:
target = ref[4:] if ref[:4].lower() == 'cid:' else None
hit = None
for i, c in enumerate(ids):
if i != root and target and c == target:
hit = i
break
if hit is not None:
used.add(hit)
resolved.append([ref, hit])
unused = [i for i in range(len(ids)) if i != root and i not in used]
return {'root': root, 'resolved': resolved, 'unused': unused}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('padded content id', ({'parts': [{'cid': '<root@x>'}, {'cid': ' <pic1@x> '}]}, ['cid:pic1@x']), {'resolved': [['cid:pic1@x', 1]], 'root': 0, 'unused': []}), ('scheme casing', ({'parts': [{'cid': '<root@x>'}, {'cid': '<pic@x>'}]}, ['CID:pic@x', 'Cid:pic@x', 'http://pic@x']), {'resolved': [['CID:pic@x', 1], ['Cid:pic@x', 1], ['http://pic@x', None]], 'root': 0, 'unused': []}), ('percent-encoded reference', ({'parts': [{}, {'cid': '<a+b1@x>'}]}, ['cid:a%2Bb1%40x']), {'resolved': [['cid:a%2Bb1%40x', 1]], 'root': 0, 'unused': []}), ('root referenced by itself', ({'params': {'start': '<root@x>'}, 'parts': [{'cid': '<pic@x>'}, {'cid': '<root@x>'}]}, ['cid:root@x', 'cid:pic@x']), {'resolved': [['cid:root@x', None], ['cid:pic@x', 0]], 'root': 1, 'unused': []}), ('no start and an id-less part', ({'params': {}, 'parts': [{'cid': '<doc@x>'}, {}, {'cid': '<p1@x>'}]}, ['cid:p1@x']), {'resolved': [['cid:p1@x', 2]], 'root': 0, 'unused': [1]}), ('unused parts with late root', ({'params': {'start': '<r@x>'}, 'parts': [{'cid': '<a@x>'}, {'cid': '<b@x>'}, {'cid': '<r@x>'}]}, ['cid:a@x']), {'resolved': [['cid:a@x', 0]], 'root': 2, 'unused': [1]})], 2: [('padded content id', ({'parts': [{'cid': '<root@x>'}, {'cid': ' <pic2@x> '}]}, ['cid:pic2@x']), {'resolved': [['cid:pic2@x', 1]], 'root': 0, 'unused': []}), ('scheme casing', ({'parts': [{'cid': '<root@x>'}, {'cid': '<pic@x>'}]}, ['CID:pic@x', 'Cid:pic@x', 'http://pic@x']), {'resolved': [['CID:pic@x', 1], ['Cid:pic@x', 1], ['http://pic@x', None]], 'root': 0, 'unused': []}), ('percent-encoded reference', ({'parts': [{}, {'cid': '<a+b2@x>'}]}, ['cid:a%2Bb2%40x']), {'resolved': [['cid:a%2Bb2%40x', 1]], 'root': 0, 'unused': []}), ('root referenced by itself', ({'params': {'start': '<root@x>'}, 'parts': [{'cid': '<pic@x>'}, {'cid': '<root@x>'}]}, ['cid:root@x', 'cid:pic@x']), {'resolved': [['cid:root@x', None], ['cid:pic@x', 0]], 'root': 1, 'unused': []}), ('no start and an id-less part', ({'params': {}, 'parts': [{'cid': '<doc@x>'}, {}, {'cid': '<p2@x>'}]}, ['cid:p2@x']), {'resolved': [['cid:p2@x', 2]], 'root': 0, 'unused': [1]}), ('unused parts with late root', ({'params': {'start': '<r@x>'}, 'parts': [{'cid': '<a@x>'}, {'cid': '<b@x>'}, {'cid': '<r@x>'}]}, ['cid:a@x']), {'resolved': [['cid:a@x', 0]], 'root': 2, 'unused': [1]})], 3: [('padded content id', ({'parts': [{'cid': '<root@x>'}, {'cid': ' <pic3@x> '}]}, ['cid:pic3@x']), {'resolved': [['cid:pic3@x', 1]], 'root': 0, 'unused': []}), ('scheme casing', ({'parts': [{'cid': '<root@x>'}, {'cid': '<pic@x>'}]}, ['CID:pic@x', 'Cid:pic@x', 'http://pic@x']), {'resolved': [['CID:pic@x', 1], ['Cid:pic@x', 1], ['http://pic@x', None]], 'root': 0, 'unused': []}), ('percent-encoded reference', ({'parts': [{}, {'cid': '<a+b3@x>'}]}, ['cid:a%2Bb3%40x']), {'resolved': [['cid:a%2Bb3%40x', 1]], 'root': 0, 'unused': []}), ('root referenced by itself', ({'params': {'start': '<root@x>'}, 'parts': [{'cid': '<pic@x>'}, {'cid': '<root@x>'}]}, ['cid:root@x', 'cid:pic@x']), {'resolved': [['cid:root@x', None], ['cid:pic@x', 0]], 'root': 1, 'unused': []}), ('no start and an id-less part', ({'params': {}, 'parts': [{'cid': '<doc@x>'}, {}, {'cid': '<p3@x>'}]}, ['cid:p3@x']), {'resolved': [['cid:p3@x', 2]], 'root': 0, 'unused': [1]}), ('unused parts with late root', ({'params': {'start': '<r@x>'}, 'parts': [{'cid': '<a@x>'}, {'cid': '<b@x>'}, {'cid': '<r@x>'}]}, ['cid:a@x']), {'resolved': [['cid:a@x', 0]], 'root': 2, 'unused': [1]})], 4: [('padded content id', ({'parts': [{'cid': '<root@x>'}, {'cid': ' <pic4@x> '}]}, ['cid:pic4@x']), {'resolved': [['cid:pic4@x', 1]], 'root': 0, 'unused': []}), ('scheme casing', ({'parts': [{'cid': '<root@x>'}, {'cid': '<pic@x>'}]}, ['CID:pic@x', 'Cid:pic@x', 'http://pic@x']), {'resolved': [['CID:pic@x', 1], ['Cid:pic@x', 1], ['http://pic@x', None]], 'root': 0, 'unused': []}), ('percent-encoded reference', ({'parts': [{}, {'cid': '<a+b4@x>'}]}, ['cid:a%2Bb4%40x']), {'resolved': [['cid:a%2Bb4%40x', 1]], 'root': 0, 'unused': []}), ('root referenced by itself', ({'params': {'start': '<root@x>'}, 'parts': [{'cid': '<pic@x>'}, {'cid': '<root@x>'}]}, ['cid:root@x', 'cid:pic@x']), {'resolved': [['cid:root@x', None], ['cid:pic@x', 0]], 'root': 1, 'unused': []}), ('no start and an id-less part', ({'params': {}, 'parts': [{'cid': '<doc@x>'}, {}, {'cid': '<p4@x>'}]}, ['cid:p4@x']), {'resolved': [['cid:p4@x', 2]], 'root': 0, 'unused': [1]}), ('unused parts with late root', ({'params': {'start': '<r@x>'}, 'parts': [{'cid': '<a@x>'}, {'cid': '<b@x>'}, {'cid': '<r@x>'}]}, ['cid:a@x']), {'resolved': [['cid:a@x', 0]], 'root': 2, 'unused': [1]})], 5: [('padded content id', ({'parts': [{'cid': '<root@x>'}, {'cid': ' <pic5@x> '}]}, ['cid:pic5@x']), {'resolved': [['cid:pic5@x', 1]], 'root': 0, 'unused': []}), ('scheme casing', ({'parts': [{'cid': '<root@x>'}, {'cid': '<pic@x>'}]}, ['CID:pic@x', 'Cid:pic@x', 'http://pic@x']), {'resolved': [['CID:pic@x', 1], ['Cid:pic@x', 1], ['http://pic@x', None]], 'root': 0, 'unused': []}), ('percent-encoded reference', ({'parts': [{}, {'cid': '<a+b5@x>'}]}, ['cid:a%2Bb5%40x']), {'resolved': [['cid:a%2Bb5%40x', 1]], 'root': 0, 'unused': []}), ('root referenced by itself', ({'params': {'start': '<root@x>'}, 'parts': [{'cid': '<pic@x>'}, {'cid': '<root@x>'}]}, ['cid:root@x', 'cid:pic@x']), {'resolved': [['cid:root@x', None], ['cid:pic@x', 0]], 'root': 1, 'unused': []}), ('no start and an id-less part', ({'params': {}, 'parts': [{'cid': '<doc@x>'}, {}, {'cid': '<p5@x>'}]}, ['cid:p5@x']), {'resolved': [['cid:p5@x', 2]], 'root': 0, 'unused': [1]}), ('unused parts with late root', ({'params': {'start': '<r@x>'}, 'parts': [{'cid': '<a@x>'}, {'cid': '<b@x>'}, {'cid': '<r@x>'}]}, ['cid:a@x']), {'resolved': [['cid:a@x', 0]], 'root': 2, 'unused': [1]})]}
for _label, _args, _expected in _CASES[N]:
check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| padded content id | {'resolved': [['cid:pic1@x', 1]], 'root': 0, 'unused': []} | {'resolved': [['cid:pic1@x', 1]], 'root': 0, 'unused': []} | Passed |
| scheme casing | {'resolved': [['CID:pic@x', 1], ['Cid:pic@x', 1], ['http://pic@x', None]], 'root': 0, 'unused': []} | {'resolved': [['CID:pic@x', 1], ['Cid:pic@x', 1], ['http://pic@x', None]], 'root': 0, 'unused': []} | Passed |
| percent-encoded reference | {'resolved': [['cid:a%2Bb1%40x', None]], 'root': 0, 'unused': [1]} | {'resolved': [['cid:a%2Bb1%40x', 1]], 'root': 0, 'unused': []} | Failed |
| root referenced by itself | {'resolved': [['cid:root@x', None], ['cid:pic@x', 0]], 'root': 1, 'unused': []} | {'resolved': [['cid:root@x', None], ['cid:pic@x', 0]], 'root': 1, 'unused': []} | Passed |
| no start and an id-less part | {'resolved': [['cid:p1@x', 2]], 'root': 0, 'unused': [1]} | {'resolved': [['cid:p1@x', 2]], 'root': 0, 'unused': [1]} | Passed |
| unused parts with late root | {'resolved': [['cid:a@x', 0]], 'root': 2, 'unused': [1]} | {'resolved': [['cid:a@x', 0]], 'root': 2, 'unused': [1]} | Passed |
SHA-256 / cb8449e92e1680c8b011d1d88685d9c48f5cdc4c8dab3abd8ae6dbc583ae025d
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
from urllib.parse import unquote
N = 1
observations = []
def solve(related, html_refs):
def norm(c):
return (c or '').strip().strip('<>').strip()
ids = [norm(p.get('cid')) for p in related['parts']]
start = norm(related.get('params', {}).get('start'))
root = ids.index(start) if start and start in ids else 0
resolved = []
used = set()
for ref in html_refs:
target = ref[4:].replace('%40', '@') if ref[:4].lower() == 'cid:' else None
hit = None
for i, c in enumerate(ids):
if i != root and target and c == target:
hit = i
break
if hit is not None:
used.add(hit)
resolved.append([ref, hit])
unused = [i for i in range(len(ids)) if i != root and i not in used]
return {'root': root, 'resolved': resolved, 'unused': unused}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('padded content id', ({'parts': [{'cid': '<root@x>'}, {'cid': ' <pic1@x> '}]}, ['cid:pic1@x']), {'resolved': [['cid:pic1@x', 1]], 'root': 0, 'unused': []}), ('scheme casing', ({'parts': [{'cid': '<root@x>'}, {'cid': '<pic@x>'}]}, ['CID:pic@x', 'Cid:pic@x', 'http://pic@x']), {'resolved': [['CID:pic@x', 1], ['Cid:pic@x', 1], ['http://pic@x', None]], 'root': 0, 'unused': []}), ('percent-encoded reference', ({'parts': [{}, {'cid': '<a+b1@x>'}]}, ['cid:a%2Bb1%40x']), {'resolved': [['cid:a%2Bb1%40x', 1]], 'root': 0, 'unused': []}), ('root referenced by itself', ({'params': {'start': '<root@x>'}, 'parts': [{'cid': '<pic@x>'}, {'cid': '<root@x>'}]}, ['cid:root@x', 'cid:pic@x']), {'resolved': [['cid:root@x', None], ['cid:pic@x', 0]], 'root': 1, 'unused': []}), ('no start and an id-less part', ({'params': {}, 'parts': [{'cid': '<doc@x>'}, {}, {'cid': '<p1@x>'}]}, ['cid:p1@x']), {'resolved': [['cid:p1@x', 2]], 'root': 0, 'unused': [1]}), ('unused parts with late root', ({'params': {'start': '<r@x>'}, 'parts': [{'cid': '<a@x>'}, {'cid': '<b@x>'}, {'cid': '<r@x>'}]}, ['cid:a@x']), {'resolved': [['cid:a@x', 0]], 'root': 2, 'unused': [1]})], 2: [('padded content id', ({'parts': [{'cid': '<root@x>'}, {'cid': ' <pic2@x> '}]}, ['cid:pic2@x']), {'resolved': [['cid:pic2@x', 1]], 'root': 0, 'unused': []}), ('scheme casing', ({'parts': [{'cid': '<root@x>'}, {'cid': '<pic@x>'}]}, ['CID:pic@x', 'Cid:pic@x', 'http://pic@x']), {'resolved': [['CID:pic@x', 1], ['Cid:pic@x', 1], ['http://pic@x', None]], 'root': 0, 'unused': []}), ('percent-encoded reference', ({'parts': [{}, {'cid': '<a+b2@x>'}]}, ['cid:a%2Bb2%40x']), {'resolved': [['cid:a%2Bb2%40x', 1]], 'root': 0, 'unused': []}), ('root referenced by itself', ({'params': {'start': '<root@x>'}, 'parts': [{'cid': '<pic@x>'}, {'cid': '<root@x>'}]}, ['cid:root@x', 'cid:pic@x']), {'resolved': [['cid:root@x', None], ['cid:pic@x', 0]], 'root': 1, 'unused': []}), ('no start and an id-less part', ({'params': {}, 'parts': [{'cid': '<doc@x>'}, {}, {'cid': '<p2@x>'}]}, ['cid:p2@x']), {'resolved': [['cid:p2@x', 2]], 'root': 0, 'unused': [1]}), ('unused parts with late root', ({'params': {'start': '<r@x>'}, 'parts': [{'cid': '<a@x>'}, {'cid': '<b@x>'}, {'cid': '<r@x>'}]}, ['cid:a@x']), {'resolved': [['cid:a@x', 0]], 'root': 2, 'unused': [1]})], 3: [('padded content id', ({'parts': [{'cid': '<root@x>'}, {'cid': ' <pic3@x> '}]}, ['cid:pic3@x']), {'resolved': [['cid:pic3@x', 1]], 'root': 0, 'unused': []}), ('scheme casing', ({'parts': [{'cid': '<root@x>'}, {'cid': '<pic@x>'}]}, ['CID:pic@x', 'Cid:pic@x', 'http://pic@x']), {'resolved': [['CID:pic@x', 1], ['Cid:pic@x', 1], ['http://pic@x', None]], 'root': 0, 'unused': []}), ('percent-encoded reference', ({'parts': [{}, {'cid': '<a+b3@x>'}]}, ['cid:a%2Bb3%40x']), {'resolved': [['cid:a%2Bb3%40x', 1]], 'root': 0, 'unused': []}), ('root referenced by itself', ({'params': {'start': '<root@x>'}, 'parts': [{'cid': '<pic@x>'}, {'cid': '<root@x>'}]}, ['cid:root@x', 'cid:pic@x']), {'resolved': [['cid:root@x', None], ['cid:pic@x', 0]], 'root': 1, 'unused': []}), ('no start and an id-less part', ({'params': {}, 'parts': [{'cid': '<doc@x>'}, {}, {'cid': '<p3@x>'}]}, ['cid:p3@x']), {'resolved': [['cid:p3@x', 2]], 'root': 0, 'unused': [1]}), ('unused parts with late root', ({'params': {'start': '<r@x>'}, 'parts': [{'cid': '<a@x>'}, {'cid': '<b@x>'}, {'cid': '<r@x>'}]}, ['cid:a@x']), {'resolved': [['cid:a@x', 0]], 'root': 2, 'unused': [1]})], 4: [('padded content id', ({'parts': [{'cid': '<root@x>'}, {'cid': ' <pic4@x> '}]}, ['cid:pic4@x']), {'resolved': [['cid:pic4@x', 1]], 'root': 0, 'unused': []}), ('scheme casing', ({'parts': [{'cid': '<root@x>'}, {'cid': '<pic@x>'}]}, ['CID:pic@x', 'Cid:pic@x', 'http://pic@x']), {'resolved': [['CID:pic@x', 1], ['Cid:pic@x', 1], ['http://pic@x', None]], 'root': 0, 'unused': []}), ('percent-encoded reference', ({'parts': [{}, {'cid': '<a+b4@x>'}]}, ['cid:a%2Bb4%40x']), {'resolved': [['cid:a%2Bb4%40x', 1]], 'root': 0, 'unused': []}), ('root referenced by itself', ({'params': {'start': '<root@x>'}, 'parts': [{'cid': '<pic@x>'}, {'cid': '<root@x>'}]}, ['cid:root@x', 'cid:pic@x']), {'resolved': [['cid:root@x', None], ['cid:pic@x', 0]], 'root': 1, 'unused': []}), ('no start and an id-less part', ({'params': {}, 'parts': [{'cid': '<doc@x>'}, {}, {'cid': '<p4@x>'}]}, ['cid:p4@x']), {'resolved': [['cid:p4@x', 2]], 'root': 0, 'unused': [1]}), ('unused parts with late root', ({'params': {'start': '<r@x>'}, 'parts': [{'cid': '<a@x>'}, {'cid': '<b@x>'}, {'cid': '<r@x>'}]}, ['cid:a@x']), {'resolved': [['cid:a@x', 0]], 'root': 2, 'unused': [1]})], 5: [('padded content id', ({'parts': [{'cid': '<root@x>'}, {'cid': ' <pic5@x> '}]}, ['cid:pic5@x']), {'resolved': [['cid:pic5@x', 1]], 'root': 0, 'unused': []}), ('scheme casing', ({'parts': [{'cid': '<root@x>'}, {'cid': '<pic@x>'}]}, ['CID:pic@x', 'Cid:pic@x', 'http://pic@x']), {'resolved': [['CID:pic@x', 1], ['Cid:pic@x', 1], ['http://pic@x', None]], 'root': 0, 'unused': []}), ('percent-encoded reference', ({'parts': [{}, {'cid': '<a+b5@x>'}]}, ['cid:a%2Bb5%40x']), {'resolved': [['cid:a%2Bb5%40x', 1]], 'root': 0, 'unused': []}), ('root referenced by itself', ({'params': {'start': '<root@x>'}, 'parts': [{'cid': '<pic@x>'}, {'cid': '<root@x>'}]}, ['cid:root@x', 'cid:pic@x']), {'resolved': [['cid:root@x', None], ['cid:pic@x', 0]], 'root': 1, 'unused': []}), ('no start and an id-less part', ({'params': {}, 'parts': [{'cid': '<doc@x>'}, {}, {'cid': '<p5@x>'}]}, ['cid:p5@x']), {'resolved': [['cid:p5@x', 2]], 'root': 0, 'unused': [1]}), ('unused parts with late root', ({'params': {'start': '<r@x>'}, 'parts': [{'cid': '<a@x>'}, {'cid': '<b@x>'}, {'cid': '<r@x>'}]}, ['cid:a@x']), {'resolved': [['cid:a@x', 0]], 'root': 2, 'unused': [1]})]}
for _label, _args, _expected in _CASES[N]:
check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| padded content id | {'resolved': [['cid:pic1@x', 1]], 'root': 0, 'unused': []} | {'resolved': [['cid:pic1@x', 1]], 'root': 0, 'unused': []} | Passed |
| scheme casing | {'resolved': [['CID:pic@x', 1], ['Cid:pic@x', 1], ['http://pic@x', None]], 'root': 0, 'unused': []} | {'resolved': [['CID:pic@x', 1], ['Cid:pic@x', 1], ['http://pic@x', None]], 'root': 0, 'unused': []} | Passed |
| percent-encoded reference | {'resolved': [['cid:a%2Bb1%40x', None]], 'root': 0, 'unused': [1]} | {'resolved': [['cid:a%2Bb1%40x', 1]], 'root': 0, 'unused': []} | Failed |
| root referenced by itself | {'resolved': [['cid:root@x', None], ['cid:pic@x', 0]], 'root': 1, 'unused': []} | {'resolved': [['cid:root@x', None], ['cid:pic@x', 0]], 'root': 1, 'unused': []} | Passed |
| no start and an id-less part | {'resolved': [['cid:p1@x', 2]], 'root': 0, 'unused': [1]} | {'resolved': [['cid:p1@x', 2]], 'root': 0, 'unused': [1]} | Passed |
| unused parts with late root | {'resolved': [['cid:a@x', 0]], 'root': 2, 'unused': [1]} | {'resolved': [['cid:a@x', 0]], 'root': 2, 'unused': [1]} | Passed |
SHA-256 / 762114d501c7e668fa3c29319ef4699ff5575ceb4ed442b521c3bf8588cf412e
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
from urllib.parse import unquote
N = 1
observations = []
def solve(related, html_refs):
def norm(c):
return (c or '').strip().strip('<>').strip()
ids = [norm(p.get('cid')) for p in related['parts']]
start = norm(related.get('params', {}).get('start'))
root = ids.index(start) if start and start in ids else 0
resolved = []
used = set()
for ref in html_refs:
target = unquote(ref[4:]) if ref[:4].lower() == 'cid:' else None
hit = None
for i, c in enumerate(ids):
if i != root and target and c == target:
hit = i
break
if hit is not None:
used.add(hit)
resolved.append([ref, hit])
unused = [i for i in range(len(ids)) if i != root and i not in used]
return {'root': root, 'resolved': resolved, 'unused': unused}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('padded content id', ({'parts': [{'cid': '<root@x>'}, {'cid': ' <pic1@x> '}]}, ['cid:pic1@x']), {'resolved': [['cid:pic1@x', 1]], 'root': 0, 'unused': []}), ('scheme casing', ({'parts': [{'cid': '<root@x>'}, {'cid': '<pic@x>'}]}, ['CID:pic@x', 'Cid:pic@x', 'http://pic@x']), {'resolved': [['CID:pic@x', 1], ['Cid:pic@x', 1], ['http://pic@x', None]], 'root': 0, 'unused': []}), ('percent-encoded reference', ({'parts': [{}, {'cid': '<a+b1@x>'}]}, ['cid:a%2Bb1%40x']), {'resolved': [['cid:a%2Bb1%40x', 1]], 'root': 0, 'unused': []}), ('root referenced by itself', ({'params': {'start': '<root@x>'}, 'parts': [{'cid': '<pic@x>'}, {'cid': '<root@x>'}]}, ['cid:root@x', 'cid:pic@x']), {'resolved': [['cid:root@x', None], ['cid:pic@x', 0]], 'root': 1, 'unused': []}), ('no start and an id-less part', ({'params': {}, 'parts': [{'cid': '<doc@x>'}, {}, {'cid': '<p1@x>'}]}, ['cid:p1@x']), {'resolved': [['cid:p1@x', 2]], 'root': 0, 'unused': [1]}), ('unused parts with late root', ({'params': {'start': '<r@x>'}, 'parts': [{'cid': '<a@x>'}, {'cid': '<b@x>'}, {'cid': '<r@x>'}]}, ['cid:a@x']), {'resolved': [['cid:a@x', 0]], 'root': 2, 'unused': [1]})], 2: [('padded content id', ({'parts': [{'cid': '<root@x>'}, {'cid': ' <pic2@x> '}]}, ['cid:pic2@x']), {'resolved': [['cid:pic2@x', 1]], 'root': 0, 'unused': []}), ('scheme casing', ({'parts': [{'cid': '<root@x>'}, {'cid': '<pic@x>'}]}, ['CID:pic@x', 'Cid:pic@x', 'http://pic@x']), {'resolved': [['CID:pic@x', 1], ['Cid:pic@x', 1], ['http://pic@x', None]], 'root': 0, 'unused': []}), ('percent-encoded reference', ({'parts': [{}, {'cid': '<a+b2@x>'}]}, ['cid:a%2Bb2%40x']), {'resolved': [['cid:a%2Bb2%40x', 1]], 'root': 0, 'unused': []}), ('root referenced by itself', ({'params': {'start': '<root@x>'}, 'parts': [{'cid': '<pic@x>'}, {'cid': '<root@x>'}]}, ['cid:root@x', 'cid:pic@x']), {'resolved': [['cid:root@x', None], ['cid:pic@x', 0]], 'root': 1, 'unused': []}), ('no start and an id-less part', ({'params': {}, 'parts': [{'cid': '<doc@x>'}, {}, {'cid': '<p2@x>'}]}, ['cid:p2@x']), {'resolved': [['cid:p2@x', 2]], 'root': 0, 'unused': [1]}), ('unused parts with late root', ({'params': {'start': '<r@x>'}, 'parts': [{'cid': '<a@x>'}, {'cid': '<b@x>'}, {'cid': '<r@x>'}]}, ['cid:a@x']), {'resolved': [['cid:a@x', 0]], 'root': 2, 'unused': [1]})], 3: [('padded content id', ({'parts': [{'cid': '<root@x>'}, {'cid': ' <pic3@x> '}]}, ['cid:pic3@x']), {'resolved': [['cid:pic3@x', 1]], 'root': 0, 'unused': []}), ('scheme casing', ({'parts': [{'cid': '<root@x>'}, {'cid': '<pic@x>'}]}, ['CID:pic@x', 'Cid:pic@x', 'http://pic@x']), {'resolved': [['CID:pic@x', 1], ['Cid:pic@x', 1], ['http://pic@x', None]], 'root': 0, 'unused': []}), ('percent-encoded reference', ({'parts': [{}, {'cid': '<a+b3@x>'}]}, ['cid:a%2Bb3%40x']), {'resolved': [['cid:a%2Bb3%40x', 1]], 'root': 0, 'unused': []}), ('root referenced by itself', ({'params': {'start': '<root@x>'}, 'parts': [{'cid': '<pic@x>'}, {'cid': '<root@x>'}]}, ['cid:root@x', 'cid:pic@x']), {'resolved': [['cid:root@x', None], ['cid:pic@x', 0]], 'root': 1, 'unused': []}), ('no start and an id-less part', ({'params': {}, 'parts': [{'cid': '<doc@x>'}, {}, {'cid': '<p3@x>'}]}, ['cid:p3@x']), {'resolved': [['cid:p3@x', 2]], 'root': 0, 'unused': [1]}), ('unused parts with late root', ({'params': {'start': '<r@x>'}, 'parts': [{'cid': '<a@x>'}, {'cid': '<b@x>'}, {'cid': '<r@x>'}]}, ['cid:a@x']), {'resolved': [['cid:a@x', 0]], 'root': 2, 'unused': [1]})], 4: [('padded content id', ({'parts': [{'cid': '<root@x>'}, {'cid': ' <pic4@x> '}]}, ['cid:pic4@x']), {'resolved': [['cid:pic4@x', 1]], 'root': 0, 'unused': []}), ('scheme casing', ({'parts': [{'cid': '<root@x>'}, {'cid': '<pic@x>'}]}, ['CID:pic@x', 'Cid:pic@x', 'http://pic@x']), {'resolved': [['CID:pic@x', 1], ['Cid:pic@x', 1], ['http://pic@x', None]], 'root': 0, 'unused': []}), ('percent-encoded reference', ({'parts': [{}, {'cid': '<a+b4@x>'}]}, ['cid:a%2Bb4%40x']), {'resolved': [['cid:a%2Bb4%40x', 1]], 'root': 0, 'unused': []}), ('root referenced by itself', ({'params': {'start': '<root@x>'}, 'parts': [{'cid': '<pic@x>'}, {'cid': '<root@x>'}]}, ['cid:root@x', 'cid:pic@x']), {'resolved': [['cid:root@x', None], ['cid:pic@x', 0]], 'root': 1, 'unused': []}), ('no start and an id-less part', ({'params': {}, 'parts': [{'cid': '<doc@x>'}, {}, {'cid': '<p4@x>'}]}, ['cid:p4@x']), {'resolved': [['cid:p4@x', 2]], 'root': 0, 'unused': [1]}), ('unused parts with late root', ({'params': {'start': '<r@x>'}, 'parts': [{'cid': '<a@x>'}, {'cid': '<b@x>'}, {'cid': '<r@x>'}]}, ['cid:a@x']), {'resolved': [['cid:a@x', 0]], 'root': 2, 'unused': [1]})], 5: [('padded content id', ({'parts': [{'cid': '<root@x>'}, {'cid': ' <pic5@x> '}]}, ['cid:pic5@x']), {'resolved': [['cid:pic5@x', 1]], 'root': 0, 'unused': []}), ('scheme casing', ({'parts': [{'cid': '<root@x>'}, {'cid': '<pic@x>'}]}, ['CID:pic@x', 'Cid:pic@x', 'http://pic@x']), {'resolved': [['CID:pic@x', 1], ['Cid:pic@x', 1], ['http://pic@x', None]], 'root': 0, 'unused': []}), ('percent-encoded reference', ({'parts': [{}, {'cid': '<a+b5@x>'}]}, ['cid:a%2Bb5%40x']), {'resolved': [['cid:a%2Bb5%40x', 1]], 'root': 0, 'unused': []}), ('root referenced by itself', ({'params': {'start': '<root@x>'}, 'parts': [{'cid': '<pic@x>'}, {'cid': '<root@x>'}]}, ['cid:root@x', 'cid:pic@x']), {'resolved': [['cid:root@x', None], ['cid:pic@x', 0]], 'root': 1, 'unused': []}), ('no start and an id-less part', ({'params': {}, 'parts': [{'cid': '<doc@x>'}, {}, {'cid': '<p5@x>'}]}, ['cid:p5@x']), {'resolved': [['cid:p5@x', 2]], 'root': 0, 'unused': [1]}), ('unused parts with late root', ({'params': {'start': '<r@x>'}, 'parts': [{'cid': '<a@x>'}, {'cid': '<b@x>'}, {'cid': '<r@x>'}]}, ['cid:a@x']), {'resolved': [['cid:a@x', 0]], 'root': 2, 'unused': [1]})]}
for _label, _args, _expected in _CASES[N]:
check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| padded content id | {'resolved': [['cid:pic1@x', 1]], 'root': 0, 'unused': []} | {'resolved': [['cid:pic1@x', 1]], 'root': 0, 'unused': []} | Passed |
| scheme casing | {'resolved': [['CID:pic@x', 1], ['Cid:pic@x', 1], ['http://pic@x', None]], 'root': 0, 'unused': []} | {'resolved': [['CID:pic@x', 1], ['Cid:pic@x', 1], ['http://pic@x', None]], 'root': 0, 'unused': []} | Passed |
| percent-encoded reference | {'resolved': [['cid:a%2Bb1%40x', 1]], 'root': 0, 'unused': []} | {'resolved': [['cid:a%2Bb1%40x', 1]], 'root': 0, 'unused': []} | Passed |
| root referenced by itself | {'resolved': [['cid:root@x', None], ['cid:pic@x', 0]], 'root': 1, 'unused': []} | {'resolved': [['cid:root@x', None], ['cid:pic@x', 0]], 'root': 1, 'unused': []} | Passed |
| no start and an id-less part | {'resolved': [['cid:p1@x', 2]], 'root': 0, 'unused': [1]} | {'resolved': [['cid:p1@x', 2]], 'root': 0, 'unused': [1]} | Passed |
| unused parts with late root | {'resolved': [['cid:a@x', 0]], 'root': 2, 'unused': [1]} | {'resolved': [['cid:a@x', 0]], 'root': 2, 'unused': [1]} | Passed |
SHA-256 / 4cb75440b3f124aed8eb5ecd5ddc8bb745872d6c02cc6c24872ee2e7cfc85d49
Verification & scope
Stipulated offline model over pre-parsed MIME dictionaries; not a conforming MIME parser, generator or mail client. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:49:16.639580+00:00.
Case digest / 8aa775b506241efc86c7e09f8634258282cec3fb3f9a75db44a8a12f4f128dad