FAILURE MAP
← Case archive

FA-76591 / Email MIME structure / Open access

Assemble the structure of a forwarded message: inline images need html · case 01

Inline images of the original become attachments of a plain-text forward.

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

ROOT CAUSE

The inline images need html decision evaluates `else: body = 'text' atts += original['inline']` where the contract requires `else: body = 'text'`.

VERIFIED REPAIR

Use `else: body = 'text'` for the inline images need html decision and keep every other rule of the model unchanged.

Unsuccessful approach: Keeping only the first image still attaches an image the forward cannot display. The attempted `else: body = 'text' atts += original['inline'][:1]` still disagrees with a fixture.

Case contract

original {subject, body_type ("text" or "alternative"), attachments [names], inline [image names]}. Subjects get a "Fwd: " prefix unless they already start with "fwd:" (case-insensitive). mode "attach" produces mixed(text,message/rfc822): the original travels whole, attachments included. mode "inline" copies the body: alternative(text,html), with related(html, images...) when the original has inline images (kept only when html exists), or text; original attachments follow in their original order inside mixed(...).

Why this case matters

Forwarding rebuilds a MIME tree; errors duplicate attachments, lose inline images or stack Fwd: prefixes.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(original, mode):
    s = original['subject']
    subject = s if s[:4].lower() == 'fwd:' else 'Fwd: ' + s
    if mode == 'attach':
        return {'subject': subject, 'structure': 'mixed(text,message/rfc822)'}
    atts = list(original['attachments'])
    if original['body_type'] == 'alternative':
        body = 'alternative(text,html)'
        if original['inline']:
            body = 'alternative(text,related(html,' + ','.join(original['inline']) + '))'
    else:
        body = 'text'
        atts += original['inline']
    if atts:
        body = 'mixed(' + ','.join([body] + atts) + ')'
    return {'subject': subject, 'structure': body}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('upper-case existing prefix', ({'subject': 'FWD: plan 1', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'FWD: plan 1'}), ('subject starting with Fwd as a word', ({'subject': 'Fwd planning review', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'Fwd: Fwd planning review'}), ('attach mode keeps parts inside', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['a1.pdf'], 'inline': ['logo.png']}, 'attach'), {'structure': 'mixed(text,message/rfc822)', 'subject': 'Fwd: s'}), ('text body with inline images', ({'subject': 's', 'body_type': 'text', 'attachments': ['a.pdf'], 'inline': ['i1.png', 'j.png']}, 'inline'), {'structure': 'mixed(text,a.pdf)', 'subject': 'Fwd: s'}), ('attachment order', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['b.pdf', 'a.doc', 'c1.txt'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),b.pdf,a.doc,c1.txt)', 'subject': 'Fwd: s'}), ('html without inline images', ({'subject': 'Re: x', 'body_type': 'alternative', 'attachments': ['x.pdf'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),x.pdf)', 'subject': 'Fwd: Re: x'}), ('html with inline image', ({'subject': 'fwd: y', 'body_type': 'alternative', 'attachments': [], 'inline': ['p1.gif']}, 'inline'), {'structure': 'alternative(text,related(html,p1.gif))', 'subject': 'fwd: y'})], 2: [('upper-case existing prefix', ({'subject': 'FWD: plan 2', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'FWD: plan 2'}), ('subject starting with Fwd as a word', ({'subject': 'Fwd planning review', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'Fwd: Fwd planning review'}), ('attach mode keeps parts inside', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['a2.pdf'], 'inline': ['logo.png']}, 'attach'), {'structure': 'mixed(text,message/rfc822)', 'subject': 'Fwd: s'}), ('text body with inline images', ({'subject': 's', 'body_type': 'text', 'attachments': ['a.pdf'], 'inline': ['i2.png', 'j.png']}, 'inline'), {'structure': 'mixed(text,a.pdf)', 'subject': 'Fwd: s'}), ('attachment order', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['b.pdf', 'a.doc', 'c2.txt'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),b.pdf,a.doc,c2.txt)', 'subject': 'Fwd: s'}), ('html without inline images', ({'subject': 'Re: x', 'body_type': 'alternative', 'attachments': ['x.pdf'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),x.pdf)', 'subject': 'Fwd: Re: x'}), ('html with inline image', ({'subject': 'fwd: y', 'body_type': 'alternative', 'attachments': [], 'inline': ['p2.gif']}, 'inline'), {'structure': 'alternative(text,related(html,p2.gif))', 'subject': 'fwd: y'})], 3: [('upper-case existing prefix', ({'subject': 'FWD: plan 3', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'FWD: plan 3'}), ('subject starting with Fwd as a word', ({'subject': 'Fwd planning review', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'Fwd: Fwd planning review'}), ('attach mode keeps parts inside', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['a3.pdf'], 'inline': ['logo.png']}, 'attach'), {'structure': 'mixed(text,message/rfc822)', 'subject': 'Fwd: s'}), ('text body with inline images', ({'subject': 's', 'body_type': 'text', 'attachments': ['a.pdf'], 'inline': ['i3.png', 'j.png']}, 'inline'), {'structure': 'mixed(text,a.pdf)', 'subject': 'Fwd: s'}), ('attachment order', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['b.pdf', 'a.doc', 'c3.txt'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),b.pdf,a.doc,c3.txt)', 'subject': 'Fwd: s'}), ('html without inline images', ({'subject': 'Re: x', 'body_type': 'alternative', 'attachments': ['x.pdf'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),x.pdf)', 'subject': 'Fwd: Re: x'}), ('html with inline image', ({'subject': 'fwd: y', 'body_type': 'alternative', 'attachments': [], 'inline': ['p3.gif']}, 'inline'), {'structure': 'alternative(text,related(html,p3.gif))', 'subject': 'fwd: y'})], 4: [('upper-case existing prefix', ({'subject': 'FWD: plan 4', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'FWD: plan 4'}), ('subject starting with Fwd as a word', ({'subject': 'Fwd planning review', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'Fwd: Fwd planning review'}), ('attach mode keeps parts inside', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['a4.pdf'], 'inline': ['logo.png']}, 'attach'), {'structure': 'mixed(text,message/rfc822)', 'subject': 'Fwd: s'}), ('text body with inline images', ({'subject': 's', 'body_type': 'text', 'attachments': ['a.pdf'], 'inline': ['i4.png', 'j.png']}, 'inline'), {'structure': 'mixed(text,a.pdf)', 'subject': 'Fwd: s'}), ('attachment order', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['b.pdf', 'a.doc', 'c4.txt'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),b.pdf,a.doc,c4.txt)', 'subject': 'Fwd: s'}), ('html without inline images', ({'subject': 'Re: x', 'body_type': 'alternative', 'attachments': ['x.pdf'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),x.pdf)', 'subject': 'Fwd: Re: x'}), ('html with inline image', ({'subject': 'fwd: y', 'body_type': 'alternative', 'attachments': [], 'inline': ['p4.gif']}, 'inline'), {'structure': 'alternative(text,related(html,p4.gif))', 'subject': 'fwd: y'})], 5: [('upper-case existing prefix', ({'subject': 'FWD: plan 5', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'FWD: plan 5'}), ('subject starting with Fwd as a word', ({'subject': 'Fwd planning review', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'Fwd: Fwd planning review'}), ('attach mode keeps parts inside', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['a5.pdf'], 'inline': ['logo.png']}, 'attach'), {'structure': 'mixed(text,message/rfc822)', 'subject': 'Fwd: s'}), ('text body with inline images', ({'subject': 's', 'body_type': 'text', 'attachments': ['a.pdf'], 'inline': ['i5.png', 'j.png']}, 'inline'), {'structure': 'mixed(text,a.pdf)', 'subject': 'Fwd: s'}), ('attachment order', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['b.pdf', 'a.doc', 'c5.txt'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),b.pdf,a.doc,c5.txt)', 'subject': 'Fwd: s'}), ('html without inline images', ({'subject': 'Re: x', 'body_type': 'alternative', 'attachments': ['x.pdf'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),x.pdf)', 'subject': 'Fwd: Re: x'}), ('html with inline image', ({'subject': 'fwd: y', 'body_type': 'alternative', 'attachments': [], 'inline': ['p5.gif']}, 'inline'), {'structure': 'alternative(text,related(html,p5.gif))', 'subject': 'fwd: y'})]}
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
upper-case existing prefix{'structure': 'text', 'subject': 'FWD: plan 1'}{'structure': 'text', 'subject': 'FWD: plan 1'}Passed
subject starting with Fwd as a word{'structure': 'text', 'subject': 'Fwd: Fwd planning review'}{'structure': 'text', 'subject': 'Fwd: Fwd planning review'}Passed
attach mode keeps parts inside{'structure': 'mixed(text,message/rfc822)', 'subject': 'Fwd: s'}{'structure': 'mixed(text,message/rfc822)', 'subject': 'Fwd: s'}Passed
text body with inline images{'structure': 'mixed(text,a.pdf,i1.png,j.png)', 'subject': 'Fwd: s'}{'structure': 'mixed(text,a.pdf)', 'subject': 'Fwd: s'}Failed
attachment order{'structure': 'mixed(alternative(text,html),b.pdf,a.doc,c1.txt)', 'subject': 'Fwd: s'}{'structure': 'mixed(alternative(text,html),b.pdf,a.doc,c1.txt)', 'subject': 'Fwd: s'}Passed
html without inline images{'structure': 'mixed(alternative(text,html),x.pdf)', 'subject': 'Fwd: Re: x'}{'structure': 'mixed(alternative(text,html),x.pdf)', 'subject': 'Fwd: Re: x'}Passed
html with inline image{'structure': 'alternative(text,related(html,p1.gif))', 'subject': 'fwd: y'}{'structure': 'alternative(text,related(html,p1.gif))', 'subject': 'fwd: y'}Passed

SHA-256 / 9fcc23e0a1cc326c30276b4eafa5e8954851452a5e6f1558345b9d9d7cfc37fe

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(original, mode):
    s = original['subject']
    subject = s if s[:4].lower() == 'fwd:' else 'Fwd: ' + s
    if mode == 'attach':
        return {'subject': subject, 'structure': 'mixed(text,message/rfc822)'}
    atts = list(original['attachments'])
    if original['body_type'] == 'alternative':
        body = 'alternative(text,html)'
        if original['inline']:
            body = 'alternative(text,related(html,' + ','.join(original['inline']) + '))'
    else:
        body = 'text'
        atts += original['inline'][:1]
    if atts:
        body = 'mixed(' + ','.join([body] + atts) + ')'
    return {'subject': subject, 'structure': body}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('upper-case existing prefix', ({'subject': 'FWD: plan 1', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'FWD: plan 1'}), ('subject starting with Fwd as a word', ({'subject': 'Fwd planning review', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'Fwd: Fwd planning review'}), ('attach mode keeps parts inside', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['a1.pdf'], 'inline': ['logo.png']}, 'attach'), {'structure': 'mixed(text,message/rfc822)', 'subject': 'Fwd: s'}), ('text body with inline images', ({'subject': 's', 'body_type': 'text', 'attachments': ['a.pdf'], 'inline': ['i1.png', 'j.png']}, 'inline'), {'structure': 'mixed(text,a.pdf)', 'subject': 'Fwd: s'}), ('attachment order', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['b.pdf', 'a.doc', 'c1.txt'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),b.pdf,a.doc,c1.txt)', 'subject': 'Fwd: s'}), ('html without inline images', ({'subject': 'Re: x', 'body_type': 'alternative', 'attachments': ['x.pdf'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),x.pdf)', 'subject': 'Fwd: Re: x'}), ('html with inline image', ({'subject': 'fwd: y', 'body_type': 'alternative', 'attachments': [], 'inline': ['p1.gif']}, 'inline'), {'structure': 'alternative(text,related(html,p1.gif))', 'subject': 'fwd: y'})], 2: [('upper-case existing prefix', ({'subject': 'FWD: plan 2', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'FWD: plan 2'}), ('subject starting with Fwd as a word', ({'subject': 'Fwd planning review', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'Fwd: Fwd planning review'}), ('attach mode keeps parts inside', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['a2.pdf'], 'inline': ['logo.png']}, 'attach'), {'structure': 'mixed(text,message/rfc822)', 'subject': 'Fwd: s'}), ('text body with inline images', ({'subject': 's', 'body_type': 'text', 'attachments': ['a.pdf'], 'inline': ['i2.png', 'j.png']}, 'inline'), {'structure': 'mixed(text,a.pdf)', 'subject': 'Fwd: s'}), ('attachment order', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['b.pdf', 'a.doc', 'c2.txt'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),b.pdf,a.doc,c2.txt)', 'subject': 'Fwd: s'}), ('html without inline images', ({'subject': 'Re: x', 'body_type': 'alternative', 'attachments': ['x.pdf'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),x.pdf)', 'subject': 'Fwd: Re: x'}), ('html with inline image', ({'subject': 'fwd: y', 'body_type': 'alternative', 'attachments': [], 'inline': ['p2.gif']}, 'inline'), {'structure': 'alternative(text,related(html,p2.gif))', 'subject': 'fwd: y'})], 3: [('upper-case existing prefix', ({'subject': 'FWD: plan 3', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'FWD: plan 3'}), ('subject starting with Fwd as a word', ({'subject': 'Fwd planning review', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'Fwd: Fwd planning review'}), ('attach mode keeps parts inside', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['a3.pdf'], 'inline': ['logo.png']}, 'attach'), {'structure': 'mixed(text,message/rfc822)', 'subject': 'Fwd: s'}), ('text body with inline images', ({'subject': 's', 'body_type': 'text', 'attachments': ['a.pdf'], 'inline': ['i3.png', 'j.png']}, 'inline'), {'structure': 'mixed(text,a.pdf)', 'subject': 'Fwd: s'}), ('attachment order', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['b.pdf', 'a.doc', 'c3.txt'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),b.pdf,a.doc,c3.txt)', 'subject': 'Fwd: s'}), ('html without inline images', ({'subject': 'Re: x', 'body_type': 'alternative', 'attachments': ['x.pdf'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),x.pdf)', 'subject': 'Fwd: Re: x'}), ('html with inline image', ({'subject': 'fwd: y', 'body_type': 'alternative', 'attachments': [], 'inline': ['p3.gif']}, 'inline'), {'structure': 'alternative(text,related(html,p3.gif))', 'subject': 'fwd: y'})], 4: [('upper-case existing prefix', ({'subject': 'FWD: plan 4', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'FWD: plan 4'}), ('subject starting with Fwd as a word', ({'subject': 'Fwd planning review', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'Fwd: Fwd planning review'}), ('attach mode keeps parts inside', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['a4.pdf'], 'inline': ['logo.png']}, 'attach'), {'structure': 'mixed(text,message/rfc822)', 'subject': 'Fwd: s'}), ('text body with inline images', ({'subject': 's', 'body_type': 'text', 'attachments': ['a.pdf'], 'inline': ['i4.png', 'j.png']}, 'inline'), {'structure': 'mixed(text,a.pdf)', 'subject': 'Fwd: s'}), ('attachment order', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['b.pdf', 'a.doc', 'c4.txt'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),b.pdf,a.doc,c4.txt)', 'subject': 'Fwd: s'}), ('html without inline images', ({'subject': 'Re: x', 'body_type': 'alternative', 'attachments': ['x.pdf'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),x.pdf)', 'subject': 'Fwd: Re: x'}), ('html with inline image', ({'subject': 'fwd: y', 'body_type': 'alternative', 'attachments': [], 'inline': ['p4.gif']}, 'inline'), {'structure': 'alternative(text,related(html,p4.gif))', 'subject': 'fwd: y'})], 5: [('upper-case existing prefix', ({'subject': 'FWD: plan 5', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'FWD: plan 5'}), ('subject starting with Fwd as a word', ({'subject': 'Fwd planning review', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'Fwd: Fwd planning review'}), ('attach mode keeps parts inside', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['a5.pdf'], 'inline': ['logo.png']}, 'attach'), {'structure': 'mixed(text,message/rfc822)', 'subject': 'Fwd: s'}), ('text body with inline images', ({'subject': 's', 'body_type': 'text', 'attachments': ['a.pdf'], 'inline': ['i5.png', 'j.png']}, 'inline'), {'structure': 'mixed(text,a.pdf)', 'subject': 'Fwd: s'}), ('attachment order', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['b.pdf', 'a.doc', 'c5.txt'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),b.pdf,a.doc,c5.txt)', 'subject': 'Fwd: s'}), ('html without inline images', ({'subject': 'Re: x', 'body_type': 'alternative', 'attachments': ['x.pdf'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),x.pdf)', 'subject': 'Fwd: Re: x'}), ('html with inline image', ({'subject': 'fwd: y', 'body_type': 'alternative', 'attachments': [], 'inline': ['p5.gif']}, 'inline'), {'structure': 'alternative(text,related(html,p5.gif))', 'subject': 'fwd: y'})]}
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
upper-case existing prefix{'structure': 'text', 'subject': 'FWD: plan 1'}{'structure': 'text', 'subject': 'FWD: plan 1'}Passed
subject starting with Fwd as a word{'structure': 'text', 'subject': 'Fwd: Fwd planning review'}{'structure': 'text', 'subject': 'Fwd: Fwd planning review'}Passed
attach mode keeps parts inside{'structure': 'mixed(text,message/rfc822)', 'subject': 'Fwd: s'}{'structure': 'mixed(text,message/rfc822)', 'subject': 'Fwd: s'}Passed
text body with inline images{'structure': 'mixed(text,a.pdf,i1.png)', 'subject': 'Fwd: s'}{'structure': 'mixed(text,a.pdf)', 'subject': 'Fwd: s'}Failed
attachment order{'structure': 'mixed(alternative(text,html),b.pdf,a.doc,c1.txt)', 'subject': 'Fwd: s'}{'structure': 'mixed(alternative(text,html),b.pdf,a.doc,c1.txt)', 'subject': 'Fwd: s'}Passed
html without inline images{'structure': 'mixed(alternative(text,html),x.pdf)', 'subject': 'Fwd: Re: x'}{'structure': 'mixed(alternative(text,html),x.pdf)', 'subject': 'Fwd: Re: x'}Passed
html with inline image{'structure': 'alternative(text,related(html,p1.gif))', 'subject': 'fwd: y'}{'structure': 'alternative(text,related(html,p1.gif))', 'subject': 'fwd: y'}Passed

SHA-256 / 564b0a50713dd8a0f52ecf3e89c010dfeea64e084cf0ce8cec10e37d75944160

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(original, mode):
    s = original['subject']
    subject = s if s[:4].lower() == 'fwd:' else 'Fwd: ' + s
    if mode == 'attach':
        return {'subject': subject, 'structure': 'mixed(text,message/rfc822)'}
    atts = list(original['attachments'])
    if original['body_type'] == 'alternative':
        body = 'alternative(text,html)'
        if original['inline']:
            body = 'alternative(text,related(html,' + ','.join(original['inline']) + '))'
    else:
        body = 'text'
    if atts:
        body = 'mixed(' + ','.join([body] + atts) + ')'
    return {'subject': subject, 'structure': body}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('upper-case existing prefix', ({'subject': 'FWD: plan 1', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'FWD: plan 1'}), ('subject starting with Fwd as a word', ({'subject': 'Fwd planning review', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'Fwd: Fwd planning review'}), ('attach mode keeps parts inside', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['a1.pdf'], 'inline': ['logo.png']}, 'attach'), {'structure': 'mixed(text,message/rfc822)', 'subject': 'Fwd: s'}), ('text body with inline images', ({'subject': 's', 'body_type': 'text', 'attachments': ['a.pdf'], 'inline': ['i1.png', 'j.png']}, 'inline'), {'structure': 'mixed(text,a.pdf)', 'subject': 'Fwd: s'}), ('attachment order', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['b.pdf', 'a.doc', 'c1.txt'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),b.pdf,a.doc,c1.txt)', 'subject': 'Fwd: s'}), ('html without inline images', ({'subject': 'Re: x', 'body_type': 'alternative', 'attachments': ['x.pdf'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),x.pdf)', 'subject': 'Fwd: Re: x'}), ('html with inline image', ({'subject': 'fwd: y', 'body_type': 'alternative', 'attachments': [], 'inline': ['p1.gif']}, 'inline'), {'structure': 'alternative(text,related(html,p1.gif))', 'subject': 'fwd: y'})], 2: [('upper-case existing prefix', ({'subject': 'FWD: plan 2', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'FWD: plan 2'}), ('subject starting with Fwd as a word', ({'subject': 'Fwd planning review', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'Fwd: Fwd planning review'}), ('attach mode keeps parts inside', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['a2.pdf'], 'inline': ['logo.png']}, 'attach'), {'structure': 'mixed(text,message/rfc822)', 'subject': 'Fwd: s'}), ('text body with inline images', ({'subject': 's', 'body_type': 'text', 'attachments': ['a.pdf'], 'inline': ['i2.png', 'j.png']}, 'inline'), {'structure': 'mixed(text,a.pdf)', 'subject': 'Fwd: s'}), ('attachment order', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['b.pdf', 'a.doc', 'c2.txt'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),b.pdf,a.doc,c2.txt)', 'subject': 'Fwd: s'}), ('html without inline images', ({'subject': 'Re: x', 'body_type': 'alternative', 'attachments': ['x.pdf'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),x.pdf)', 'subject': 'Fwd: Re: x'}), ('html with inline image', ({'subject': 'fwd: y', 'body_type': 'alternative', 'attachments': [], 'inline': ['p2.gif']}, 'inline'), {'structure': 'alternative(text,related(html,p2.gif))', 'subject': 'fwd: y'})], 3: [('upper-case existing prefix', ({'subject': 'FWD: plan 3', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'FWD: plan 3'}), ('subject starting with Fwd as a word', ({'subject': 'Fwd planning review', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'Fwd: Fwd planning review'}), ('attach mode keeps parts inside', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['a3.pdf'], 'inline': ['logo.png']}, 'attach'), {'structure': 'mixed(text,message/rfc822)', 'subject': 'Fwd: s'}), ('text body with inline images', ({'subject': 's', 'body_type': 'text', 'attachments': ['a.pdf'], 'inline': ['i3.png', 'j.png']}, 'inline'), {'structure': 'mixed(text,a.pdf)', 'subject': 'Fwd: s'}), ('attachment order', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['b.pdf', 'a.doc', 'c3.txt'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),b.pdf,a.doc,c3.txt)', 'subject': 'Fwd: s'}), ('html without inline images', ({'subject': 'Re: x', 'body_type': 'alternative', 'attachments': ['x.pdf'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),x.pdf)', 'subject': 'Fwd: Re: x'}), ('html with inline image', ({'subject': 'fwd: y', 'body_type': 'alternative', 'attachments': [], 'inline': ['p3.gif']}, 'inline'), {'structure': 'alternative(text,related(html,p3.gif))', 'subject': 'fwd: y'})], 4: [('upper-case existing prefix', ({'subject': 'FWD: plan 4', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'FWD: plan 4'}), ('subject starting with Fwd as a word', ({'subject': 'Fwd planning review', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'Fwd: Fwd planning review'}), ('attach mode keeps parts inside', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['a4.pdf'], 'inline': ['logo.png']}, 'attach'), {'structure': 'mixed(text,message/rfc822)', 'subject': 'Fwd: s'}), ('text body with inline images', ({'subject': 's', 'body_type': 'text', 'attachments': ['a.pdf'], 'inline': ['i4.png', 'j.png']}, 'inline'), {'structure': 'mixed(text,a.pdf)', 'subject': 'Fwd: s'}), ('attachment order', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['b.pdf', 'a.doc', 'c4.txt'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),b.pdf,a.doc,c4.txt)', 'subject': 'Fwd: s'}), ('html without inline images', ({'subject': 'Re: x', 'body_type': 'alternative', 'attachments': ['x.pdf'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),x.pdf)', 'subject': 'Fwd: Re: x'}), ('html with inline image', ({'subject': 'fwd: y', 'body_type': 'alternative', 'attachments': [], 'inline': ['p4.gif']}, 'inline'), {'structure': 'alternative(text,related(html,p4.gif))', 'subject': 'fwd: y'})], 5: [('upper-case existing prefix', ({'subject': 'FWD: plan 5', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'FWD: plan 5'}), ('subject starting with Fwd as a word', ({'subject': 'Fwd planning review', 'body_type': 'text', 'attachments': [], 'inline': []}, 'inline'), {'structure': 'text', 'subject': 'Fwd: Fwd planning review'}), ('attach mode keeps parts inside', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['a5.pdf'], 'inline': ['logo.png']}, 'attach'), {'structure': 'mixed(text,message/rfc822)', 'subject': 'Fwd: s'}), ('text body with inline images', ({'subject': 's', 'body_type': 'text', 'attachments': ['a.pdf'], 'inline': ['i5.png', 'j.png']}, 'inline'), {'structure': 'mixed(text,a.pdf)', 'subject': 'Fwd: s'}), ('attachment order', ({'subject': 's', 'body_type': 'alternative', 'attachments': ['b.pdf', 'a.doc', 'c5.txt'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),b.pdf,a.doc,c5.txt)', 'subject': 'Fwd: s'}), ('html without inline images', ({'subject': 'Re: x', 'body_type': 'alternative', 'attachments': ['x.pdf'], 'inline': []}, 'inline'), {'structure': 'mixed(alternative(text,html),x.pdf)', 'subject': 'Fwd: Re: x'}), ('html with inline image', ({'subject': 'fwd: y', 'body_type': 'alternative', 'attachments': [], 'inline': ['p5.gif']}, 'inline'), {'structure': 'alternative(text,related(html,p5.gif))', 'subject': 'fwd: y'})]}
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
upper-case existing prefix{'structure': 'text', 'subject': 'FWD: plan 1'}{'structure': 'text', 'subject': 'FWD: plan 1'}Passed
subject starting with Fwd as a word{'structure': 'text', 'subject': 'Fwd: Fwd planning review'}{'structure': 'text', 'subject': 'Fwd: Fwd planning review'}Passed
attach mode keeps parts inside{'structure': 'mixed(text,message/rfc822)', 'subject': 'Fwd: s'}{'structure': 'mixed(text,message/rfc822)', 'subject': 'Fwd: s'}Passed
text body with inline images{'structure': 'mixed(text,a.pdf)', 'subject': 'Fwd: s'}{'structure': 'mixed(text,a.pdf)', 'subject': 'Fwd: s'}Passed
attachment order{'structure': 'mixed(alternative(text,html),b.pdf,a.doc,c1.txt)', 'subject': 'Fwd: s'}{'structure': 'mixed(alternative(text,html),b.pdf,a.doc,c1.txt)', 'subject': 'Fwd: s'}Passed
html without inline images{'structure': 'mixed(alternative(text,html),x.pdf)', 'subject': 'Fwd: Re: x'}{'structure': 'mixed(alternative(text,html),x.pdf)', 'subject': 'Fwd: Re: x'}Passed
html with inline image{'structure': 'alternative(text,related(html,p1.gif))', 'subject': 'fwd: y'}{'structure': 'alternative(text,related(html,p1.gif))', 'subject': 'fwd: y'}Passed

SHA-256 / 91da49c453a36293da53758fba9fef12444e4106d3499940762a79aae1e92348

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

Case digest / 8337c5d933554113d4a67597cb50f8330fc294a75a1bee282acec3bb14062572