SMTP receiver rejects RFC 2047 Subject encoded as ISO-8859-2
SMTP publishing fails on RFC 2047 Subject encoded as ISO-8859-2
Description
ntfy's SMTP receiver rejects an otherwise valid e-mail when the Subject header uses RFC 2047 encoding with the ISO-8859-2 charset.
The SMTP server returns:
554 5.0.0 Error: transaction failed, blame it on the weather: mime: unhandled charset "ISO-8859-2"
This was encountered with a Brother MFC-L2710DW printer configured to send e-mail notifications directly to ntfy.
When the printer's local language is Polish, it generates a Subject using ISO-8859-2, and ntfy rejects the message. Changing the printer's local language to English makes the same SMTP test succeed.
Reproduction
- Configure ntfy's built-in SMTP receiver.
- Send an e-mail containing an RFC 2047 encoded Subject using
ISO-8859-2, for example a header of the form:
Subject: =?ISO-8859-2?Q?...?=
- ntfy rejects the SMTP DATA transaction with:
554 5.0.0 Error: transaction failed, blame it on the weather: mime: unhandled charset "ISO-8859-2"
Expected behavior
ntfy should decode valid MIME/RFC 2047 legacy character sets such as ISO-8859-2 to UTF-8 and publish the message.
At minimum, a charset used by ordinary legacy network appliances should not cause the entire SMTP transaction to fail.
Actual behavior
The message is rejected with SMTP status 554.
Suspected cause
In server/smtp_server.go, the Subject is currently decoded using:
dec := mime.WordDecoder{}
subject, err := dec.DecodeHeader(subject)
mime.WordDecoder requires a CharsetReader to decode character sets other than those supported natively by Go's mime package.
A possible fix would be to provide an appropriate charset reader and convert decoded header values to UTF-8.
It may also be worth checking text MIME body handling for the same issue, since the current SMTP parser appears to process transfer encoding but not the charset= parameter of text/plain / text/html parts.
Environment
- Self-hosted ntfy
- SMTP publishing enabled
- Sender: Brother MFC-L2710DW
- Printer language when failing: Polish
- Printer language when succeeding: English
- Failing charset:
ISO-8859-2
ntfy version: 2.28.0
Source: binwiederhier/ntfy