Repository navigation
fix(receiving): forward raw email bytes without re-decoding them as UTF-8 - #1117
Merged
dielduarte merged 2 commits intoOct 6, 2026
Merged
Conversation
dielduarte
requested changes
Oct 3, 2026
Comment on lines
+1153
to
+1167
| fetchMock.mockOnce(JSON.stringify(getEmailResponse), { | ||
| status: 200, | ||
| headers: { 'content-type': 'application/json' }, | ||
| }); | ||
| fetchMock.mockOnce( | ||
| async () => | ||
| new Response(latin1Message, { | ||
| status: 200, | ||
| headers: { 'content-type': 'message/rfc822' }, | ||
| }) as unknown as string, | ||
| ); | ||
| fetchMock.mockOnce(JSON.stringify({ id: 'new-email-id' }), { | ||
| status: 200, | ||
| headers: { 'content-type': 'application/json' }, | ||
| }); |
Contributor
There was a problem hiding this comment.
looks like we are repeating these mocks on each tests, can you please move to a beforeEach block?
| new Response(latin1Message, { | ||
| status: 200, | ||
| headers: { 'content-type': 'message/rfc822' }, | ||
| }) as unknown as string, |
Contributor
There was a problem hiding this comment.
The as unknown as string casts aren't needed. vitest-fetch-mock 0.4.5 types its mock responses as MockResponse | ResponseBody | Response, so a real Response is already allowed
RaphaelFakhri
force-pushed
the
fix/forward-raw-email-bytes
branch
from
October 3, 2026 16:21
de6e31f to
9004bcd
Compare
Contributor
Author
|
Thanks. I rebased on canary (the fix now lives in downloadRaw), moved the mocks into a beforeEach and dropped the casts. |
commit: |
dielduarte
approved these changes
Oct 6, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
emails.receiving.forward()downloads the raw message withresponse.text(). That call decodes the bytes as UTF-8, so any byte that is not valid UTF-8 becomes U+FFFD before the message is used.passthrough: false), the.emlattachment is built from the decoded string. The forwarded attachment no longer matches the original message.postal-mimereceives a string, so it cannot apply the charset declared in the message. A body such astext/plain; charset="ISO-8859-1"with an 8-bit0xE9byte forwards ascaf�instead ofcafé.This change reads the download with
arrayBuffer()in both paths.postal-mimedecodes the bytes with the declared charset, and the wrapped attachment is the exact original bytes encoded as base64.Testing
src/emails/receiving/receiving.spec.tsforward an ISO-8859-1 message in each mode.vitest run --exclude e2e),biome checkandtsc --noEmitpass.Summary by cubic
Fixes
emails.receiving.forward()so forwarded emails keep their original raw bytes instead of corrupting non-UTF-8 content.response.text()decoded the downloaded message as UTF-8, so bytes that weren't valid UTF-8 became U+FFFD. In wrapped mode the.emlattachment no longer matched the original message; in passthrough modepostal-mimecouldn't apply the declared charset, so an ISO-8859-1 body forwarded ascaf�instead ofcafé.The download is now read with
arrayBuffer().postal-mimedecodes the exact bytes using the declared charset, and the wrapped attachment is the original bytes as base64. Adds tests for an ISO-8859-1 message in both modes and bumps the package version to6.32.1.Written for commit 58e2bdb. Summary will update on new commits.