зеркало из https://github.com/github/ruby.git
* lib/net/imap.rb (send_string_data): wait command continuation
requests before sending octet data of literals. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6664 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
de804fe235
Коммит
b9db231cbd
|
@ -1,3 +1,8 @@
|
|||
Sat Jul 17 23:59:01 2004 Shugo Maeda <shugo@ruby-lang.org>
|
||||
|
||||
* lib/net/imap.rb (send_string_data): wait command continuation
|
||||
requests before sending octet data of literals.
|
||||
|
||||
Sat Jul 17 23:54:59 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
||||
|
||||
* ext/tk/lib/tk/variable.rb: TkVariable#ref returns a TkVariable object
|
||||
|
|
134
lib/net/imap.rb
134
lib/net/imap.rb
|
@ -352,7 +352,9 @@ module Net
|
|||
send_command("AUTHENTICATE", auth_type) do |resp|
|
||||
if resp.instance_of?(ContinuationRequest)
|
||||
data = authenticator.process(resp.data.text.unpack("m")[0])
|
||||
send_data([data].pack("m").gsub(/\n/, ""))
|
||||
s = [data].pack("m").gsub(/\n/, "")
|
||||
send_string_data(s)
|
||||
put_string(CRLF)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -884,8 +886,9 @@ module Net
|
|||
@sock.ca_file = certs if certs && FileTest::file?(certs)
|
||||
@sock.ca_path = certs if certs && FileTest::directory?(certs)
|
||||
@sock.verify_mode = VERIFY_PEER if verify
|
||||
@sock.verify_callback = VerifyCallbackProc if defined?(VerifyCallbackProc)
|
||||
|
||||
if defined?(VerifyCallbackProc)
|
||||
@sock.verify_callback = VerifyCallbackProc
|
||||
end
|
||||
@sock.connect # start ssl session.
|
||||
else
|
||||
@usessl = false
|
||||
|
@ -893,7 +896,9 @@ module Net
|
|||
@responses = Hash.new([].freeze)
|
||||
@tagged_responses = {}
|
||||
@response_handlers = []
|
||||
@tag_arrival = new_cond
|
||||
@tagged_response_arrival = new_cond
|
||||
@continuation_request_arrival = new_cond
|
||||
@debug_output_bol = true
|
||||
|
||||
@greeting = get_response
|
||||
if /\ABYE\z/ni =~ @greeting.name
|
||||
|
@ -922,13 +927,15 @@ module Net
|
|||
case resp
|
||||
when TaggedResponse
|
||||
@tagged_responses[resp.tag] = resp
|
||||
@tag_arrival.broadcast
|
||||
@tagged_response_arrival.broadcast
|
||||
when UntaggedResponse
|
||||
record_response(resp.name, resp.data)
|
||||
if resp.data.instance_of?(ResponseText) &&
|
||||
(code = resp.data.code)
|
||||
record_response(code.name, code.data)
|
||||
end
|
||||
when ContinuationRequest
|
||||
@continuation_request_arrival.signal
|
||||
end
|
||||
@response_handlers.each do |handler|
|
||||
handler.call(resp)
|
||||
|
@ -942,7 +949,7 @@ module Net
|
|||
|
||||
def get_tagged_response(tag, cmd)
|
||||
until @tagged_responses.key?(tag)
|
||||
@tag_arrival.wait
|
||||
@tagged_response_arrival.wait
|
||||
end
|
||||
resp = @tagged_responses.delete(tag)
|
||||
case resp.name
|
||||
|
@ -985,12 +992,12 @@ module Net
|
|||
def send_command(cmd, *args, &block)
|
||||
synchronize do
|
||||
tag = generate_tag
|
||||
data = args.collect {|i| format_data(i)}.join(" ")
|
||||
if data.length > 0
|
||||
put_line(tag + " " + cmd + " " + data)
|
||||
else
|
||||
put_line(tag + " " + cmd)
|
||||
put_string(tag + " " + cmd)
|
||||
args.each do |i|
|
||||
put_string(" ")
|
||||
send_data(i)
|
||||
end
|
||||
put_string(CRLF)
|
||||
if block
|
||||
add_response_handler(block)
|
||||
end
|
||||
|
@ -1009,77 +1016,98 @@ module Net
|
|||
return format("%s%04d", @tag_prefix, @tagno)
|
||||
end
|
||||
|
||||
def send_data(*args)
|
||||
data = args.collect {|i| format_data(i)}.join(" ")
|
||||
put_line(data)
|
||||
end
|
||||
|
||||
def put_line(line)
|
||||
line = line + CRLF
|
||||
@sock.print(line)
|
||||
def put_string(str)
|
||||
@sock.print(str)
|
||||
if @@debug
|
||||
$stderr.print(line.gsub(/^/n, "C: "))
|
||||
if @debug_output_bol
|
||||
$stderr.print("C: ")
|
||||
end
|
||||
$stderr.print(str.gsub(/\n(?!\z)/n, "\nC: "))
|
||||
if /\r\n\z/n.match(str)
|
||||
@debug_output_bol = true
|
||||
else
|
||||
@debug_output_bol = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def format_data(data)
|
||||
def send_data(data)
|
||||
case data
|
||||
when nil
|
||||
return "NIL"
|
||||
put_string("NIL")
|
||||
when String
|
||||
return format_string(data)
|
||||
send_string_data(data)
|
||||
when Integer
|
||||
return format_number(data)
|
||||
send_number_data(data)
|
||||
when Array
|
||||
return format_list(data)
|
||||
send_list_data(data)
|
||||
when Time
|
||||
return format_time(data)
|
||||
send_time_data(data)
|
||||
when Symbol
|
||||
return format_symbol(data)
|
||||
send_symbol_data(data)
|
||||
else
|
||||
return data.format_data
|
||||
data.send_data(self)
|
||||
end
|
||||
end
|
||||
|
||||
def format_string(str)
|
||||
def send_string_data(str)
|
||||
case str
|
||||
when ""
|
||||
return '""'
|
||||
put_string('""')
|
||||
when /[\x80-\xff\r\n]/n
|
||||
# literal
|
||||
return "{" + str.length.to_s + "}" + CRLF + str
|
||||
send_literal(str)
|
||||
when /[(){ \x00-\x1f\x7f%*"\\]/n
|
||||
# quoted string
|
||||
return '"' + str.gsub(/["\\]/n, "\\\\\\&") + '"'
|
||||
send_quoted_string(str)
|
||||
else
|
||||
# atom
|
||||
return str
|
||||
put_string(str)
|
||||
end
|
||||
end
|
||||
|
||||
def format_number(num)
|
||||
def send_quoted_string(str)
|
||||
put_string('"' + str.gsub(/["\\]/n, "\\\\\\&") + '"')
|
||||
end
|
||||
|
||||
def send_literal(str)
|
||||
put_string("{" + str.length.to_s + "}" + CRLF)
|
||||
@continuation_request_arrival.wait
|
||||
put_string(str)
|
||||
end
|
||||
|
||||
def send_number_data(num)
|
||||
if num < 0 || num >= 4294967296
|
||||
raise DataFormatError, num.to_s
|
||||
end
|
||||
return num.to_s
|
||||
put_string(num.to_s)
|
||||
end
|
||||
|
||||
def format_list(list)
|
||||
contents = list.collect {|i| format_data(i)}.join(" ")
|
||||
return "(" + contents + ")"
|
||||
def send_list_data(list)
|
||||
put_string("(")
|
||||
first = true
|
||||
list.each do |i|
|
||||
if first
|
||||
first = false
|
||||
else
|
||||
put_string(" ")
|
||||
end
|
||||
send_data(i)
|
||||
end
|
||||
put_string(")")
|
||||
end
|
||||
|
||||
DATE_MONTH = %w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
|
||||
|
||||
def format_time(time)
|
||||
def send_time_data(time)
|
||||
t = time.dup.gmtime
|
||||
return format('"%2d-%3s-%4d %02d:%02d:%02d +0000"',
|
||||
s = format('"%2d-%3s-%4d %02d:%02d:%02d +0000"',
|
||||
t.day, DATE_MONTH[t.month - 1], t.year,
|
||||
t.hour, t.min, t.sec)
|
||||
put_string(s)
|
||||
end
|
||||
|
||||
def format_symbol(symbol)
|
||||
return "\\" + symbol.to_s
|
||||
def send_symbol_data(symbol)
|
||||
put_string("\\" + symbol.to_s)
|
||||
end
|
||||
|
||||
def search_internal(cmd, keys, charset)
|
||||
|
@ -1279,8 +1307,8 @@ module Net
|
|||
private_class_method :u8tou16
|
||||
|
||||
class RawData # :nodoc:
|
||||
def format_data
|
||||
return @data
|
||||
def send_data(imap)
|
||||
imap.send(:put_string, @data)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -1291,8 +1319,8 @@ module Net
|
|||
end
|
||||
|
||||
class Atom # :nodoc:
|
||||
def format_data
|
||||
return @data
|
||||
def send_data(imap)
|
||||
imap.send(:put_string, @data)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -1303,8 +1331,8 @@ module Net
|
|||
end
|
||||
|
||||
class QuotedString # :nodoc:
|
||||
def format_data
|
||||
return '"' + @data.gsub(/["\\]/n, "\\\\\\&") + '"'
|
||||
def send_data(imap)
|
||||
imap.send(:send_quoted_string, @data)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -1315,8 +1343,8 @@ module Net
|
|||
end
|
||||
|
||||
class Literal # :nodoc:
|
||||
def format_data
|
||||
return "{" + @data.length.to_s + "}" + CRLF + @data
|
||||
def send_data(imap)
|
||||
imap.send(:send_literal, @data)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -1327,8 +1355,8 @@ module Net
|
|||
end
|
||||
|
||||
class MessageSet # :nodoc:
|
||||
def format_data
|
||||
return format_internal(@data)
|
||||
def send_data(imap)
|
||||
imap.send(:put_string, format_internal(@data))
|
||||
end
|
||||
|
||||
private
|
||||
|
|
Загрузка…
Ссылка в новой задаче