diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/net/imap.rb | 6 | ||||
-rw-r--r-- | test/net/imap/test_imap.rb | 8 |
3 files changed, 14 insertions, 6 deletions
@@ -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 |