Skip to content

fix: join adjacent MIME encoded words before decoding multibyte text - #182

Open
charan-rathore wants to merge 1 commit into
CopilotKit:mainfrom
charan-rathore:fix/mime-split-multibyte-words
Open

charan-rathore wants to merge 1 commit into
CopilotKit:mainfrom
charan-rathore:fix/mime-split-multibyte-words

Conversation

@charan-rathore

Copy link
Copy Markdown
Contributor

Summary

A sender that wraps a long header at the RFC 2047 encoded-word length limit can break a multibyte character across two adjacent encoded words. decodeHeader glued the words' whitespace together (#130) but still decoded each word on its own, so the split bytes each became U+FFFD: =?UTF-8?B?...w6?= =?UTF-8?B?qQ==?= rendered as caf�� instead of café.

Fix

Per RFC 2047 §6.2, adjacent encoded words are concatenated before decoding. The decoder now matches a run of adjacent words, joins the raw bytes of consecutive same-charset words, and decodes each joined group once. Unknown charsets keep the existing fallback of printing the original words verbatim, and words separated by plain text still decode independently.

Test

mail joins adjacent encoded words that split a multibyte character covers base64 and quoted-printable splits, including a fold-separated pair; it fails on main with replacement characters and passes with the join. The full tests/google.test.ts suite passes (37/37), and tsc --noEmit and biome check are clean.

Signed-off-by: Charan Rathore <180254320+charan-rathore@users.noreply.github.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T19:19:20.631311Z 8b24bc9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8b24bc9b75

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

"latin1",
);
if (pending !== null && normalized === pendingCharset) {
pending = Buffer.concat([pending, bytes]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Concatenate adjacent-word buffers only once

When an incoming Gmail Subject or From contains thousands of adjacent same-charset encoded words, this loop copies the entire accumulated prefix for every word, making decodeHeader quadratic in header size. The mapMessage path accepts unrestricted header strings up to the whole-response limit, so a sufficiently large folded header can cause seconds of CPU time and heavy allocation churn whenever the message is listed or opened; collect the byte chunks and call Buffer.concat once in flush() instead.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
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.

1 participant