broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(has_text, has_html, inline_images, attachments):
    atts = attachments
    html = None
    if has_html:
        html = 'html' if inline_images == 0 else 'related(' + ','.join(['html'] + ['img'] * inline_images) + ')'
    else:
        atts += inline_images
    if has_text and html:
        body = 'alternative(text,' + html + ')'
    elif html:
        body = html
    else:
        body = 'text'
    if atts or inline_images:
        return 'mixed(' + ','.join([body] + ['att'] * atts) + ')'
    return body
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('images without html', (False, False, 2, 0), 'mixed(text,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 2, 0), 'alternative(text,related(html,img,img))'), ('html images and attachment', (False, True, 1, 1), 'mixed(related(html,img),att)'), ('text and attachments', (True, False, 0, 1), 'mixed(text,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 1), 'mixed(alternative(text,related(html,img,img)),att)')], 2: [('images without html', (False, False, 3, 0), 'mixed(text,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 3, 0), 'alternative(text,related(html,img,img,img))'), ('html images and attachment', (False, True, 2, 1), 'mixed(related(html,img,img),att)'), ('text and attachments', (True, False, 0, 2), 'mixed(text,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 2), 'mixed(alternative(text,related(html,img,img)),att,att)')], 3: [('images without html', (False, False, 4, 0), 'mixed(text,att,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 4, 0), 'alternative(text,related(html,img,img,img,img))'), ('html images and attachment', (False, True, 3, 1), 'mixed(related(html,img,img,img),att)'), ('text and attachments', (True, False, 0, 3), 'mixed(text,att,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 3), 'mixed(alternative(text,related(html,img,img)),att,att,att)')], 4: [('images without html', (False, False, 5, 0), 'mixed(text,att,att,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 5, 0), 'alternative(text,related(html,img,img,img,img,img))'), ('html images and attachment', (False, True, 4, 1), 'mixed(related(html,img,img,img,img),att)'), ('text and attachments', (True, False, 0, 4), 'mixed(text,att,att,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 4), 'mixed(alternative(text,related(html,img,img)),att,att,att,att)')], 5: [('images without html', (False, False, 6, 0), 'mixed(text,att,att,att,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 6, 0), 'alternative(text,related(html,img,img,img,img,img,img))'), ('html images and attachment', (False, True, 5, 1), 'mixed(related(html,img,img,img,img,img),att)'), ('text and attachments', (True, False, 0, 5), 'mixed(text,att,att,att,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 5), 'mixed(alternative(text,related(html,img,img)),att,att,att,att,att)')]}
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(has_text, has_html, inline_images, attachments):
    atts = attachments
    html = None
    if has_html:
        html = 'html' if inline_images == 0 else 'related(' + ','.join(['html'] + ['img'] * inline_images) + ')'
    else:
        atts += inline_images
    if has_text and html:
        body = 'alternative(text,' + html + ')'
    elif html:
        body = html
    else:
        body = 'text'
    if atts or inline_images > 1:
        return 'mixed(' + ','.join([body] + ['att'] * atts) + ')'
    return body
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('images without html', (False, False, 2, 0), 'mixed(text,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 2, 0), 'alternative(text,related(html,img,img))'), ('html images and attachment', (False, True, 1, 1), 'mixed(related(html,img),att)'), ('text and attachments', (True, False, 0, 1), 'mixed(text,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 1), 'mixed(alternative(text,related(html,img,img)),att)')], 2: [('images without html', (False, False, 3, 0), 'mixed(text,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 3, 0), 'alternative(text,related(html,img,img,img))'), ('html images and attachment', (False, True, 2, 1), 'mixed(related(html,img,img),att)'), ('text and attachments', (True, False, 0, 2), 'mixed(text,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 2), 'mixed(alternative(text,related(html,img,img)),att,att)')], 3: [('images without html', (False, False, 4, 0), 'mixed(text,att,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 4, 0), 'alternative(text,related(html,img,img,img,img))'), ('html images and attachment', (False, True, 3, 1), 'mixed(related(html,img,img,img),att)'), ('text and attachments', (True, False, 0, 3), 'mixed(text,att,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 3), 'mixed(alternative(text,related(html,img,img)),att,att,att)')], 4: [('images without html', (False, False, 5, 0), 'mixed(text,att,att,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 5, 0), 'alternative(text,related(html,img,img,img,img,img))'), ('html images and attachment', (False, True, 4, 1), 'mixed(related(html,img,img,img,img),att)'), ('text and attachments', (True, False, 0, 4), 'mixed(text,att,att,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 4), 'mixed(alternative(text,related(html,img,img)),att,att,att,att)')], 5: [('images without html', (False, False, 6, 0), 'mixed(text,att,att,att,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 6, 0), 'alternative(text,related(html,img,img,img,img,img,img))'), ('html images and attachment', (False, True, 5, 1), 'mixed(related(html,img,img,img,img,img),att)'), ('text and attachments', (True, False, 0, 5), 'mixed(text,att,att,att,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 5), 'mixed(alternative(text,related(html,img,img)),att,att,att,att,att)')]}
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)

prompt:
Messages with inline images but no attachments get an unnecessary multipart/mixed wrapper.

The body is multipart/alternative(text, html) when both versions exist, the html alone when only html exists, else text. Inline images go into multipart/related with the html root first; without html they become attachments. When there are attachments the result is multipart/mixed(body, attachments...). Output is a compact string such as "mixed(alternative(text,related(html,img)),att)".

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(has_text, has_html, inline_images, attachments):
    atts = attachments
    html = None
    if has_html:
        html = 'html' if inline_images == 0 else 'related(' + ','.join(['img'] * inline_images + ['html']) + ')'
    else:
        atts += inline_images
    if has_text and html:
        body = 'alternative(text,' + html + ')'
    elif html:
        body = html
    else:
        body = 'text'
    if atts:
        return 'mixed(' + ','.join([body] + ['att'] * atts) + ')'
    return body
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('images without html', (False, False, 2, 0), 'mixed(text,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 2, 0), 'alternative(text,related(html,img,img))'), ('html images and attachment', (False, True, 1, 1), 'mixed(related(html,img),att)'), ('text and attachments', (True, False, 0, 1), 'mixed(text,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 1), 'mixed(alternative(text,related(html,img,img)),att)')], 2: [('images without html', (False, False, 3, 0), 'mixed(text,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 3, 0), 'alternative(text,related(html,img,img,img))'), ('html images and attachment', (False, True, 2, 1), 'mixed(related(html,img,img),att)'), ('text and attachments', (True, False, 0, 2), 'mixed(text,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 2), 'mixed(alternative(text,related(html,img,img)),att,att)')], 3: [('images without html', (False, False, 4, 0), 'mixed(text,att,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 4, 0), 'alternative(text,related(html,img,img,img,img))'), ('html images and attachment', (False, True, 3, 1), 'mixed(related(html,img,img,img),att)'), ('text and attachments', (True, False, 0, 3), 'mixed(text,att,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 3), 'mixed(alternative(text,related(html,img,img)),att,att,att)')], 4: [('images without html', (False, False, 5, 0), 'mixed(text,att,att,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 5, 0), 'alternative(text,related(html,img,img,img,img,img))'), ('html images and attachment', (False, True, 4, 1), 'mixed(related(html,img,img,img,img),att)'), ('text and attachments', (True, False, 0, 4), 'mixed(text,att,att,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 4), 'mixed(alternative(text,related(html,img,img)),att,att,att,att)')], 5: [('images without html', (False, False, 6, 0), 'mixed(text,att,att,att,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 6, 0), 'alternative(text,related(html,img,img,img,img,img,img))'), ('html images and attachment', (False, True, 5, 1), 'mixed(related(html,img,img,img,img,img),att)'), ('text and attachments', (True, False, 0, 5), 'mixed(text,att,att,att,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 5), 'mixed(alternative(text,related(html,img,img)),att,att,att,att,att)')]}
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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(has_text, has_html, inline_images, attachments):
    atts = attachments
    html = None
    if has_html:
        html = 'html' if inline_images == 0 else 'related(' + ','.join(['img'] + ['html'] + ['img'] * (inline_images - 1)) + ')'
    else:
        atts += inline_images
    if has_text and html:
        body = 'alternative(text,' + html + ')'
    elif html:
        body = html
    else:
        body = 'text'
    if atts:
        return 'mixed(' + ','.join([body] + ['att'] * atts) + ')'
    return body
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('images without html', (False, False, 2, 0), 'mixed(text,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 2, 0), 'alternative(text,related(html,img,img))'), ('html images and attachment', (False, True, 1, 1), 'mixed(related(html,img),att)'), ('text and attachments', (True, False, 0, 1), 'mixed(text,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 1), 'mixed(alternative(text,related(html,img,img)),att)')], 2: [('images without html', (False, False, 3, 0), 'mixed(text,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 3, 0), 'alternative(text,related(html,img,img,img))'), ('html images and attachment', (False, True, 2, 1), 'mixed(related(html,img,img),att)'), ('text and attachments', (True, False, 0, 2), 'mixed(text,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 2), 'mixed(alternative(text,related(html,img,img)),att,att)')], 3: [('images without html', (False, False, 4, 0), 'mixed(text,att,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 4, 0), 'alternative(text,related(html,img,img,img,img))'), ('html images and attachment', (False, True, 3, 1), 'mixed(related(html,img,img,img),att)'), ('text and attachments', (True, False, 0, 3), 'mixed(text,att,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 3), 'mixed(alternative(text,related(html,img,img)),att,att,att)')], 4: [('images without html', (False, False, 5, 0), 'mixed(text,att,att,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 5, 0), 'alternative(text,related(html,img,img,img,img,img))'), ('html images and attachment', (False, True, 4, 1), 'mixed(related(html,img,img,img,img),att)'), ('text and attachments', (True, False, 0, 4), 'mixed(text,att,att,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 4), 'mixed(alternative(text,related(html,img,img)),att,att,att,att)')], 5: [('images without html', (False, False, 6, 0), 'mixed(text,att,att,att,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 6, 0), 'alternative(text,related(html,img,img,img,img,img,img))'), ('html images and attachment', (False, True, 5, 1), 'mixed(related(html,img,img,img,img,img),att)'), ('text and attachments', (True, False, 0, 5), 'mixed(text,att,att,att,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 5), 'mixed(alternative(text,related(html,img,img)),att,att,att,att,att)')]}
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)

prompt:
The HTML root is placed after the images inside multipart/related.

The body is multipart/alternative(text, html) when both versions exist, the html alone when only html exists, else text. Inline images go into multipart/related with the html root first; without html they become attachments. When there are attachments the result is multipart/mixed(body, attachments...). Output is a compact string such as "mixed(alternative(text,related(html,img)),att)".

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(has_text, has_html, inline_images, attachments):
    atts = attachments
    html = None
    if has_html:
        html = 'html' if inline_images == 0 else 'related(' + ','.join(['html'] + ['img'] * inline_images) + ')'
    else:
        atts += inline_images
    if has_text and html:
        body = 'alternative(text,' + html + ')'
    elif html:
        body = html
    else:
        body = 'text'
    if atts:
        return 'mixed(' + ','.join(['att'] * atts + [body]) + ')'
    return body
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('images without html', (False, False, 2, 0), 'mixed(text,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 2, 0), 'alternative(text,related(html,img,img))'), ('html images and attachment', (False, True, 1, 1), 'mixed(related(html,img),att)'), ('text and attachments', (True, False, 0, 1), 'mixed(text,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 1), 'mixed(alternative(text,related(html,img,img)),att)')], 2: [('images without html', (False, False, 3, 0), 'mixed(text,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 3, 0), 'alternative(text,related(html,img,img,img))'), ('html images and attachment', (False, True, 2, 1), 'mixed(related(html,img,img),att)'), ('text and attachments', (True, False, 0, 2), 'mixed(text,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 2), 'mixed(alternative(text,related(html,img,img)),att,att)')], 3: [('images without html', (False, False, 4, 0), 'mixed(text,att,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 4, 0), 'alternative(text,related(html,img,img,img,img))'), ('html images and attachment', (False, True, 3, 1), 'mixed(related(html,img,img,img),att)'), ('text and attachments', (True, False, 0, 3), 'mixed(text,att,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 3), 'mixed(alternative(text,related(html,img,img)),att,att,att)')], 4: [('images without html', (False, False, 5, 0), 'mixed(text,att,att,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 5, 0), 'alternative(text,related(html,img,img,img,img,img))'), ('html images and attachment', (False, True, 4, 1), 'mixed(related(html,img,img,img,img),att)'), ('text and attachments', (True, False, 0, 4), 'mixed(text,att,att,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 4), 'mixed(alternative(text,related(html,img,img)),att,att,att,att)')], 5: [('images without html', (False, False, 6, 0), 'mixed(text,att,att,att,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 6, 0), 'alternative(text,related(html,img,img,img,img,img,img))'), ('html images and attachment', (False, True, 5, 1), 'mixed(related(html,img,img,img,img,img),att)'), ('text and attachments', (True, False, 0, 5), 'mixed(text,att,att,att,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 5), 'mixed(alternative(text,related(html,img,img)),att,att,att,att,att)')]}
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(has_text, has_html, inline_images, attachments):
    atts = attachments
    html = None
    if has_html:
        html = 'html' if inline_images == 0 else 'related(' + ','.join(['html'] + ['img'] * inline_images) + ')'
    else:
        atts += inline_images
    if has_text and html:
        body = 'alternative(text,' + html + ')'
    elif html:
        body = html
    else:
        body = 'text'
    if atts:
        return 'mixed(' + ','.join(['att'] + [body] + ['att'] * (atts - 1)) + ')'
    return body
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('images without html', (False, False, 2, 0), 'mixed(text,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 2, 0), 'alternative(text,related(html,img,img))'), ('html images and attachment', (False, True, 1, 1), 'mixed(related(html,img),att)'), ('text and attachments', (True, False, 0, 1), 'mixed(text,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 1), 'mixed(alternative(text,related(html,img,img)),att)')], 2: [('images without html', (False, False, 3, 0), 'mixed(text,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 3, 0), 'alternative(text,related(html,img,img,img))'), ('html images and attachment', (False, True, 2, 1), 'mixed(related(html,img,img),att)'), ('text and attachments', (True, False, 0, 2), 'mixed(text,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 2), 'mixed(alternative(text,related(html,img,img)),att,att)')], 3: [('images without html', (False, False, 4, 0), 'mixed(text,att,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 4, 0), 'alternative(text,related(html,img,img,img,img))'), ('html images and attachment', (False, True, 3, 1), 'mixed(related(html,img,img,img),att)'), ('text and attachments', (True, False, 0, 3), 'mixed(text,att,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 3), 'mixed(alternative(text,related(html,img,img)),att,att,att)')], 4: [('images without html', (False, False, 5, 0), 'mixed(text,att,att,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 5, 0), 'alternative(text,related(html,img,img,img,img,img))'), ('html images and attachment', (False, True, 4, 1), 'mixed(related(html,img,img,img,img),att)'), ('text and attachments', (True, False, 0, 4), 'mixed(text,att,att,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 4), 'mixed(alternative(text,related(html,img,img)),att,att,att,att)')], 5: [('images without html', (False, False, 6, 0), 'mixed(text,att,att,att,att,att,att)'), ('text and html', (True, True, 0, 0), 'alternative(text,html)'), ('text html and images', (True, True, 6, 0), 'alternative(text,related(html,img,img,img,img,img,img))'), ('html images and attachment', (False, True, 5, 1), 'mixed(related(html,img,img,img,img,img),att)'), ('text and attachments', (True, False, 0, 5), 'mixed(text,att,att,att,att,att)'), ('plain text only', (True, False, 0, 0), 'text'), ('everything', (True, True, 2, 5), 'mixed(alternative(text,related(html,img,img)),att,att,att,att,att)')]}
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)

prompt:
Attachments precede the body in multipart/mixed, so clients show an attachment as the message.

The body is multipart/alternative(text, html) when both versions exist, the html alone when only html exists, else text. Inline images go into multipart/related with the html root first; without html they become attachments. When there are attachments the result is multipart/mixed(body, attachments...). Output is a compact string such as "mixed(alternative(text,related(html,img)),att)".

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(original, mode):
    s = original['subject']
    subject = s if s.startswith('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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(original, mode):
    s = original['subject']
    subject = s if s.lower().startswith('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)

prompt:
An existing "FWD:" prefix is not recognised, so forwarded subjects accumulate prefixes.

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(...).

split: open-access


broken_source:
"""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' + ''.join(',' + a for a in original['attachments']) + ')'}
    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)

source:
"""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' + ''.join(',' + a for a in original['inline']) + ')'}
    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)

prompt:
Forwarding as an attachment also copies the original attachments beside the attached message, duplicating them.

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(...).

split: open-access


broken_source:
"""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)

source:
"""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)

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

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(...).

split: open-access


broken_source:
"""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] + sorted(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)

source:
"""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[::-1]) + ')'
    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)

prompt:
Forwarded attachments are reordered alphabetically.

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(...).

split: open-access