Skip to content

fix: convert non-UTF-8 email body charset to UTF-8#324

Merged
butschster merged 1 commit intomasterfrom
fix/smtp-charset-conversion
Mar 31, 2026
Merged

fix: convert non-UTF-8 email body charset to UTF-8#324
butschster merged 1 commit intomasterfrom
fix/smtp-charset-conversion

Conversation

@butschster
Copy link
Copy Markdown
Member

What

Adds charset-to-UTF-8 conversion for SMTP email bodies. Non-UTF-8 charsets (e.g. windows-1250, iso-8859-2) are now transcoded before storage.

Why

Emails with non-UTF-8 Content-Type charset (common for Czech, German, and other languages) were displayed as garbled text (��) in both the HTML preview and raw text tabs.

How

  • Added convertToUTF8() function using golang.org/x/text/encoding/ianaindex to transcode body bytes based on the charset parameter from Content-Type
  • Applied in both single-part and multipart email body processing paths
  • UTF-8, US-ASCII, and empty charset pass through unchanged
  • Unknown charsets fall back gracefully (data returned as-is)

Testing

  • TestConvertToUTF8 — 5 cases: utf-8 passthrough, empty charset, windows-1250 Czech, iso-8859-1 Latin, unknown charset
  • TestParseEmail_CharsetConversion — 3 integration cases: single-part text, single-part html, multipart with charset
  • go test ./modules/smtp/ — all pass

Email bodies arriving in charsets like windows-1250, iso-8859-2, etc.
were stored as raw bytes and displayed as garbled text (�). Added
convertToUTF8() using golang.org/x/text to transcode body content
based on the charset parameter from Content-Type headers.
@butschster butschster added the bug Something isn't working label Mar 31, 2026
@butschster butschster linked an issue Mar 31, 2026 that may be closed by this pull request
@butschster butschster self-assigned this Mar 31, 2026
@butschster butschster moved this to Done in Buggregator Mar 31, 2026
@butschster butschster merged commit dece0fe into master Mar 31, 2026
1 check passed
@butschster butschster deleted the fix/smtp-charset-conversion branch March 31, 2026 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working module [Smtp]

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

SMTP - emojis not showing in PreviewHTML

1 participant