Repository navigation
fix(mailcompose): encode every Subject chunk so folding adds no space - #283
Merged
Merged
Conversation
encodedHeaderWords used mime.QEncoding.Encode, which returns pure-ASCII input unchanged. A Subject chunk without non-ASCII bytes became plain text next to an encoded-word, and RFC 2047 section 6.2 keeps the whitespace between them, so "renewal charged Nov 6" decoded as "renewal charge d Nov 6". Wrap every chunk in a Q encoded-word with output identical to mime.QEncoding for non-ASCII input, and fold Subject lines at the RFC 2047 section 2 limit of 76 bytes. ASCII-only subjects still use the plain header path and are unchanged. Refs itsjeremyjohnson/fleet#805 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Refs itsjeremyjohnson/fleet#805
Problem
A
mail_compose_sendSubject... renewal charged Nov 6arrived as... renewal charge d Nov 6.encodedHeaderWordssplit the Subject withmime.QEncoding.Encode. That function returns pure-ASCII input unchanged, so an ASCII chunk stayed plain text next to an encoded-word. RFC 2047 section 6.2 keeps whitespace between an encoded-word and plain text, so the joining space or fold showed up in the decoded Subject. A leading ASCII chunk gave a doubled space instead.Change
internal/mailcompose/mime.go: newqEncodedWordalways emits=?utf-8?q?...?=. Its output matchesmime.QEncodingbyte for byte for non-ASCII input. Every Subject chunk now goes through it, split on UTF-8 rune boundaries.writeStructuredHeadertakes the line limit as a parameter. To/Cc/Bcc and References keep 998.writeHeaderpath. Output is unchanged.From/To display names go through
net/mailAddress.String(), which emits only adjacent encoded-words. Attachment filenames use RFC 2231filename*=viamime.FormatMediaType. Both round-trip exactly, and the new tests cover them. Nothing else in the repo builds=?utf-8?headers.Testing
TestSubjectRoundTripsExactlyrenders throughrenderMIME, parses withnet/mailandmime.WordDecoder, and requires an exact decoded match. Cases: the incident subject, a trailing-ASCII case, a leading-ASCII case, a 177-byte mixed subject that folds onto 4 lines, and an ASCII-only subject whose raw line is pinned. Every Subject line must be at most 78 bytes and every encoded-word at most 75.TestDisplayNamesAndFilenameRoundTripExactlycovers long non-ASCII From/To names and a non-ASCII attachment filename.charge d,account – Nov,abcd efghij,for the Q4). With the fix, all pass.make ci(fmt-check, golangci-lint v2.13.2,go test ./...) passes on go1.26.0.🤖 Generated with Claude Code