FAILURE MAP
← Case archive

FA-76826 / Email MIME structure / Open access

Decide whether a message is interpreted as MIME: first version wins · case 01

A later MIME-Version header overrides an empty first one and turns a legacy message into MIME.

Verified by executionVariant 1 · 7 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The first version wins decision evaluates `if key == 'mime-version':` where the contract requires `if key == 'mime-version' and version is None:`.

VERIFIED REPAIR

Use `if key == 'mime-version' and version is None:` for the first version wins decision and keep every other rule of the model unchanged.

Unsuccessful approach: Replacing only empty values still lets the second header win over the first. The attempted `if key == 'mime-version' and not version:` still disagrees with a fixture.

Case contract

headers are [name, value] pairs with case-insensitive, trimmed names; the first occurrence of MIME-Version and of Content-Type is used. The MIME-Version value, after removing parenthesised comments and all whitespace, must equal "1.0"; otherwise the message is ["text/plain", "non-mime"]. MIME messages report [type, "mime"] with the type taken from the first Content-Type (before ";", trimmed, lower-cased; text/plain when absent or empty).

Why this case matters

Legacy messages without MIME-Version must not have their Content-Type honoured.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import re
N = 1
observations = []
def solve(headers):
    version = None
    ctype = None
    for name, value in headers:
        key = name.strip().lower()
        if key == 'mime-version':
            version = value
        elif key == 'content-type' and ctype is None:
            ctype = value
    clean = re.sub(r'\([^()]*\)', '', version or '')
    clean = ''.join(clean.split())
    if clean != '1.0':
        return ['text/plain', 'non-mime']
    mtype = (ctype or 'text/plain').split(';')[0].strip().lower() or 'text/plain'
    return [mtype, 'mime']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('empty first version header', ([['MIME-Version', ''], ['MIME-Version', '1.0'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('trailing comment', ([['Mime-Version', '1.0 (produced by MetaSend v1)'], ['Content-Type', 'Text/HTML; charset=utf-8']],), ['text/html', 'mime']), ('leading comment', ([['MIME-Version', '(generated) 1.0'], ['content-type', 'image/png']],), ['image/png', 'mime']), ('inner whitespace', ([['MIME-Version', '1 .\t0'], ['Content-Type', 'multipart/mixed; boundary=b1']],), ['multipart/mixed', 'mime']), ('no version header', ([['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('other version', ([['MIME-Version', '1.1'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('empty content type', ([[' MIME-Version ', '1.0'], ['Content-Type', ' ; charset=x']],), ['text/plain', 'mime'])], 2: [('empty first version header', ([['MIME-Version', ''], ['MIME-Version', '1.0'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('trailing comment', ([['Mime-Version', '1.0 (produced by MetaSend v2)'], ['Content-Type', 'Text/HTML; charset=utf-8']],), ['text/html', 'mime']), ('leading comment', ([['MIME-Version', '(generated) 1.0'], ['content-type', 'image/png']],), ['image/png', 'mime']), ('inner whitespace', ([['MIME-Version', '1 .\t0'], ['Content-Type', 'multipart/mixed; boundary=b2']],), ['multipart/mixed', 'mime']), ('no version header', ([['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('other version', ([['MIME-Version', '1.2'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('empty content type', ([[' MIME-Version ', '1.0'], ['Content-Type', ' ; charset=x']],), ['text/plain', 'mime'])], 3: [('empty first version header', ([['MIME-Version', ''], ['MIME-Version', '1.0'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('trailing comment', ([['Mime-Version', '1.0 (produced by MetaSend v3)'], ['Content-Type', 'Text/HTML; charset=utf-8']],), ['text/html', 'mime']), ('leading comment', ([['MIME-Version', '(generated) 1.0'], ['content-type', 'image/png']],), ['image/png', 'mime']), ('inner whitespace', ([['MIME-Version', '1 .\t0'], ['Content-Type', 'multipart/mixed; boundary=b3']],), ['multipart/mixed', 'mime']), ('no version header', ([['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('other version', ([['MIME-Version', '1.3'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('empty content type', ([[' MIME-Version ', '1.0'], ['Content-Type', ' ; charset=x']],), ['text/plain', 'mime'])], 4: [('empty first version header', ([['MIME-Version', ''], ['MIME-Version', '1.0'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('trailing comment', ([['Mime-Version', '1.0 (produced by MetaSend v4)'], ['Content-Type', 'Text/HTML; charset=utf-8']],), ['text/html', 'mime']), ('leading comment', ([['MIME-Version', '(generated) 1.0'], ['content-type', 'image/png']],), ['image/png', 'mime']), ('inner whitespace', ([['MIME-Version', '1 .\t0'], ['Content-Type', 'multipart/mixed; boundary=b4']],), ['multipart/mixed', 'mime']), ('no version header', ([['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('other version', ([['MIME-Version', '1.4'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('empty content type', ([[' MIME-Version ', '1.0'], ['Content-Type', ' ; charset=x']],), ['text/plain', 'mime'])], 5: [('empty first version header', ([['MIME-Version', ''], ['MIME-Version', '1.0'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('trailing comment', ([['Mime-Version', '1.0 (produced by MetaSend v5)'], ['Content-Type', 'Text/HTML; charset=utf-8']],), ['text/html', 'mime']), ('leading comment', ([['MIME-Version', '(generated) 1.0'], ['content-type', 'image/png']],), ['image/png', 'mime']), ('inner whitespace', ([['MIME-Version', '1 .\t0'], ['Content-Type', 'multipart/mixed; boundary=b5']],), ['multipart/mixed', 'mime']), ('no version header', ([['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('other version', ([['MIME-Version', '1.5'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('empty content type', ([[' MIME-Version ', '1.0'], ['Content-Type', ' ; charset=x']],), ['text/plain', 'mime'])]}
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 fixtureActualExpectedOutcome
empty first version header['text/html', 'mime']['text/plain', 'non-mime']Failed
trailing comment['text/html', 'mime']['text/html', 'mime']Passed
leading comment['image/png', 'mime']['image/png', 'mime']Passed
inner whitespace['multipart/mixed', 'mime']['multipart/mixed', 'mime']Passed
no version header['text/plain', 'non-mime']['text/plain', 'non-mime']Passed
other version['text/plain', 'non-mime']['text/plain', 'non-mime']Passed
empty content type['text/plain', 'mime']['text/plain', 'mime']Passed

SHA-256 / 9e4dfc0877c8be486ec22ba6dae3c69f60663332b4928a30bd3d58cd9d1b3d31

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import re
N = 1
observations = []
def solve(headers):
    version = None
    ctype = None
    for name, value in headers:
        key = name.strip().lower()
        if key == 'mime-version' and not version:
            version = value
        elif key == 'content-type' and ctype is None:
            ctype = value
    clean = re.sub(r'\([^()]*\)', '', version or '')
    clean = ''.join(clean.split())
    if clean != '1.0':
        return ['text/plain', 'non-mime']
    mtype = (ctype or 'text/plain').split(';')[0].strip().lower() or 'text/plain'
    return [mtype, 'mime']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('empty first version header', ([['MIME-Version', ''], ['MIME-Version', '1.0'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('trailing comment', ([['Mime-Version', '1.0 (produced by MetaSend v1)'], ['Content-Type', 'Text/HTML; charset=utf-8']],), ['text/html', 'mime']), ('leading comment', ([['MIME-Version', '(generated) 1.0'], ['content-type', 'image/png']],), ['image/png', 'mime']), ('inner whitespace', ([['MIME-Version', '1 .\t0'], ['Content-Type', 'multipart/mixed; boundary=b1']],), ['multipart/mixed', 'mime']), ('no version header', ([['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('other version', ([['MIME-Version', '1.1'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('empty content type', ([[' MIME-Version ', '1.0'], ['Content-Type', ' ; charset=x']],), ['text/plain', 'mime'])], 2: [('empty first version header', ([['MIME-Version', ''], ['MIME-Version', '1.0'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('trailing comment', ([['Mime-Version', '1.0 (produced by MetaSend v2)'], ['Content-Type', 'Text/HTML; charset=utf-8']],), ['text/html', 'mime']), ('leading comment', ([['MIME-Version', '(generated) 1.0'], ['content-type', 'image/png']],), ['image/png', 'mime']), ('inner whitespace', ([['MIME-Version', '1 .\t0'], ['Content-Type', 'multipart/mixed; boundary=b2']],), ['multipart/mixed', 'mime']), ('no version header', ([['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('other version', ([['MIME-Version', '1.2'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('empty content type', ([[' MIME-Version ', '1.0'], ['Content-Type', ' ; charset=x']],), ['text/plain', 'mime'])], 3: [('empty first version header', ([['MIME-Version', ''], ['MIME-Version', '1.0'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('trailing comment', ([['Mime-Version', '1.0 (produced by MetaSend v3)'], ['Content-Type', 'Text/HTML; charset=utf-8']],), ['text/html', 'mime']), ('leading comment', ([['MIME-Version', '(generated) 1.0'], ['content-type', 'image/png']],), ['image/png', 'mime']), ('inner whitespace', ([['MIME-Version', '1 .\t0'], ['Content-Type', 'multipart/mixed; boundary=b3']],), ['multipart/mixed', 'mime']), ('no version header', ([['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('other version', ([['MIME-Version', '1.3'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('empty content type', ([[' MIME-Version ', '1.0'], ['Content-Type', ' ; charset=x']],), ['text/plain', 'mime'])], 4: [('empty first version header', ([['MIME-Version', ''], ['MIME-Version', '1.0'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('trailing comment', ([['Mime-Version', '1.0 (produced by MetaSend v4)'], ['Content-Type', 'Text/HTML; charset=utf-8']],), ['text/html', 'mime']), ('leading comment', ([['MIME-Version', '(generated) 1.0'], ['content-type', 'image/png']],), ['image/png', 'mime']), ('inner whitespace', ([['MIME-Version', '1 .\t0'], ['Content-Type', 'multipart/mixed; boundary=b4']],), ['multipart/mixed', 'mime']), ('no version header', ([['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('other version', ([['MIME-Version', '1.4'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('empty content type', ([[' MIME-Version ', '1.0'], ['Content-Type', ' ; charset=x']],), ['text/plain', 'mime'])], 5: [('empty first version header', ([['MIME-Version', ''], ['MIME-Version', '1.0'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('trailing comment', ([['Mime-Version', '1.0 (produced by MetaSend v5)'], ['Content-Type', 'Text/HTML; charset=utf-8']],), ['text/html', 'mime']), ('leading comment', ([['MIME-Version', '(generated) 1.0'], ['content-type', 'image/png']],), ['image/png', 'mime']), ('inner whitespace', ([['MIME-Version', '1 .\t0'], ['Content-Type', 'multipart/mixed; boundary=b5']],), ['multipart/mixed', 'mime']), ('no version header', ([['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('other version', ([['MIME-Version', '1.5'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('empty content type', ([[' MIME-Version ', '1.0'], ['Content-Type', ' ; charset=x']],), ['text/plain', 'mime'])]}
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 fixtureActualExpectedOutcome
empty first version header['text/html', 'mime']['text/plain', 'non-mime']Failed
trailing comment['text/html', 'mime']['text/html', 'mime']Passed
leading comment['image/png', 'mime']['image/png', 'mime']Passed
inner whitespace['multipart/mixed', 'mime']['multipart/mixed', 'mime']Passed
no version header['text/plain', 'non-mime']['text/plain', 'non-mime']Passed
other version['text/plain', 'non-mime']['text/plain', 'non-mime']Passed
empty content type['text/plain', 'mime']['text/plain', 'mime']Passed

SHA-256 / 348e91325cefb37de033fa535efc32c26c1e5834e78bb771293a6e7ed6b608e3

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import re
N = 1
observations = []
def solve(headers):
    version = None
    ctype = None
    for name, value in headers:
        key = name.strip().lower()
        if key == 'mime-version' and version is None:
            version = value
        elif key == 'content-type' and ctype is None:
            ctype = value
    clean = re.sub(r'\([^()]*\)', '', version or '')
    clean = ''.join(clean.split())
    if clean != '1.0':
        return ['text/plain', 'non-mime']
    mtype = (ctype or 'text/plain').split(';')[0].strip().lower() or 'text/plain'
    return [mtype, 'mime']
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('empty first version header', ([['MIME-Version', ''], ['MIME-Version', '1.0'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('trailing comment', ([['Mime-Version', '1.0 (produced by MetaSend v1)'], ['Content-Type', 'Text/HTML; charset=utf-8']],), ['text/html', 'mime']), ('leading comment', ([['MIME-Version', '(generated) 1.0'], ['content-type', 'image/png']],), ['image/png', 'mime']), ('inner whitespace', ([['MIME-Version', '1 .\t0'], ['Content-Type', 'multipart/mixed; boundary=b1']],), ['multipart/mixed', 'mime']), ('no version header', ([['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('other version', ([['MIME-Version', '1.1'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('empty content type', ([[' MIME-Version ', '1.0'], ['Content-Type', ' ; charset=x']],), ['text/plain', 'mime'])], 2: [('empty first version header', ([['MIME-Version', ''], ['MIME-Version', '1.0'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('trailing comment', ([['Mime-Version', '1.0 (produced by MetaSend v2)'], ['Content-Type', 'Text/HTML; charset=utf-8']],), ['text/html', 'mime']), ('leading comment', ([['MIME-Version', '(generated) 1.0'], ['content-type', 'image/png']],), ['image/png', 'mime']), ('inner whitespace', ([['MIME-Version', '1 .\t0'], ['Content-Type', 'multipart/mixed; boundary=b2']],), ['multipart/mixed', 'mime']), ('no version header', ([['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('other version', ([['MIME-Version', '1.2'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('empty content type', ([[' MIME-Version ', '1.0'], ['Content-Type', ' ; charset=x']],), ['text/plain', 'mime'])], 3: [('empty first version header', ([['MIME-Version', ''], ['MIME-Version', '1.0'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('trailing comment', ([['Mime-Version', '1.0 (produced by MetaSend v3)'], ['Content-Type', 'Text/HTML; charset=utf-8']],), ['text/html', 'mime']), ('leading comment', ([['MIME-Version', '(generated) 1.0'], ['content-type', 'image/png']],), ['image/png', 'mime']), ('inner whitespace', ([['MIME-Version', '1 .\t0'], ['Content-Type', 'multipart/mixed; boundary=b3']],), ['multipart/mixed', 'mime']), ('no version header', ([['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('other version', ([['MIME-Version', '1.3'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('empty content type', ([[' MIME-Version ', '1.0'], ['Content-Type', ' ; charset=x']],), ['text/plain', 'mime'])], 4: [('empty first version header', ([['MIME-Version', ''], ['MIME-Version', '1.0'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('trailing comment', ([['Mime-Version', '1.0 (produced by MetaSend v4)'], ['Content-Type', 'Text/HTML; charset=utf-8']],), ['text/html', 'mime']), ('leading comment', ([['MIME-Version', '(generated) 1.0'], ['content-type', 'image/png']],), ['image/png', 'mime']), ('inner whitespace', ([['MIME-Version', '1 .\t0'], ['Content-Type', 'multipart/mixed; boundary=b4']],), ['multipart/mixed', 'mime']), ('no version header', ([['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('other version', ([['MIME-Version', '1.4'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('empty content type', ([[' MIME-Version ', '1.0'], ['Content-Type', ' ; charset=x']],), ['text/plain', 'mime'])], 5: [('empty first version header', ([['MIME-Version', ''], ['MIME-Version', '1.0'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('trailing comment', ([['Mime-Version', '1.0 (produced by MetaSend v5)'], ['Content-Type', 'Text/HTML; charset=utf-8']],), ['text/html', 'mime']), ('leading comment', ([['MIME-Version', '(generated) 1.0'], ['content-type', 'image/png']],), ['image/png', 'mime']), ('inner whitespace', ([['MIME-Version', '1 .\t0'], ['Content-Type', 'multipart/mixed; boundary=b5']],), ['multipart/mixed', 'mime']), ('no version header', ([['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('other version', ([['MIME-Version', '1.5'], ['Content-Type', 'text/html']],), ['text/plain', 'non-mime']), ('empty content type', ([[' MIME-Version ', '1.0'], ['Content-Type', ' ; charset=x']],), ['text/plain', 'mime'])]}
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 fixtureActualExpectedOutcome
empty first version header['text/plain', 'non-mime']['text/plain', 'non-mime']Passed
trailing comment['text/html', 'mime']['text/html', 'mime']Passed
leading comment['image/png', 'mime']['image/png', 'mime']Passed
inner whitespace['multipart/mixed', 'mime']['multipart/mixed', 'mime']Passed
no version header['text/plain', 'non-mime']['text/plain', 'non-mime']Passed
other version['text/plain', 'non-mime']['text/plain', 'non-mime']Passed
empty content type['text/plain', 'mime']['text/plain', 'mime']Passed

SHA-256 / a458d0d134b40c060e4dafc97f84c33c96b6b1d3d435bc3ce8165abf19cee949

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:19.864482+00:00.

Case digest / 70b128ff5df7d1b681c8a32d0f4dd14a10fbe470224414db01be070695d310d7