Skip to content

Decode an inbound email part in the charset it names, not always as UTF-8 - #787

Open
kevin9327 wants to merge 1 commit into
CopilotKit:mainfrom
kevin9327:fix/email-charset
Open

kevin9327 wants to merge 1 commit into
CopilotKit:mainfrom
kevin9327:fix/email-charset

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

What was wrong

extractEmailText (the SES → SNS email trigger) turned base64 and quoted-printable parts into bytes and then always read them as UTF-8, ignoring the charset on the part's Content-Type. A part sent as text/plain; charset=iso-8859-1 (or windows-1252, still common from Outlook and older mailers) saying Caf=E9 ferm=E9 reached the Bot as Caf� ferm�.

Change

decodeBody now takes the part's charset and decodes the bytes with TextDecoder(charset). A missing or unknown charset label still reads as UTF-8, so existing behaviour is unchanged for UTF-8 mail.

Test

New case in server/tests/responsibility-triggers.test.ts: an ISO-8859-1 quoted-printable part, a quoted windows-1252 base64 part, and a UTF-8 quoted-printable part.

  • Before: Expected "Café fermé à minuit." Received "Caf� ferm� � minuit."
  • After: bun test tests/responsibility-triggers.test.ts → 29 pass, 0 fail
  • biome check clean on both files

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

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