FA-76376 / Email MIME structure / Open access
Assign IMAP-style section numbers to body parts: nested container number · case 01
Nested multipart containers are flattened, so their children collide with their siblings' numbers.
ROOT CAUSE
The nested container number decision evaluates `walk(child, prefix if child['type'].startswith('multipart/') else prefix + [str(i)])` where the contract requires `walk(child, prefix + [str(i)])`.
VERIFIED REPAIR
Use `walk(child, prefix + [str(i)])` for the nested container number decision and keep every other rule of the model unchanged.
Unsuccessful approach: Flattening only alternatives still collides the alternative's children with later siblings. The attempted `walk(child, prefix if child['type'] == 'multipart/alternative' else prefix + [str(i)])` still disagrees with a fixture.
Case contract
Returns [section, type] for every non-multipart entity in depth-first order. A single-part message body is section "1". Children of a multipart are numbered 1..n under the parent's number (nested multiparts get their own number). A message/rfc822 part is listed itself; if its encapsulated body is multipart, that body's children are numbered directly under the message part (P.1, P.2...); a single-part encapsulated body is P.1.
Why this case matters
Section numbers are how clients fetch individual parts; off-by-one numbering downloads the wrong attachment.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(tree):
out = []
def walk(node, prefix):
t = node['type']
if t.startswith('multipart/'):
for i, child in enumerate(node['parts'], 1):
walk(child, prefix if child['type'].startswith('multipart/') else prefix + [str(i)])
elif t == 'message/rfc822':
out.append(['.'.join(prefix), t])
inner = node['body']
if inner['type'].startswith('multipart/'):
walk(inner, prefix)
else:
walk(inner, prefix + ['1'])
else:
out.append(['.'.join(prefix) or '1', t])
walk(tree, [])
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('single part message', ({'type': 'text/plain'},), [['1', 'text/plain']]), ('flat mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream'}]},), [['1', 'text/plain'], ['2', 'application/octet-stream']]), ('alternative inside mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, {'type': 'application/pdf'}]},), [['1.1', 'text/plain'], ['1.2', 'text/html'], ['2', 'application/pdf']]), ('attached multipart message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/jpeg'}]}}]},), [['1', 'text/plain'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'image/jpeg']]), ('attached single part message', ({'type': 'multipart/mixed', 'parts': [{'type': 'message/rfc822', 'body': {'type': 'text/plain'}}]},), [['1', 'message/rfc822'], ['1.1', 'text/plain']]), ('related and forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/related', 'parts': [{'type': 'text/html'}, {'type': 'image/gif'}]}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}}]},), [['1.1', 'text/html'], ['1.2', 'image/gif'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'text/html']])], 2: [('single part message', ({'type': 'text/html'},), [['1', 'text/html']]), ('flat mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}]},), [['1', 'text/plain'], ['2', 'application/octet-stream'], ['3', 'application/octet-stream']]), ('alternative inside mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, {'type': 'application/pdf'}]},), [['1.1', 'text/plain'], ['1.2', 'text/html'], ['2', 'application/pdf']]), ('attached multipart message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/jpeg'}]}}]},), [['1', 'text/plain'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'image/jpeg']]), ('attached single part message', ({'type': 'multipart/mixed', 'parts': [{'type': 'message/rfc822', 'body': {'type': 'text/plain'}}]},), [['1', 'message/rfc822'], ['1.1', 'text/plain']]), ('related and forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/related', 'parts': [{'type': 'text/html'}, {'type': 'image/gif'}]}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}}]},), [['1.1', 'text/html'], ['1.2', 'image/gif'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'text/html']])], 3: [('single part message', ({'type': 'application/pdf'},), [['1', 'application/pdf']]), ('flat mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}]},), [['1', 'text/plain'], ['2', 'application/octet-stream'], ['3', 'application/octet-stream'], ['4', 'application/octet-stream']]), ('alternative inside mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, {'type': 'application/pdf'}]},), [['1.1', 'text/plain'], ['1.2', 'text/html'], ['2', 'application/pdf']]), ('attached multipart message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/jpeg'}]}}]},), [['1', 'text/plain'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'image/jpeg']]), ('attached single part message', ({'type': 'multipart/mixed', 'parts': [{'type': 'message/rfc822', 'body': {'type': 'text/plain'}}]},), [['1', 'message/rfc822'], ['1.1', 'text/plain']]), ('related and forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/related', 'parts': [{'type': 'text/html'}, {'type': 'image/gif'}]}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}}]},), [['1.1', 'text/html'], ['1.2', 'image/gif'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'text/html']])], 4: [('single part message', ({'type': 'image/png'},), [['1', 'image/png']]), ('flat mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}]},), [['1', 'text/plain'], ['2', 'application/octet-stream'], ['3', 'application/octet-stream'], ['4', 'application/octet-stream'], ['5', 'application/octet-stream']]), ('alternative inside mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, {'type': 'application/pdf'}]},), [['1.1', 'text/plain'], ['1.2', 'text/html'], ['2', 'application/pdf']]), ('attached multipart message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/jpeg'}]}}]},), [['1', 'text/plain'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'image/jpeg']]), ('attached single part message', ({'type': 'multipart/mixed', 'parts': [{'type': 'message/rfc822', 'body': {'type': 'text/plain'}}]},), [['1', 'message/rfc822'], ['1.1', 'text/plain']]), ('related and forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/related', 'parts': [{'type': 'text/html'}, {'type': 'image/gif'}]}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}}]},), [['1.1', 'text/html'], ['1.2', 'image/gif'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'text/html']])], 5: [('single part message', ({'type': 'text/calendar'},), [['1', 'text/calendar']]), ('flat mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}]},), [['1', 'text/plain'], ['2', 'application/octet-stream'], ['3', 'application/octet-stream'], ['4', 'application/octet-stream'], ['5', 'application/octet-stream'], ['6', 'application/octet-stream']]), ('alternative inside mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, {'type': 'application/pdf'}]},), [['1.1', 'text/plain'], ['1.2', 'text/html'], ['2', 'application/pdf']]), ('attached multipart message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/jpeg'}]}}]},), [['1', 'text/plain'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'image/jpeg']]), ('attached single part message', ({'type': 'multipart/mixed', 'parts': [{'type': 'message/rfc822', 'body': {'type': 'text/plain'}}]},), [['1', 'message/rfc822'], ['1.1', 'text/plain']]), ('related and forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/related', 'parts': [{'type': 'text/html'}, {'type': 'image/gif'}]}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}}]},), [['1.1', 'text/html'], ['1.2', 'image/gif'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'text/html']])]}
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 |
|---|---|---|---|
| single part message | [['1', 'text/plain']] | [['1', 'text/plain']] | Passed |
| flat mixed | [['1', 'text/plain'], ['2', 'application/octet-stream']] | [['1', 'text/plain'], ['2', 'application/octet-stream']] | Passed |
| alternative inside mixed | [['1', 'text/plain'], ['2', 'text/html'], ['2', 'application/pdf']] | [['1.1', 'text/plain'], ['1.2', 'text/html'], ['2', 'application/pdf']] | Failed |
| attached multipart message | [['1', 'text/plain'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'image/jpeg']] | [['1', 'text/plain'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'image/jpeg']] | Passed |
| attached single part message | [['1', 'message/rfc822'], ['1.1', 'text/plain']] | [['1', 'message/rfc822'], ['1.1', 'text/plain']] | Passed |
| related and forwarded alternative | [['1', 'text/html'], ['2', 'image/gif'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'text/html']] | [['1.1', 'text/html'], ['1.2', 'image/gif'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'text/html']] | Failed |
SHA-256 / 319651e2c7d0d184afb70e45da9b9663c8886f00c5da4b9ec0f76d6537cba5b0
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(tree):
out = []
def walk(node, prefix):
t = node['type']
if t.startswith('multipart/'):
for i, child in enumerate(node['parts'], 1):
walk(child, prefix if child['type'] == 'multipart/alternative' else prefix + [str(i)])
elif t == 'message/rfc822':
out.append(['.'.join(prefix), t])
inner = node['body']
if inner['type'].startswith('multipart/'):
walk(inner, prefix)
else:
walk(inner, prefix + ['1'])
else:
out.append(['.'.join(prefix) or '1', t])
walk(tree, [])
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('single part message', ({'type': 'text/plain'},), [['1', 'text/plain']]), ('flat mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream'}]},), [['1', 'text/plain'], ['2', 'application/octet-stream']]), ('alternative inside mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, {'type': 'application/pdf'}]},), [['1.1', 'text/plain'], ['1.2', 'text/html'], ['2', 'application/pdf']]), ('attached multipart message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/jpeg'}]}}]},), [['1', 'text/plain'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'image/jpeg']]), ('attached single part message', ({'type': 'multipart/mixed', 'parts': [{'type': 'message/rfc822', 'body': {'type': 'text/plain'}}]},), [['1', 'message/rfc822'], ['1.1', 'text/plain']]), ('related and forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/related', 'parts': [{'type': 'text/html'}, {'type': 'image/gif'}]}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}}]},), [['1.1', 'text/html'], ['1.2', 'image/gif'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'text/html']])], 2: [('single part message', ({'type': 'text/html'},), [['1', 'text/html']]), ('flat mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}]},), [['1', 'text/plain'], ['2', 'application/octet-stream'], ['3', 'application/octet-stream']]), ('alternative inside mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, {'type': 'application/pdf'}]},), [['1.1', 'text/plain'], ['1.2', 'text/html'], ['2', 'application/pdf']]), ('attached multipart message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/jpeg'}]}}]},), [['1', 'text/plain'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'image/jpeg']]), ('attached single part message', ({'type': 'multipart/mixed', 'parts': [{'type': 'message/rfc822', 'body': {'type': 'text/plain'}}]},), [['1', 'message/rfc822'], ['1.1', 'text/plain']]), ('related and forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/related', 'parts': [{'type': 'text/html'}, {'type': 'image/gif'}]}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}}]},), [['1.1', 'text/html'], ['1.2', 'image/gif'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'text/html']])], 3: [('single part message', ({'type': 'application/pdf'},), [['1', 'application/pdf']]), ('flat mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}]},), [['1', 'text/plain'], ['2', 'application/octet-stream'], ['3', 'application/octet-stream'], ['4', 'application/octet-stream']]), ('alternative inside mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, {'type': 'application/pdf'}]},), [['1.1', 'text/plain'], ['1.2', 'text/html'], ['2', 'application/pdf']]), ('attached multipart message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/jpeg'}]}}]},), [['1', 'text/plain'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'image/jpeg']]), ('attached single part message', ({'type': 'multipart/mixed', 'parts': [{'type': 'message/rfc822', 'body': {'type': 'text/plain'}}]},), [['1', 'message/rfc822'], ['1.1', 'text/plain']]), ('related and forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/related', 'parts': [{'type': 'text/html'}, {'type': 'image/gif'}]}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}}]},), [['1.1', 'text/html'], ['1.2', 'image/gif'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'text/html']])], 4: [('single part message', ({'type': 'image/png'},), [['1', 'image/png']]), ('flat mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}]},), [['1', 'text/plain'], ['2', 'application/octet-stream'], ['3', 'application/octet-stream'], ['4', 'application/octet-stream'], ['5', 'application/octet-stream']]), ('alternative inside mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, {'type': 'application/pdf'}]},), [['1.1', 'text/plain'], ['1.2', 'text/html'], ['2', 'application/pdf']]), ('attached multipart message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/jpeg'}]}}]},), [['1', 'text/plain'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'image/jpeg']]), ('attached single part message', ({'type': 'multipart/mixed', 'parts': [{'type': 'message/rfc822', 'body': {'type': 'text/plain'}}]},), [['1', 'message/rfc822'], ['1.1', 'text/plain']]), ('related and forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/related', 'parts': [{'type': 'text/html'}, {'type': 'image/gif'}]}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}}]},), [['1.1', 'text/html'], ['1.2', 'image/gif'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'text/html']])], 5: [('single part message', ({'type': 'text/calendar'},), [['1', 'text/calendar']]), ('flat mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}]},), [['1', 'text/plain'], ['2', 'application/octet-stream'], ['3', 'application/octet-stream'], ['4', 'application/octet-stream'], ['5', 'application/octet-stream'], ['6', 'application/octet-stream']]), ('alternative inside mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, {'type': 'application/pdf'}]},), [['1.1', 'text/plain'], ['1.2', 'text/html'], ['2', 'application/pdf']]), ('attached multipart message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/jpeg'}]}}]},), [['1', 'text/plain'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'image/jpeg']]), ('attached single part message', ({'type': 'multipart/mixed', 'parts': [{'type': 'message/rfc822', 'body': {'type': 'text/plain'}}]},), [['1', 'message/rfc822'], ['1.1', 'text/plain']]), ('related and forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/related', 'parts': [{'type': 'text/html'}, {'type': 'image/gif'}]}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}}]},), [['1.1', 'text/html'], ['1.2', 'image/gif'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'text/html']])]}
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 |
|---|---|---|---|
| single part message | [['1', 'text/plain']] | [['1', 'text/plain']] | Passed |
| flat mixed | [['1', 'text/plain'], ['2', 'application/octet-stream']] | [['1', 'text/plain'], ['2', 'application/octet-stream']] | Passed |
| alternative inside mixed | [['1', 'text/plain'], ['2', 'text/html'], ['2', 'application/pdf']] | [['1.1', 'text/plain'], ['1.2', 'text/html'], ['2', 'application/pdf']] | Failed |
| attached multipart message | [['1', 'text/plain'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'image/jpeg']] | [['1', 'text/plain'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'image/jpeg']] | Passed |
| attached single part message | [['1', 'message/rfc822'], ['1.1', 'text/plain']] | [['1', 'message/rfc822'], ['1.1', 'text/plain']] | Passed |
| related and forwarded alternative | [['1.1', 'text/html'], ['1.2', 'image/gif'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'text/html']] | [['1.1', 'text/html'], ['1.2', 'image/gif'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'text/html']] | Passed |
SHA-256 / 984e48760c2df5d8cc366b550a15b4f6dec81a90c43db12c7a1481212046c8a5
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(tree):
out = []
def walk(node, prefix):
t = node['type']
if t.startswith('multipart/'):
for i, child in enumerate(node['parts'], 1):
walk(child, prefix + [str(i)])
elif t == 'message/rfc822':
out.append(['.'.join(prefix), t])
inner = node['body']
if inner['type'].startswith('multipart/'):
walk(inner, prefix)
else:
walk(inner, prefix + ['1'])
else:
out.append(['.'.join(prefix) or '1', t])
walk(tree, [])
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('single part message', ({'type': 'text/plain'},), [['1', 'text/plain']]), ('flat mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream'}]},), [['1', 'text/plain'], ['2', 'application/octet-stream']]), ('alternative inside mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, {'type': 'application/pdf'}]},), [['1.1', 'text/plain'], ['1.2', 'text/html'], ['2', 'application/pdf']]), ('attached multipart message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/jpeg'}]}}]},), [['1', 'text/plain'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'image/jpeg']]), ('attached single part message', ({'type': 'multipart/mixed', 'parts': [{'type': 'message/rfc822', 'body': {'type': 'text/plain'}}]},), [['1', 'message/rfc822'], ['1.1', 'text/plain']]), ('related and forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/related', 'parts': [{'type': 'text/html'}, {'type': 'image/gif'}]}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}}]},), [['1.1', 'text/html'], ['1.2', 'image/gif'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'text/html']])], 2: [('single part message', ({'type': 'text/html'},), [['1', 'text/html']]), ('flat mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}]},), [['1', 'text/plain'], ['2', 'application/octet-stream'], ['3', 'application/octet-stream']]), ('alternative inside mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, {'type': 'application/pdf'}]},), [['1.1', 'text/plain'], ['1.2', 'text/html'], ['2', 'application/pdf']]), ('attached multipart message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/jpeg'}]}}]},), [['1', 'text/plain'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'image/jpeg']]), ('attached single part message', ({'type': 'multipart/mixed', 'parts': [{'type': 'message/rfc822', 'body': {'type': 'text/plain'}}]},), [['1', 'message/rfc822'], ['1.1', 'text/plain']]), ('related and forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/related', 'parts': [{'type': 'text/html'}, {'type': 'image/gif'}]}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}}]},), [['1.1', 'text/html'], ['1.2', 'image/gif'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'text/html']])], 3: [('single part message', ({'type': 'application/pdf'},), [['1', 'application/pdf']]), ('flat mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}]},), [['1', 'text/plain'], ['2', 'application/octet-stream'], ['3', 'application/octet-stream'], ['4', 'application/octet-stream']]), ('alternative inside mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, {'type': 'application/pdf'}]},), [['1.1', 'text/plain'], ['1.2', 'text/html'], ['2', 'application/pdf']]), ('attached multipart message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/jpeg'}]}}]},), [['1', 'text/plain'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'image/jpeg']]), ('attached single part message', ({'type': 'multipart/mixed', 'parts': [{'type': 'message/rfc822', 'body': {'type': 'text/plain'}}]},), [['1', 'message/rfc822'], ['1.1', 'text/plain']]), ('related and forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/related', 'parts': [{'type': 'text/html'}, {'type': 'image/gif'}]}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}}]},), [['1.1', 'text/html'], ['1.2', 'image/gif'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'text/html']])], 4: [('single part message', ({'type': 'image/png'},), [['1', 'image/png']]), ('flat mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}]},), [['1', 'text/plain'], ['2', 'application/octet-stream'], ['3', 'application/octet-stream'], ['4', 'application/octet-stream'], ['5', 'application/octet-stream']]), ('alternative inside mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, {'type': 'application/pdf'}]},), [['1.1', 'text/plain'], ['1.2', 'text/html'], ['2', 'application/pdf']]), ('attached multipart message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/jpeg'}]}}]},), [['1', 'text/plain'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'image/jpeg']]), ('attached single part message', ({'type': 'multipart/mixed', 'parts': [{'type': 'message/rfc822', 'body': {'type': 'text/plain'}}]},), [['1', 'message/rfc822'], ['1.1', 'text/plain']]), ('related and forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/related', 'parts': [{'type': 'text/html'}, {'type': 'image/gif'}]}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}}]},), [['1.1', 'text/html'], ['1.2', 'image/gif'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'text/html']])], 5: [('single part message', ({'type': 'text/calendar'},), [['1', 'text/calendar']]), ('flat mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}, {'type': 'application/octet-stream'}]},), [['1', 'text/plain'], ['2', 'application/octet-stream'], ['3', 'application/octet-stream'], ['4', 'application/octet-stream'], ['5', 'application/octet-stream'], ['6', 'application/octet-stream']]), ('alternative inside mixed', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}, {'type': 'application/pdf'}]},), [['1.1', 'text/plain'], ['1.2', 'text/html'], ['2', 'application/pdf']]), ('attached multipart message', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain'}, {'type': 'image/jpeg'}]}}]},), [['1', 'text/plain'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'image/jpeg']]), ('attached single part message', ({'type': 'multipart/mixed', 'parts': [{'type': 'message/rfc822', 'body': {'type': 'text/plain'}}]},), [['1', 'message/rfc822'], ['1.1', 'text/plain']]), ('related and forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'multipart/related', 'parts': [{'type': 'text/html'}, {'type': 'image/gif'}]}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain'}, {'type': 'text/html'}]}}]},), [['1.1', 'text/html'], ['1.2', 'image/gif'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'text/html']])]}
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 |
|---|---|---|---|
| single part message | [['1', 'text/plain']] | [['1', 'text/plain']] | Passed |
| flat mixed | [['1', 'text/plain'], ['2', 'application/octet-stream']] | [['1', 'text/plain'], ['2', 'application/octet-stream']] | Passed |
| alternative inside mixed | [['1.1', 'text/plain'], ['1.2', 'text/html'], ['2', 'application/pdf']] | [['1.1', 'text/plain'], ['1.2', 'text/html'], ['2', 'application/pdf']] | Passed |
| attached multipart message | [['1', 'text/plain'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'image/jpeg']] | [['1', 'text/plain'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'image/jpeg']] | Passed |
| attached single part message | [['1', 'message/rfc822'], ['1.1', 'text/plain']] | [['1', 'message/rfc822'], ['1.1', 'text/plain']] | Passed |
| related and forwarded alternative | [['1.1', 'text/html'], ['1.2', 'image/gif'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'text/html']] | [['1.1', 'text/html'], ['1.2', 'image/gif'], ['2', 'message/rfc822'], ['2.1', 'text/plain'], ['2.2', 'text/html']] | Passed |
SHA-256 / ad5cec88e1b7ca24cbb6b0d7c8ddb097e26f0e6d7e2472f7788ba4506d953001
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:15.829963+00:00.
Case digest / 3a004a833478f117cbf41c6bf4fbac64d4a4f5fcae62b5a2df9a8cd44c6b7418