mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
3ee72c86ef
commit
e875cfa1fe
3 changed files with 14 additions and 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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue