Posted to tcl by jnc at Mon Oct 17 15:26:32 GMT 2011view raw
- 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"]
-
- # Protect the backslash for later subst and
- # smash soft newlines, has to occur after white-space smash
- # and any encoded word modification.
-
- set string [string map [list "\\" "\\\\" "=\n" ""] $string]
-
- # Decode specials
-
- regsub -all -nocase {=([a-f0-9][a-f0-9])} $string {\\u00\1} string
-
- # process \u unicode mapped chars
-
- return [subst -novar -nocommand $string]
- }