Attachment "qp_encode.patch" to
ticket [763669ffff]
added by
gunzel
2003-07-01 11:16:03.
Index: modules/mime/mime.tcl
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/mime/mime.tcl,v
retrieving revision 1.33
diff -u -r1.33 mime.tcl
--- modules/mime/mime.tcl 25 Jun 2003 20:54:59 -0000 1.33
+++ modules/mime/mime.tcl 1 Jul 2003 03:57:34 -0000
@@ -2182,6 +2326,9 @@
# The properly quoted string is returned.
proc ::mime::qp_encode {string {encoded_word 0} {no_softbreak 0}} {
+
+ if {$encoded_word} {set no_softbreak 1}
+
# 8.1+ improved string manipulation routines used.
# Replace outlying characters, characters that would normally
# be munged by EBCDIC gateways, and special Tcl characters "[\]{}
@@ -2201,7 +2348,7 @@
"\n\.\n" "\n=2E\n" "\nFrom " "\n=46rom "]
if {$encoded_word} {
# Special processing for encoded words (RFC 2047)
- lappend mapChars " " "_"
+ lappend mapChars "_" "=5F" " " "_" "?" "=3F" "\t" "=09"
}
set string [string map $mapChars $string]
@@ -2232,18 +2379,20 @@
}
}
- # Trim off last \n, since the above code has the side-effect
- # of adding an extra \n to the encoded string and return the result.
-
- set result [string range $result 0 end-1]
-
- # If the string ends in space or tab, replace with =xx
-
- set lastChar [string index $result end]
- if {$lastChar==" "} {
- set result [string replace $result end end "=20"]
- } elseif {$lastChar=="\t"} {
- set result [string replace $result end end "=09"]
+ if {!$encoded_word && !$no_softbreak} {
+ # Trim off last \n, since the above code has the side-effect
+ # of adding an extra \n to the encoded string.
+
+ set result [string range $result 0 end-1]
+
+ # If the string ends in space or tab, replace with =xx
+
+ set lastChar [string index $result end]
+ if {$lastChar==" "} {
+ set result [string replace $result end end "=20"]
+ } elseif {$lastChar=="\t"} {
+ set result [string replace $result end end "=09"]
+ }
}
return $result
Index: modules/mime/mime.test
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/mime/mime.test,v
retrieving revision 1.9
diff -u -r1.9 mime.test
--- modules/mime/mime.test 25 Jun 2003 20:54:59 -0000 1.9
+++ modules/mime/mime.test 1 Jul 2003 03:57:34 -0000
@@ -196,9 +217,30 @@
mime::qp_encode $str1
} "Test de caract=E8res accentu=E9s : =E2 =EE =E9 =E7 et quelques contr=F4le=\ns =22=5B=7C=5D()=22"
-
-
-
+test mime-4.5 {Test qp_encode/decode in encoded_word mode} {
+ set enc [mime::qp_encode "jack and jill went up the hill" 1]
+ mime::qp_decode $enc 1
+} "jack and jill went up the hill"
+
+test mime-4.6 {Test qp_encode in encoded_word mode with equal signs} {
+ mime::qp_encode "1and1=2" 1
+} "1and1=3D2"
+
+test mime-4.7 {Test qp_encode in encoded_word mode with underscores} {
+ mime::qp_encode "2003_06_30" 1
+} "2003=5F06=5F30"
+
+test mime-4.8 {Test qp_encode in encoded_word mode with underscores and spaces} {
+ mime::qp_encode "2003_06_30 is 30 June 2003" 1
+} "2003=5F06=5F30_is_30_June_2003"
+
+test mime-4.9 {Test qp_encode in encoded_word mode with question marks} {
+ mime::qp_encode "How long is a piece of string ?" 1
+} "How_long_is_a_piece_of_string_=3F"
+
+test mime-4.10 {Test qp_encode in no_softbreak mode} {
+ mime::qp_encode "This is a very long string into which we do not want inserted softbreaks as we want one very long line returned even though that's probably not how we whould be doing it (see RFC2047) but we don't want to break backward compatibility" 0 1
+} "This is a very long string into which we do not want inserted softbreaks as we want one very long line returned even though that's probably not how we whould be doing it (see RFC2047) but we don't want to break backward compatibility"
test mime-5.1 {Test word_encode with quoted-printable method} {
mime::word_encode iso8859-1 quoted-printable "Test de contrôle effectué"