Skip to content

Add ContentTransferEncoding field to force CTE on a Part - #396

Merged
jhillyerd merged 3 commits into
mainfrom
cte-override
Aug 9, 2026
Merged

Add ContentTransferEncoding field to force CTE on a Part#396
jhillyerd merged 3 commits into
mainfrom
cte-override

Conversation

@jhillyerd

Copy link
Copy Markdown
Owner

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

@coveralls

coveralls commented Jun 6, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 86.563% (+0.1%) from 86.467% — cte-override into main

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>
@jhillyerd
jhillyerd marked this pull request as ready for review August 9, 2026 17:45
@jhillyerd
jhillyerd requested a lite review from Copilot August 9, 2026 17:45

Copilot AI 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.

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.ContentTransferEncoding plus a WithContentTransferEncoding(...) builder.
  • Updates encoding logic to apply a forced CTE and (when needed) switch away from the streaming base64 path by materializing ContentReader content.
  • 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.

Comment thread encode.go Outdated
Signed-off-by: James Hillyerd <james@hillyerd.com>
@jhillyerd
jhillyerd merged commit e3b0d6f into main Aug 9, 2026
12 checks passed
@jhillyerd
jhillyerd deleted the cte-override branch August 9, 2026 18:21
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.

Allow forcing Content-Transfer-Encoding when encoding a Part

3 participants