Skip to content

fix: use 8bit Content-Transfer-Encoding for non-ASCII text bodies#477

Closed
yeager wants to merge 1 commit intoopenclaw:mainfrom
yeager:fix-utf8-attachment-encoding
Closed

fix: use 8bit Content-Transfer-Encoding for non-ASCII text bodies#477
yeager wants to merge 1 commit intoopenclaw:mainfrom
yeager:fix-utf8-attachment-encoding

Conversation

@yeager
Copy link
Copy Markdown

@yeager yeager commented Mar 25, 2026

Problem

When sending emails with non-ASCII body text (e.g. Swedish, German) AND attachments, the MIME Content-Transfer-Encoding header was set to 7bit for text parts. Per RFC 2045 §2.7, 7bit encoding must not contain octets with the high bit set.

This caused some mail servers/clients to either mangle the message body or strip attachments from multipart/mixed messages.

Fix

Introduce transferEncodingForText() helper that:

  • Returns "7bit" for pure ASCII text (no change for English-only emails)
  • Returns "8bit" for text containing non-ASCII bytes (UTF-8)

Applied to all text body emission paths:

  • Standalone text/plain and text/html
  • Parts within multipart/alternative
  • Inline text parts within multipart/mixed (emails with attachments)

Testing

All existing tests pass. The change is backwards-compatible — ASCII-only emails continue to use 7bit.

When the message body contains non-ASCII characters (e.g. UTF-8 text
in Swedish, German, etc.), the MIME Content-Transfer-Encoding was
incorrectly set to '7bit'. Per RFC 2045 §2.7, 7bit encoding must not
contain octets with the high bit set.

This could cause mail servers to mangle the message body or, in some
cases, strip attachments from multipart/mixed messages.

Fix: introduce transferEncodingForText() that returns '8bit' when the
text contains non-ASCII bytes, and '7bit' otherwise. Applied to all
text body parts: standalone, multipart/alternative, and inline parts
within multipart/mixed (with attachments).
@steipete
Copy link
Copy Markdown
Collaborator

Thanks! Landed manually on main as 3d63ebc with regression coverage and a CHANGELOG thank-you. I kept plain text quoted-printable, and fixed the non-ASCII HTML path so it no longer declares 7bit. Closing this PR since the fix is now on main.

@steipete steipete closed this Apr 20, 2026
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.

2 participants