Tcl Library Source Code

View Ticket
Login
Ticket UUID: d3f66f9a756f54569caf57bbb2cade1f3d25ad06
Title: mime::field_decode remove spaces in specific situations
Type: Bug Version: 1.20
Submitter: anonymous Created on: 2025-05-19 09:28:02
Subsystem: mime Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Open Last Modified: 2025-05-19 09:28:02
Resolution: None Closed By: nobody
    Closed on:
Description:
Example from a newsletter:

Subject: =?UTF-8?Q?Neuer_SPD-Generalsekret=C3=A4r_?=
 =?UTF-8?Q?Kl=C3=BCssendorf_warnt_Union_vor_?=
 =?UTF-8?Q?Konflikt_bei_Migration?=

puts [::mime::field_decode [::mime::getheader $mime_data "Subject"]]
results in

"Neuer SPD-GeneralsekretärKlüssendorf warnt Union vorKonflikt bei Migration"

it should be
"Neuer SPD-Generalsekretär Klüssendorf warnt Union vor Konflikt bei Migration"

Note that the whitespace is part of the encoded word.
A quick-fix for me (may break some other case) was to switch order while decoding:

@@ -2537,18 +2537,18 @@
 proc ::mime::qp_decode {string {encoded_word 0}} {
     # 8.1+ improved string manipulation routines used.
     # Special processing for encoded words (RFC 2047)
-
-    if {$encoded_word} {
-        # _ == \x20, even if SPACE occupies a different code position
-        set string [string map [list _ \u0020] $string]
-    }
-
+
     # smash the white-space at the ends of lines since that must've been
     # generated by an MUA.

     regsub -all -- {[ \t]+\n} $string \n string
     set string [string trimright $string " \t"]

+    if {$encoded_word} {
+        # _ == \x20, even if SPACE occupies a different code position
+        set string [string map [list _ \u0020] $string]
+    }
+
     # Protect the backslash for later subst and
     # smash soft newlines, has to occur after white-space smash
     # and any encoded word modification.