Tcl Library Source Code

View Ticket
Login
2026-10-08
21:57 • New ticket [04b8e4fb3c] buildmessage/copymessage emit Content-Transfer-Encoding header twice. artifact: 6cd8021cd7 user: anonymous

Ticket UUID: 04b8e4fb3cc43f9b88065af15e789a83bf279957
Title: buildmessage/copymessage emit Content-Transfer-Encoding header twice
Type: Bug Version: 1.7.2
Submitter: anonymous Created on: 2026-10-08 21:57:27
Subsystem: mime Assigned To: nobody
Priority: 5 Medium Severity: Important
Status: Open Last Modified: 2026-10-08 21:57:27
Resolution: None Closed By: nobody
    Closed on:
Description:

For any canonical, non-multipart part, mime::buildmessage and mime::copymessage write the Content-Transfer-Encoding header twice:

package require mime
set m [mime::initialize -canonical {text/plain; charset="UTF-8"} -encoding 8bit -string hi]
mime::setheader $m Subject test
puts [mime::buildmessage $m]

Output:

MIME-Version: 1.0
Content-ID: <...>
Subject: test
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit

hi

This happens whether or not -encoding is given, because both code paths fall back to [mime::encoding $token]. RFC 2045 allows at most one Content-Transfer-Encoding field per part. AWS SES (SendEmail, Raw content) rejects these messages with a duplicate-header error.

Cause:

Check-in 7c25c9a457 ("Separate header determination from body generation", 2021-04-30) changed mime::getheader (called without a key) to add Content-Transfer-Encoding to its result through mime::getTransferEncoding. mime::copymessageaux prints every header returned by getheader, then still runs its older code that writes the header again:

if {$encoding ne {}} {
    puts $channel "Content-Transfer-Encoding: $encoding"
}

Suggested fix:

Remove that puts from mime::copymessageaux. Keep the switch after it, because it still has to set $converter for base64/quoted-printable bodies. Add a test asserting that [mime::buildmessage] output contains exactly one Content-Transfer-Encoding line for -encoding 8bit, base64 and quoted-printable, and when -encoding is omitted.