Skip to content

Fix: Parse address headers with non-UTF-8 display names - #763

Merged
axllent merged 1 commit into
axllent:developfrom
yamamoto7:fix/non-utf8-address-headers
Nov 2, 2026
Merged

axllent merged 1 commit into
axllent:developfrom
yamamoto7:fix/non-utf8-address-headers

Conversation

@yamamoto7

Copy link
Copy Markdown
Contributor

Summary

mail.Header.AddressList cannot decode display names in charsets such as ISO-2022-JP, Shift_JIS or windows-1252. Mailpit ignores that error in the SMTP Bcc check, so To and Cc recipients with those names look missing and are added to an injected Bcc header. Release returns an error for the same reason when the From name uses one of those charsets.

This adds tools.AddressList, which parses the header with enmime.ParseAddressList, and uses it in the SMTP Bcc check, release and ingest. Storage already uses enmime for these headers, so there is no new dependency.

enmime is more tolerant of malformed lists, for example a missing comma between addresses. These code paths now accept what storage already accepted.

Reproduced against develop (75d9473) and this branch with the same ISO-2022-JP message:

Check Before After
Bcc from the API [email protected] empty
Bcc: header in the raw message added none
Search bcc:[email protected] 1 result 0 results
Release 400 200
Before After
image image

Related issues

#762

Type of change

  • Bug fix
  • New feature
  • Refactor / code cleanup
  • Documentation
  • Other (please describe):

Test plan

  • Added TestScanAddressesInHeaderCharsets. It fails on develop for ISO-2022-JP, Shift_JIS, EUC-JP and windows-1252, and passes here.
  • Added TestAddressList.
  • Ran the go test packages from .github/workflows/tests.yml.
  • Sent messages from Python, Jakarta Mail and PHP mbstring in legacy charsets, plus UTF-8 messages from those and from Nodemailer and the Ruby mail gem. No false Bcc appeared.
  • Released a message with an ISO-2022-JP From name through the API to a second Mailpit.

AI assistance disclosure

Please indicate whether AI tools (e.g. Claude, Copilot, ChatGPT, Cursor) were used in preparing this pull request:

  • No AI was used
  • Assisted — AI was used for suggestions, explanations, or small snippets, but the code was primarily written and understood by me
  • Extensive — AI generated a significant portion of the code in this PR

If AI was used, briefly describe how (which tools, and for what parts):

Claude Code found the bug, wrote the fix and tests, ran the checks above, and drafted this description. I reproduced the bug and reviewed the change.

Checklist

  • I have tested my changes locally
  • I have read and understood all code being submitted (including any AI-generated portions)
  • Documentation has been updated where relevant

@axllent
axllent merged commit 22883eb into axllent:develop Nov 2, 2026
8 checks passed
@axllent

axllent commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Thank you

axllent added a commit that referenced this pull request Nov 2, 2026
The helper added in #763 used enmime.ParseAddressList, which decodes
encoded words inside the address itself and inserts missing commas.
This made it differ from net/mail: a local part such as
[email protected] became [email protected]@example.com,
and comma-less lists were split into extra recipients.

Parse with net/mail and only extend the charset reader used for display
names, so addresses are never decoded and malformed lists are rejected as
before. Also use the helper for sendmail -t recipients.
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