summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-22 08:00:04 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-22 08:00:04 +0000
commite875cfa1fedca6826c55b4d62f6860c933427cf7 (patch)
tree8ce88dd672ee81126794bb62b9d805fa10bb24d4
parent3ee72c86efef9d63f49c7513cf8b11c87be5b0eb (diff)
* lib/net/imap.rb (encode_utf7): accept UTF-8 strings.
* lib/net/imap.rb (decode_utf7): return UTF-8 strings. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14477 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--lib/net/imap.rb6
-rw-r--r--test/net/imap/test_imap.rb8
3 files changed, 14 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index a2de3085e6..9e9abe4c31 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sat Dec 22 16:58:49 2007 Shugo Maeda <shugo@ruby-lang.org>
+
+ * lib/net/imap.rb (encode_utf7): accept UTF-8 strings.
+
+ * lib/net/imap.rb (decode_utf7): return UTF-8 strings.
+
Sat Dec 22 15:56:36 2007 NAKAMURA Usaku <usa@ruby-lang.org>
* transcode_data_japanese: typo.
diff --git a/lib/net/imap.rb b/lib/net/imap.rb
index 540e366729..2398a5d10c 100644
--- a/lib/net/imap.rb
+++ b/lib/net/imap.rb
@@ -852,19 +852,19 @@ module Net
end
base64.unpack("m")[0].unpack("n*").pack("U*")
end
- }
+ }.force_encoding("UTF-8")
end
# Encode a string from UTF-8 format to modified UTF-7.
def self.encode_utf7(s)
- return s.gsub(/(&)|([^\x20-\x25\x27-\x7e]+)/n) { |x|
+ return s.gsub(/(&)|([^\x20-\x25\x27-\x7e]+)/u) { |x|
if $1
"&-"
else
base64 = [x.unpack("U*").pack("n*")].pack("m")
"&" + base64.delete("=\n").tr("/", ",") + "-"
end
- }
+ }.force_encoding("ASCII-8BIT")
end
private
diff --git a/test/net/imap/test_imap.rb b/test/net/imap/test_imap.rb
index aa4215224f..a984cbe4ed 100644
--- a/test/net/imap/test_imap.rb
+++ b/test/net/imap/test_imap.rb
@@ -3,12 +3,14 @@ require "test/unit"
class IMAPTest < Test::Unit::TestCase
def test_encode_utf7
- s = Net::IMAP.encode_utf7("\357\274\241\357\274\242\357\274\243")
- assert_equal("&,yH,Iv8j-", s)
+ utf8 = "\357\274\241\357\274\242\357\274\243".force_encoding("UTF-8")
+ s = Net::IMAP.encode_utf7(utf8)
+ assert_equal("&,yH,Iv8j-".force_encoding("UTF-8"), s)
end
def test_decode_utf7
s = Net::IMAP.decode_utf7("&,yH,Iv8j-")
- assert_equal("\357\274\241\357\274\242\357\274\243", s)
+ utf8 = "\357\274\241\357\274\242\357\274\243".force_encoding("UTF-8")
+ assert_equal(utf8, s)
end
end