Add ContentTransferEncoding field to force CTE on a Part - #396
Merged
Conversation
Allows callers to override the automatic Content-Transfer-Encoding selection on a per-part basis. Valid values are "7bit", "8bit", "base64", and "quoted-printable". Empty or unrecognised values fall back to automatic detection. This is useful for ASCII-safe content like PGP armor (application/pgp-encrypted, application/pgp-signature) that would otherwise be unnecessarily base64-encoded. The forced CTE takes precedence over both the TextContent() gate and the Encoder.ForceQuotedPrintableCte option. Closes #395
Signed-off-by: James Hillyerd <james@hillyerd.com>
There was a problem hiding this comment.
Pull request overview
Adds a per-Part override for Content-Transfer-Encoding so callers can explicitly force "7bit", "8bit", "base64", or "quoted-printable" instead of relying on automatic detection—primarily to avoid unnecessary base64 encoding for ASCII-safe non-text payloads (e.g., PGP armor).
Changes:
- Introduces
Part.ContentTransferEncodingplus aWithContentTransferEncoding(...)builder. - Updates encoding logic to apply a forced CTE and (when needed) switch away from the streaming base64 path by materializing
ContentReadercontent. - Adds unit tests covering forced CTE behavior, fallback behavior, and precedence over encoder-level options.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| part.go | Adds the ContentTransferEncoding field, clones it, and provides a builder method. |
| encode.go | Applies the forced CTE during encoding and introduces resolveForcedCTE() mapping. |
| encode_test.go | Adds tests validating forced CTE behavior and precedence rules. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Signed-off-by: James Hillyerd <james@hillyerd.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.
Allows callers to override the automatic Content-Transfer-Encoding
selection on a per-part basis. Valid values are "7bit", "8bit",
"base64", and "quoted-printable". Empty or unrecognised values
fall back to automatic detection.
This is useful for ASCII-safe content like PGP armor
(application/pgp-encrypted, application/pgp-signature) that would
otherwise be unnecessarily base64-encoded.
The forced CTE takes precedence over both the TextContent() gate
and the Encoder.ForceQuotedPrintableCte option.
Closes #395