FAILURE MAP
← Case archive

FA-76441 / Email MIME structure / Open access

Resolve and de-duplicate attachment file names: backslash separators · case 01

A Windows path sent as the filename is kept whole, directory names included.

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

ROOT CAUSE

The backslash separators decision evaluates `raw` where the contract requires `raw.replace('\\', '/')`.

VERIFIED REPAIR

Use `raw.replace('\\', '/')` for the backslash separators decision and keep every other rule of the model unchanged.

Unsuccessful approach: Replacing doubled backslashes misses the single backslashes of a real path. The attempted `raw.replace('\\\\', '/')` still disagrees with a fixture.

Case contract

Each part has optional fstar (already decoded filename*), fname (filename) and ctname (Content-Type name) and a type. Precedence is fstar, fname, ctname. Directory components are removed (both "/" and "\" separate). An empty name, "." or ".." becomes "attachment" plus an extension by type (.pdf, .png, .txt, else .bin). Names are de-duplicated case-insensitively: the k-th copy gets " (k)" before the last extension, or at the end when there is no extension or the name starts with its only dot.

Why this case matters

Attachment names end up on disk; wrong names overwrite files, leak paths or confuse users.

1 / The failure

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

N = 1
observations = []
def solve(parts):
    exts = {'application/pdf': '.pdf', 'image/png': '.png', 'text/plain': '.txt'}
    used = {}
    out = []
    for p in parts:
        raw = p.get('fstar') or p.get('fname') or p.get('ctname') or ''
        base = raw.split('/')[-1]
        if base in ('', '.', '..'):
            base = 'attachment' + exts.get(p['type'], '.bin')
        key = base.lower()
        used[key] = used.get(key, 0) + 1
        if used[key] > 1:
            stem, dot, ext = base.rpartition('.')
            base = (stem + ' (%d).' % used[key] + ext) if dot and stem else base + ' (%d)' % used[key]
        out.append(base)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('extended name wins', ([{'fstar': 'résumé1.pdf', 'fname': 'resume.pdf', 'ctname': 'r.pdf', 'type': 'application/pdf'}],), ['résumé1.pdf']), ('windows path', ([{'fname': 'C:\\Users\\bo\\report1.docx', 'type': 'application/msword'}, {'fname': '../../etc/passwd', 'type': 'text/plain'}],), ['report1.docx', 'passwd']), ('dot names', ([{'fname': '..', 'type': 'image/png'}, {'fname': '.', 'type': 'text/plain'}],), ['attachment.png', 'attachment.txt']), ('case-insensitive duplicates', ([{'fname': 'Report1.PDF', 'type': 'application/pdf'}, {'ctname': 'report1.pdf', 'type': 'application/pdf'}],), ['Report1.PDF', 'report1 (2).pdf']), ('multi-dot duplicate', ([{'fname': 'archive.tar.gz', 'type': 'application/gzip'}, {'fname': 'archive.tar.gz', 'type': 'application/gzip'}],), ['archive.tar.gz', 'archive.tar (2).gz']), ('dotfile and short stem', ([{'fname': '.profile', 'type': 'text/plain'}, {'fname': '.profile', 'type': 'text/plain'}, {'fname': 'a.pdf', 'type': 'application/pdf'}, {'fname': 'a.pdf', 'type': 'application/pdf'}],), ['.profile', '.profile (2)', 'a.pdf', 'a (2).pdf']), ('third copy', ([{'fname': 'x1.png', 'type': 'image/png'}, {'fname': 'x1.png', 'type': 'image/png'}, {'fname': 'x1.png', 'type': 'image/png'}],), ['x1.png', 'x1 (2).png', 'x1 (3).png']), ('no name at all', ([{'type': 'application/zip'}, {'type': 'application/pdf'}],), ['attachment.bin', 'attachment.pdf'])], 2: [('extended name wins', ([{'fstar': 'résumé2.pdf', 'fname': 'resume.pdf', 'ctname': 'r.pdf', 'type': 'application/pdf'}],), ['résumé2.pdf']), ('windows path', ([{'fname': 'C:\\Users\\bo\\report2.docx', 'type': 'application/msword'}, {'fname': '../../etc/passwd', 'type': 'text/plain'}],), ['report2.docx', 'passwd']), ('dot names', ([{'fname': '..', 'type': 'image/png'}, {'fname': '.', 'type': 'text/plain'}],), ['attachment.png', 'attachment.txt']), ('case-insensitive duplicates', ([{'fname': 'Report2.PDF', 'type': 'application/pdf'}, {'ctname': 'report2.pdf', 'type': 'application/pdf'}],), ['Report2.PDF', 'report2 (2).pdf']), ('multi-dot duplicate', ([{'fname': 'archive.tar.gz', 'type': 'application/gzip'}, {'fname': 'archive.tar.gz', 'type': 'application/gzip'}],), ['archive.tar.gz', 'archive.tar (2).gz']), ('dotfile and short stem', ([{'fname': '.profile', 'type': 'text/plain'}, {'fname': '.profile', 'type': 'text/plain'}, {'fname': 'a.pdf', 'type': 'application/pdf'}, {'fname': 'a.pdf', 'type': 'application/pdf'}],), ['.profile', '.profile (2)', 'a.pdf', 'a (2).pdf']), ('third copy', ([{'fname': 'x2.png', 'type': 'image/png'}, {'fname': 'x2.png', 'type': 'image/png'}, {'fname': 'x2.png', 'type': 'image/png'}],), ['x2.png', 'x2 (2).png', 'x2 (3).png']), ('no name at all', ([{'type': 'application/zip'}, {'type': 'application/pdf'}],), ['attachment.bin', 'attachment.pdf'])], 3: [('extended name wins', ([{'fstar': 'résumé3.pdf', 'fname': 'resume.pdf', 'ctname': 'r.pdf', 'type': 'application/pdf'}],), ['résumé3.pdf']), ('windows path', ([{'fname': 'C:\\Users\\bo\\report3.docx', 'type': 'application/msword'}, {'fname': '../../etc/passwd', 'type': 'text/plain'}],), ['report3.docx', 'passwd']), ('dot names', ([{'fname': '..', 'type': 'image/png'}, {'fname': '.', 'type': 'text/plain'}],), ['attachment.png', 'attachment.txt']), ('case-insensitive duplicates', ([{'fname': 'Report3.PDF', 'type': 'application/pdf'}, {'ctname': 'report3.pdf', 'type': 'application/pdf'}],), ['Report3.PDF', 'report3 (2).pdf']), ('multi-dot duplicate', ([{'fname': 'archive.tar.gz', 'type': 'application/gzip'}, {'fname': 'archive.tar.gz', 'type': 'application/gzip'}],), ['archive.tar.gz', 'archive.tar (2).gz']), ('dotfile and short stem', ([{'fname': '.profile', 'type': 'text/plain'}, {'fname': '.profile', 'type': 'text/plain'}, {'fname': 'a.pdf', 'type': 'application/pdf'}, {'fname': 'a.pdf', 'type': 'application/pdf'}],), ['.profile', '.profile (2)', 'a.pdf', 'a (2).pdf']), ('third copy', ([{'fname': 'x3.png', 'type': 'image/png'}, {'fname': 'x3.png', 'type': 'image/png'}, {'fname': 'x3.png', 'type': 'image/png'}],), ['x3.png', 'x3 (2).png', 'x3 (3).png']), ('no name at all', ([{'type': 'application/zip'}, {'type': 'application/pdf'}],), ['attachment.bin', 'attachment.pdf'])], 4: [('extended name wins', ([{'fstar': 'résumé4.pdf', 'fname': 'resume.pdf', 'ctname': 'r.pdf', 'type': 'application/pdf'}],), ['résumé4.pdf']), ('windows path', ([{'fname': 'C:\\Users\\bo\\report4.docx', 'type': 'application/msword'}, {'fname': '../../etc/passwd', 'type': 'text/plain'}],), ['report4.docx', 'passwd']), ('dot names', ([{'fname': '..', 'type': 'image/png'}, {'fname': '.', 'type': 'text/plain'}],), ['attachment.png', 'attachment.txt']), ('case-insensitive duplicates', ([{'fname': 'Report4.PDF', 'type': 'application/pdf'}, {'ctname': 'report4.pdf', 'type': 'application/pdf'}],), ['Report4.PDF', 'report4 (2).pdf']), ('multi-dot duplicate', ([{'fname': 'archive.tar.gz', 'type': 'application/gzip'}, {'fname': 'archive.tar.gz', 'type': 'application/gzip'}],), ['archive.tar.gz', 'archive.tar (2).gz']), ('dotfile and short stem', ([{'fname': '.profile', 'type': 'text/plain'}, {'fname': '.profile', 'type': 'text/plain'}, {'fname': 'a.pdf', 'type': 'application/pdf'}, {'fname': 'a.pdf', 'type': 'application/pdf'}],), ['.profile', '.profile (2)', 'a.pdf', 'a (2).pdf']), ('third copy', ([{'fname': 'x4.png', 'type': 'image/png'}, {'fname': 'x4.png', 'type': 'image/png'}, {'fname': 'x4.png', 'type': 'image/png'}],), ['x4.png', 'x4 (2).png', 'x4 (3).png']), ('no name at all', ([{'type': 'application/zip'}, {'type': 'application/pdf'}],), ['attachment.bin', 'attachment.pdf'])], 5: [('extended name wins', ([{'fstar': 'résumé5.pdf', 'fname': 'resume.pdf', 'ctname': 'r.pdf', 'type': 'application/pdf'}],), ['résumé5.pdf']), ('windows path', ([{'fname': 'C:\\Users\\bo\\report5.docx', 'type': 'application/msword'}, {'fname': '../../etc/passwd', 'type': 'text/plain'}],), ['report5.docx', 'passwd']), ('dot names', ([{'fname': '..', 'type': 'image/png'}, {'fname': '.', 'type': 'text/plain'}],), ['attachment.png', 'attachment.txt']), ('case-insensitive duplicates', ([{'fname': 'Report5.PDF', 'type': 'application/pdf'}, {'ctname': 'report5.pdf', 'type': 'application/pdf'}],), ['Report5.PDF', 'report5 (2).pdf']), ('multi-dot duplicate', ([{'fname': 'archive.tar.gz', 'type': 'application/gzip'}, {'fname': 'archive.tar.gz', 'type': 'application/gzip'}],), ['archive.tar.gz', 'archive.tar (2).gz']), ('dotfile and short stem', ([{'fname': '.profile', 'type': 'text/plain'}, {'fname': '.profile', 'type': 'text/plain'}, {'fname': 'a.pdf', 'type': 'application/pdf'}, {'fname': 'a.pdf', 'type': 'application/pdf'}],), ['.profile', '.profile (2)', 'a.pdf', 'a (2).pdf']), ('third copy', ([{'fname': 'x5.png', 'type': 'image/png'}, {'fname': 'x5.png', 'type': 'image/png'}, {'fname': 'x5.png', 'type': 'image/png'}],), ['x5.png', 'x5 (2).png', 'x5 (3).png']), ('no name at all', ([{'type': 'application/zip'}, {'type': 'application/pdf'}],), ['attachment.bin', 'attachment.pdf'])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
extended name wins['résumé1.pdf']['résumé1.pdf']Passed
windows path['C:\\Users\\bo\\report1.docx', 'passwd']['report1.docx', 'passwd']Failed
dot names['attachment.png', 'attachment.txt']['attachment.png', 'attachment.txt']Passed
case-insensitive duplicates['Report1.PDF', 'report1 (2).pdf']['Report1.PDF', 'report1 (2).pdf']Passed
multi-dot duplicate['archive.tar.gz', 'archive.tar (2).gz']['archive.tar.gz', 'archive.tar (2).gz']Passed
dotfile and short stem['.profile', '.profile (2)', 'a.pdf', 'a (2).pdf']['.profile', '.profile (2)', 'a.pdf', 'a (2).pdf']Passed
third copy['x1.png', 'x1 (2).png', 'x1 (3).png']['x1.png', 'x1 (2).png', 'x1 (3).png']Passed
no name at all['attachment.bin', 'attachment.pdf']['attachment.bin', 'attachment.pdf']Passed

SHA-256 / cf0648c3933dd36de6f41e9b14dbb39233e3a3bd824c27d0452785525b391efe

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(parts):
    exts = {'application/pdf': '.pdf', 'image/png': '.png', 'text/plain': '.txt'}
    used = {}
    out = []
    for p in parts:
        raw = p.get('fstar') or p.get('fname') or p.get('ctname') or ''
        base = raw.replace('\\\\', '/').split('/')[-1]
        if base in ('', '.', '..'):
            base = 'attachment' + exts.get(p['type'], '.bin')
        key = base.lower()
        used[key] = used.get(key, 0) + 1
        if used[key] > 1:
            stem, dot, ext = base.rpartition('.')
            base = (stem + ' (%d).' % used[key] + ext) if dot and stem else base + ' (%d)' % used[key]
        out.append(base)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('extended name wins', ([{'fstar': 'résumé1.pdf', 'fname': 'resume.pdf', 'ctname': 'r.pdf', 'type': 'application/pdf'}],), ['résumé1.pdf']), ('windows path', ([{'fname': 'C:\\Users\\bo\\report1.docx', 'type': 'application/msword'}, {'fname': '../../etc/passwd', 'type': 'text/plain'}],), ['report1.docx', 'passwd']), ('dot names', ([{'fname': '..', 'type': 'image/png'}, {'fname': '.', 'type': 'text/plain'}],), ['attachment.png', 'attachment.txt']), ('case-insensitive duplicates', ([{'fname': 'Report1.PDF', 'type': 'application/pdf'}, {'ctname': 'report1.pdf', 'type': 'application/pdf'}],), ['Report1.PDF', 'report1 (2).pdf']), ('multi-dot duplicate', ([{'fname': 'archive.tar.gz', 'type': 'application/gzip'}, {'fname': 'archive.tar.gz', 'type': 'application/gzip'}],), ['archive.tar.gz', 'archive.tar (2).gz']), ('dotfile and short stem', ([{'fname': '.profile', 'type': 'text/plain'}, {'fname': '.profile', 'type': 'text/plain'}, {'fname': 'a.pdf', 'type': 'application/pdf'}, {'fname': 'a.pdf', 'type': 'application/pdf'}],), ['.profile', '.profile (2)', 'a.pdf', 'a (2).pdf']), ('third copy', ([{'fname': 'x1.png', 'type': 'image/png'}, {'fname': 'x1.png', 'type': 'image/png'}, {'fname': 'x1.png', 'type': 'image/png'}],), ['x1.png', 'x1 (2).png', 'x1 (3).png']), ('no name at all', ([{'type': 'application/zip'}, {'type': 'application/pdf'}],), ['attachment.bin', 'attachment.pdf'])], 2: [('extended name wins', ([{'fstar': 'résumé2.pdf', 'fname': 'resume.pdf', 'ctname': 'r.pdf', 'type': 'application/pdf'}],), ['résumé2.pdf']), ('windows path', ([{'fname': 'C:\\Users\\bo\\report2.docx', 'type': 'application/msword'}, {'fname': '../../etc/passwd', 'type': 'text/plain'}],), ['report2.docx', 'passwd']), ('dot names', ([{'fname': '..', 'type': 'image/png'}, {'fname': '.', 'type': 'text/plain'}],), ['attachment.png', 'attachment.txt']), ('case-insensitive duplicates', ([{'fname': 'Report2.PDF', 'type': 'application/pdf'}, {'ctname': 'report2.pdf', 'type': 'application/pdf'}],), ['Report2.PDF', 'report2 (2).pdf']), ('multi-dot duplicate', ([{'fname': 'archive.tar.gz', 'type': 'application/gzip'}, {'fname': 'archive.tar.gz', 'type': 'application/gzip'}],), ['archive.tar.gz', 'archive.tar (2).gz']), ('dotfile and short stem', ([{'fname': '.profile', 'type': 'text/plain'}, {'fname': '.profile', 'type': 'text/plain'}, {'fname': 'a.pdf', 'type': 'application/pdf'}, {'fname': 'a.pdf', 'type': 'application/pdf'}],), ['.profile', '.profile (2)', 'a.pdf', 'a (2).pdf']), ('third copy', ([{'fname': 'x2.png', 'type': 'image/png'}, {'fname': 'x2.png', 'type': 'image/png'}, {'fname': 'x2.png', 'type': 'image/png'}],), ['x2.png', 'x2 (2).png', 'x2 (3).png']), ('no name at all', ([{'type': 'application/zip'}, {'type': 'application/pdf'}],), ['attachment.bin', 'attachment.pdf'])], 3: [('extended name wins', ([{'fstar': 'résumé3.pdf', 'fname': 'resume.pdf', 'ctname': 'r.pdf', 'type': 'application/pdf'}],), ['résumé3.pdf']), ('windows path', ([{'fname': 'C:\\Users\\bo\\report3.docx', 'type': 'application/msword'}, {'fname': '../../etc/passwd', 'type': 'text/plain'}],), ['report3.docx', 'passwd']), ('dot names', ([{'fname': '..', 'type': 'image/png'}, {'fname': '.', 'type': 'text/plain'}],), ['attachment.png', 'attachment.txt']), ('case-insensitive duplicates', ([{'fname': 'Report3.PDF', 'type': 'application/pdf'}, {'ctname': 'report3.pdf', 'type': 'application/pdf'}],), ['Report3.PDF', 'report3 (2).pdf']), ('multi-dot duplicate', ([{'fname': 'archive.tar.gz', 'type': 'application/gzip'}, {'fname': 'archive.tar.gz', 'type': 'application/gzip'}],), ['archive.tar.gz', 'archive.tar (2).gz']), ('dotfile and short stem', ([{'fname': '.profile', 'type': 'text/plain'}, {'fname': '.profile', 'type': 'text/plain'}, {'fname': 'a.pdf', 'type': 'application/pdf'}, {'fname': 'a.pdf', 'type': 'application/pdf'}],), ['.profile', '.profile (2)', 'a.pdf', 'a (2).pdf']), ('third copy', ([{'fname': 'x3.png', 'type': 'image/png'}, {'fname': 'x3.png', 'type': 'image/png'}, {'fname': 'x3.png', 'type': 'image/png'}],), ['x3.png', 'x3 (2).png', 'x3 (3).png']), ('no name at all', ([{'type': 'application/zip'}, {'type': 'application/pdf'}],), ['attachment.bin', 'attachment.pdf'])], 4: [('extended name wins', ([{'fstar': 'résumé4.pdf', 'fname': 'resume.pdf', 'ctname': 'r.pdf', 'type': 'application/pdf'}],), ['résumé4.pdf']), ('windows path', ([{'fname': 'C:\\Users\\bo\\report4.docx', 'type': 'application/msword'}, {'fname': '../../etc/passwd', 'type': 'text/plain'}],), ['report4.docx', 'passwd']), ('dot names', ([{'fname': '..', 'type': 'image/png'}, {'fname': '.', 'type': 'text/plain'}],), ['attachment.png', 'attachment.txt']), ('case-insensitive duplicates', ([{'fname': 'Report4.PDF', 'type': 'application/pdf'}, {'ctname': 'report4.pdf', 'type': 'application/pdf'}],), ['Report4.PDF', 'report4 (2).pdf']), ('multi-dot duplicate', ([{'fname': 'archive.tar.gz', 'type': 'application/gzip'}, {'fname': 'archive.tar.gz', 'type': 'application/gzip'}],), ['archive.tar.gz', 'archive.tar (2).gz']), ('dotfile and short stem', ([{'fname': '.profile', 'type': 'text/plain'}, {'fname': '.profile', 'type': 'text/plain'}, {'fname': 'a.pdf', 'type': 'application/pdf'}, {'fname': 'a.pdf', 'type': 'application/pdf'}],), ['.profile', '.profile (2)', 'a.pdf', 'a (2).pdf']), ('third copy', ([{'fname': 'x4.png', 'type': 'image/png'}, {'fname': 'x4.png', 'type': 'image/png'}, {'fname': 'x4.png', 'type': 'image/png'}],), ['x4.png', 'x4 (2).png', 'x4 (3).png']), ('no name at all', ([{'type': 'application/zip'}, {'type': 'application/pdf'}],), ['attachment.bin', 'attachment.pdf'])], 5: [('extended name wins', ([{'fstar': 'résumé5.pdf', 'fname': 'resume.pdf', 'ctname': 'r.pdf', 'type': 'application/pdf'}],), ['résumé5.pdf']), ('windows path', ([{'fname': 'C:\\Users\\bo\\report5.docx', 'type': 'application/msword'}, {'fname': '../../etc/passwd', 'type': 'text/plain'}],), ['report5.docx', 'passwd']), ('dot names', ([{'fname': '..', 'type': 'image/png'}, {'fname': '.', 'type': 'text/plain'}],), ['attachment.png', 'attachment.txt']), ('case-insensitive duplicates', ([{'fname': 'Report5.PDF', 'type': 'application/pdf'}, {'ctname': 'report5.pdf', 'type': 'application/pdf'}],), ['Report5.PDF', 'report5 (2).pdf']), ('multi-dot duplicate', ([{'fname': 'archive.tar.gz', 'type': 'application/gzip'}, {'fname': 'archive.tar.gz', 'type': 'application/gzip'}],), ['archive.tar.gz', 'archive.tar (2).gz']), ('dotfile and short stem', ([{'fname': '.profile', 'type': 'text/plain'}, {'fname': '.profile', 'type': 'text/plain'}, {'fname': 'a.pdf', 'type': 'application/pdf'}, {'fname': 'a.pdf', 'type': 'application/pdf'}],), ['.profile', '.profile (2)', 'a.pdf', 'a (2).pdf']), ('third copy', ([{'fname': 'x5.png', 'type': 'image/png'}, {'fname': 'x5.png', 'type': 'image/png'}, {'fname': 'x5.png', 'type': 'image/png'}],), ['x5.png', 'x5 (2).png', 'x5 (3).png']), ('no name at all', ([{'type': 'application/zip'}, {'type': 'application/pdf'}],), ['attachment.bin', 'attachment.pdf'])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
extended name wins['résumé1.pdf']['résumé1.pdf']Passed
windows path['C:\\Users\\bo\\report1.docx', 'passwd']['report1.docx', 'passwd']Failed
dot names['attachment.png', 'attachment.txt']['attachment.png', 'attachment.txt']Passed
case-insensitive duplicates['Report1.PDF', 'report1 (2).pdf']['Report1.PDF', 'report1 (2).pdf']Passed
multi-dot duplicate['archive.tar.gz', 'archive.tar (2).gz']['archive.tar.gz', 'archive.tar (2).gz']Passed
dotfile and short stem['.profile', '.profile (2)', 'a.pdf', 'a (2).pdf']['.profile', '.profile (2)', 'a.pdf', 'a (2).pdf']Passed
third copy['x1.png', 'x1 (2).png', 'x1 (3).png']['x1.png', 'x1 (2).png', 'x1 (3).png']Passed
no name at all['attachment.bin', 'attachment.pdf']['attachment.bin', 'attachment.pdf']Passed

SHA-256 / 7892ed75e1f18d2b727aeffc128a7e277653ca330b4b34995787b23bfce32bb6

3 / The verified repair

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

N = 1
observations = []
def solve(parts):
    exts = {'application/pdf': '.pdf', 'image/png': '.png', 'text/plain': '.txt'}
    used = {}
    out = []
    for p in parts:
        raw = p.get('fstar') or p.get('fname') or p.get('ctname') or ''
        base = raw.replace('\\', '/').split('/')[-1]
        if base in ('', '.', '..'):
            base = 'attachment' + exts.get(p['type'], '.bin')
        key = base.lower()
        used[key] = used.get(key, 0) + 1
        if used[key] > 1:
            stem, dot, ext = base.rpartition('.')
            base = (stem + ' (%d).' % used[key] + ext) if dot and stem else base + ' (%d)' % used[key]
        out.append(base)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('extended name wins', ([{'fstar': 'résumé1.pdf', 'fname': 'resume.pdf', 'ctname': 'r.pdf', 'type': 'application/pdf'}],), ['résumé1.pdf']), ('windows path', ([{'fname': 'C:\\Users\\bo\\report1.docx', 'type': 'application/msword'}, {'fname': '../../etc/passwd', 'type': 'text/plain'}],), ['report1.docx', 'passwd']), ('dot names', ([{'fname': '..', 'type': 'image/png'}, {'fname': '.', 'type': 'text/plain'}],), ['attachment.png', 'attachment.txt']), ('case-insensitive duplicates', ([{'fname': 'Report1.PDF', 'type': 'application/pdf'}, {'ctname': 'report1.pdf', 'type': 'application/pdf'}],), ['Report1.PDF', 'report1 (2).pdf']), ('multi-dot duplicate', ([{'fname': 'archive.tar.gz', 'type': 'application/gzip'}, {'fname': 'archive.tar.gz', 'type': 'application/gzip'}],), ['archive.tar.gz', 'archive.tar (2).gz']), ('dotfile and short stem', ([{'fname': '.profile', 'type': 'text/plain'}, {'fname': '.profile', 'type': 'text/plain'}, {'fname': 'a.pdf', 'type': 'application/pdf'}, {'fname': 'a.pdf', 'type': 'application/pdf'}],), ['.profile', '.profile (2)', 'a.pdf', 'a (2).pdf']), ('third copy', ([{'fname': 'x1.png', 'type': 'image/png'}, {'fname': 'x1.png', 'type': 'image/png'}, {'fname': 'x1.png', 'type': 'image/png'}],), ['x1.png', 'x1 (2).png', 'x1 (3).png']), ('no name at all', ([{'type': 'application/zip'}, {'type': 'application/pdf'}],), ['attachment.bin', 'attachment.pdf'])], 2: [('extended name wins', ([{'fstar': 'résumé2.pdf', 'fname': 'resume.pdf', 'ctname': 'r.pdf', 'type': 'application/pdf'}],), ['résumé2.pdf']), ('windows path', ([{'fname': 'C:\\Users\\bo\\report2.docx', 'type': 'application/msword'}, {'fname': '../../etc/passwd', 'type': 'text/plain'}],), ['report2.docx', 'passwd']), ('dot names', ([{'fname': '..', 'type': 'image/png'}, {'fname': '.', 'type': 'text/plain'}],), ['attachment.png', 'attachment.txt']), ('case-insensitive duplicates', ([{'fname': 'Report2.PDF', 'type': 'application/pdf'}, {'ctname': 'report2.pdf', 'type': 'application/pdf'}],), ['Report2.PDF', 'report2 (2).pdf']), ('multi-dot duplicate', ([{'fname': 'archive.tar.gz', 'type': 'application/gzip'}, {'fname': 'archive.tar.gz', 'type': 'application/gzip'}],), ['archive.tar.gz', 'archive.tar (2).gz']), ('dotfile and short stem', ([{'fname': '.profile', 'type': 'text/plain'}, {'fname': '.profile', 'type': 'text/plain'}, {'fname': 'a.pdf', 'type': 'application/pdf'}, {'fname': 'a.pdf', 'type': 'application/pdf'}],), ['.profile', '.profile (2)', 'a.pdf', 'a (2).pdf']), ('third copy', ([{'fname': 'x2.png', 'type': 'image/png'}, {'fname': 'x2.png', 'type': 'image/png'}, {'fname': 'x2.png', 'type': 'image/png'}],), ['x2.png', 'x2 (2).png', 'x2 (3).png']), ('no name at all', ([{'type': 'application/zip'}, {'type': 'application/pdf'}],), ['attachment.bin', 'attachment.pdf'])], 3: [('extended name wins', ([{'fstar': 'résumé3.pdf', 'fname': 'resume.pdf', 'ctname': 'r.pdf', 'type': 'application/pdf'}],), ['résumé3.pdf']), ('windows path', ([{'fname': 'C:\\Users\\bo\\report3.docx', 'type': 'application/msword'}, {'fname': '../../etc/passwd', 'type': 'text/plain'}],), ['report3.docx', 'passwd']), ('dot names', ([{'fname': '..', 'type': 'image/png'}, {'fname': '.', 'type': 'text/plain'}],), ['attachment.png', 'attachment.txt']), ('case-insensitive duplicates', ([{'fname': 'Report3.PDF', 'type': 'application/pdf'}, {'ctname': 'report3.pdf', 'type': 'application/pdf'}],), ['Report3.PDF', 'report3 (2).pdf']), ('multi-dot duplicate', ([{'fname': 'archive.tar.gz', 'type': 'application/gzip'}, {'fname': 'archive.tar.gz', 'type': 'application/gzip'}],), ['archive.tar.gz', 'archive.tar (2).gz']), ('dotfile and short stem', ([{'fname': '.profile', 'type': 'text/plain'}, {'fname': '.profile', 'type': 'text/plain'}, {'fname': 'a.pdf', 'type': 'application/pdf'}, {'fname': 'a.pdf', 'type': 'application/pdf'}],), ['.profile', '.profile (2)', 'a.pdf', 'a (2).pdf']), ('third copy', ([{'fname': 'x3.png', 'type': 'image/png'}, {'fname': 'x3.png', 'type': 'image/png'}, {'fname': 'x3.png', 'type': 'image/png'}],), ['x3.png', 'x3 (2).png', 'x3 (3).png']), ('no name at all', ([{'type': 'application/zip'}, {'type': 'application/pdf'}],), ['attachment.bin', 'attachment.pdf'])], 4: [('extended name wins', ([{'fstar': 'résumé4.pdf', 'fname': 'resume.pdf', 'ctname': 'r.pdf', 'type': 'application/pdf'}],), ['résumé4.pdf']), ('windows path', ([{'fname': 'C:\\Users\\bo\\report4.docx', 'type': 'application/msword'}, {'fname': '../../etc/passwd', 'type': 'text/plain'}],), ['report4.docx', 'passwd']), ('dot names', ([{'fname': '..', 'type': 'image/png'}, {'fname': '.', 'type': 'text/plain'}],), ['attachment.png', 'attachment.txt']), ('case-insensitive duplicates', ([{'fname': 'Report4.PDF', 'type': 'application/pdf'}, {'ctname': 'report4.pdf', 'type': 'application/pdf'}],), ['Report4.PDF', 'report4 (2).pdf']), ('multi-dot duplicate', ([{'fname': 'archive.tar.gz', 'type': 'application/gzip'}, {'fname': 'archive.tar.gz', 'type': 'application/gzip'}],), ['archive.tar.gz', 'archive.tar (2).gz']), ('dotfile and short stem', ([{'fname': '.profile', 'type': 'text/plain'}, {'fname': '.profile', 'type': 'text/plain'}, {'fname': 'a.pdf', 'type': 'application/pdf'}, {'fname': 'a.pdf', 'type': 'application/pdf'}],), ['.profile', '.profile (2)', 'a.pdf', 'a (2).pdf']), ('third copy', ([{'fname': 'x4.png', 'type': 'image/png'}, {'fname': 'x4.png', 'type': 'image/png'}, {'fname': 'x4.png', 'type': 'image/png'}],), ['x4.png', 'x4 (2).png', 'x4 (3).png']), ('no name at all', ([{'type': 'application/zip'}, {'type': 'application/pdf'}],), ['attachment.bin', 'attachment.pdf'])], 5: [('extended name wins', ([{'fstar': 'résumé5.pdf', 'fname': 'resume.pdf', 'ctname': 'r.pdf', 'type': 'application/pdf'}],), ['résumé5.pdf']), ('windows path', ([{'fname': 'C:\\Users\\bo\\report5.docx', 'type': 'application/msword'}, {'fname': '../../etc/passwd', 'type': 'text/plain'}],), ['report5.docx', 'passwd']), ('dot names', ([{'fname': '..', 'type': 'image/png'}, {'fname': '.', 'type': 'text/plain'}],), ['attachment.png', 'attachment.txt']), ('case-insensitive duplicates', ([{'fname': 'Report5.PDF', 'type': 'application/pdf'}, {'ctname': 'report5.pdf', 'type': 'application/pdf'}],), ['Report5.PDF', 'report5 (2).pdf']), ('multi-dot duplicate', ([{'fname': 'archive.tar.gz', 'type': 'application/gzip'}, {'fname': 'archive.tar.gz', 'type': 'application/gzip'}],), ['archive.tar.gz', 'archive.tar (2).gz']), ('dotfile and short stem', ([{'fname': '.profile', 'type': 'text/plain'}, {'fname': '.profile', 'type': 'text/plain'}, {'fname': 'a.pdf', 'type': 'application/pdf'}, {'fname': 'a.pdf', 'type': 'application/pdf'}],), ['.profile', '.profile (2)', 'a.pdf', 'a (2).pdf']), ('third copy', ([{'fname': 'x5.png', 'type': 'image/png'}, {'fname': 'x5.png', 'type': 'image/png'}, {'fname': 'x5.png', 'type': 'image/png'}],), ['x5.png', 'x5 (2).png', 'x5 (3).png']), ('no name at all', ([{'type': 'application/zip'}, {'type': 'application/pdf'}],), ['attachment.bin', 'attachment.pdf'])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
extended name wins['résumé1.pdf']['résumé1.pdf']Passed
windows path['report1.docx', 'passwd']['report1.docx', 'passwd']Passed
dot names['attachment.png', 'attachment.txt']['attachment.png', 'attachment.txt']Passed
case-insensitive duplicates['Report1.PDF', 'report1 (2).pdf']['Report1.PDF', 'report1 (2).pdf']Passed
multi-dot duplicate['archive.tar.gz', 'archive.tar (2).gz']['archive.tar.gz', 'archive.tar (2).gz']Passed
dotfile and short stem['.profile', '.profile (2)', 'a.pdf', 'a (2).pdf']['.profile', '.profile (2)', 'a.pdf', 'a (2).pdf']Passed
third copy['x1.png', 'x1 (2).png', 'x1 (3).png']['x1.png', 'x1 (2).png', 'x1 (3).png']Passed
no name at all['attachment.bin', 'attachment.pdf']['attachment.bin', 'attachment.pdf']Passed

SHA-256 / 1d6c1d8f7b811741c661df82a23e61f0bc8447645eee6b8ea7e98117a34e1da9

Verification & scope

Stipulated offline model over pre-parsed MIME dictionaries; not a conforming MIME parser, generator or mail client. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:49:16.183402+00:00.

Case digest / 8ef98c4dd8819dcf0a180bdbc6e28f1481df14a2e0b10e634791987c0ceed0c7