Skip to content

test(mail): cover decodeCharset and headerParams by name (#221) - #247

Merged
juancguerrerodev merged 5 commits into
DojoCodingLabs:mainfrom
saurabhbhoir456:test/mail-charset-221
Dec 6, 2026
Merged

juancguerrerodev merged 5 commits into
DojoCodingLabs:mainfrom
saurabhbhoir456:test/mail-charset-221

Conversation

@saurabhbhoir456

@saurabhbhoir456 saurabhbhoir456 commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

Closes #221

packages/mail/src/mime-read.ts reads incoming mail from IMAP. Two of its helpers had no test that called them by
name: decodeCharset, which turns a part's bytes into text for its declared charset, and headerParams, which splits
a Content-Type or Content-Disposition into its value and parameters. The existing tests reached them only through
whole messages.

What this PR does

  • Adds a describe block for each helper to packages/mail/test/mime-read.test.ts, importing them from
    ../src/mime-read.ts. Tests only: mime-read.ts is unchanged.

Tests

  • decodeCharset with utf-8 and UTF8 (any case, with spaces around it) decodes UTF-8: "señal", "acción" and an
    emoji.
  • With iso-8859-1, latin1 and windows-1252, a byte like 0xF1 reads as "ñ", and bytes in 0x80 to 0x9F read
    as Windows-1252 (for example 0x80 is the euro sign and 0x93 and 0x94 are curly quotes).
  • With no charset, or one it does not know, valid UTF-8 reads as UTF-8 and anything else falls back to Windows-1252,
    with no U+FFFD in the result.
  • headerParams("text/plain; charset=UTF-8") gives the value text/plain and the parameter charset.
  • The value and parameter names come back in lower case; parameter values keep their case.
  • A ; inside quotes does not split, and a backslash escape inside quotes keeps the next character.
  • A repeated parameter keeps the first one. A piece with no = is skipped. undefined gives an empty value and no
    parameters.
  • Only the first 31 parameters are read: a header with 40 gives a map of size 31.
  • Today the quotes around a quoted value are dropped. That is pinned in a test, so a change to it is a choice someone
    makes on purpose.

How to check

pnpm --filter @hermit/mail test test/mime-read.test.ts
pnpm --filter @hermit/mail test
pnpm --filter @hermit/mail typecheck

Keep in mind

  • Tests only. Bytes built with Uint8Array.from([...]) or TextEncoder. Made-up text only, never a real message.

Pull request template

What and why

Closes #221.

Adds named tests for decodeCharset and headerParams in the IMAP reader.

Vision fit

Principle 5, Spanish and English first-class: much of Latin America's mail still arrives as Windows-1252, and it now reads as intended by test.

Non-negotiables

  • This keeps every non-negotiable in AGENTS.md as it is.
  • Or it changes one, and this is the accepted RFC: n/a

Checklist

  • It closes one issue, linked above, or it's a small fix (a typo, a broken link, a wrong comment). A feature has an accepted proposal.
  • I wrote the failing test first. It fails without this change and passes with it. Tests were added for the existing helpers; a broken expectation was checked to fail during development.
  • These pass: pnpm check:privacy, pnpm typecheck, pnpm lint, pnpm test and node scripts/guard/check.mjs --patterns scripts/guard/patterns.txt. Gate note: privacy and guard pass on this checkout today; the rest was run per package as listed under AI agents, not as one root gate on this Windows machine, where unrelated pre-existing failures appear in the site badges, the devices table and mobile source scans.
  • No new network call, telemetry, analytics, ads or crash reporting. (A new request in an app adapter is explained below, with its host, skill and risk.)
  • No new dependency, or the reason for each one is below.
  • Every UI string is in packages/copy, in es-419 and en, with matching keys and placeholders, and no em or en dashes.
  • Tests, fixtures and screenshots use made-up data only.

Model path

  • This doesn't touch the model path: packages/model, agent, skills or eval, the prompt, the router, tool descriptions, normalizers, examples or the model file.
  • It does. The eval numbers from before and after are below, run as docs/evals.md says. No held-out case was tuned on.

Screenshots

  • No UI change.
  • UI change. Each changed screen is below, in both themes and both languages, with made-up data.

New dependencies and network calls

None. No new dependency and no new network call.

AI agents

  • No AI agent wrote any part of this.
  • An AI agent helped. Which one, and what it did: Tinsel Alpha, an AI coding agent running in OpenCode, drafted the change and this description and ran the checks below, in a session directed by the author, who reviewed each step's report before it was pushed.
  • I read and ran everything in this pull request, and I can explain it.

What was run: pnpm --filter @hermit/mail exec vitest run test/mime-read.test.ts (16/16); full @hermit/mail test at the time; typecheck; eslint.

@juancguerrerodev

Copy link
Copy Markdown
Contributor

Ready to merge once the pull request template is filled in, including the "I read and ran everything" box (details on #234). 🦀

@juancguerrerodev
juancguerrerodev merged commit 616a0b5 into DojoCodingLabs:main Dec 6, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mail: test decodeCharset and headerParams

3 participants