1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/net/imap.rb: OpenSSL support.

* lib/net/imap.rb (setquota): unset quota if the second argument is nil.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2048 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shugo 2002-02-06 04:39:00 +00:00
parent cc2ab3aca6
commit 6bebc82c03
2 changed files with 63 additions and 14 deletions

View file

@ -1,3 +1,10 @@
Wed Feb 6 13:28:53 2002 Amos Gouaux <amos+ruby@utdallas.edu>
* lib/net/imap.rb: OpenSSL support.
* lib/net/imap.rb (setquota): unset quota if the second argument
is nil.
Wed Feb 6 02:10:30 2002 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp> Wed Feb 6 02:10:30 2002 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* io.c (fptr_finalize): ignore EBADF when f and f2 use same * io.c (fptr_finalize): ignore EBADF when f and f2 use same

View file

@ -684,10 +684,18 @@ Struct
require "socket" require "socket"
require "monitor" require "monitor"
require "digest/md5" require "digest/md5"
begin
require "openssl"
rescue LoadError
end
module Net module Net
class IMAP class IMAP
include MonitorMixin include MonitorMixin
if defined?(OpenSSL)
include OpenSSL
include SSL
end
attr_reader :greeting, :responses, :response_handlers attr_reader :greeting, :responses, :response_handlers
@ -716,7 +724,7 @@ module Net
end end
def disconnect def disconnect
@sock.shutdown @sock.shutdown unless @usessl
@receiver_thread.join @receiver_thread.join
@sock.close @sock.close
end end
@ -803,8 +811,13 @@ module Net
end end
end end
# setquota(mailbox, nil) will unset quota.
def setquota(mailbox, quota) def setquota(mailbox, quota)
data = '(STORAGE ' + quota.to_s + ')' if quota.nil?
data = '()'
else
data = '(STORAGE ' + quota.to_s + ')'
end
send_command("SETQUOTA", mailbox, RawData.new(data)) send_command("SETQUOTA", mailbox, RawData.new(data))
end end
@ -914,7 +927,7 @@ module Net
@@debug = false @@debug = false
@@authenticators = {} @@authenticators = {}
def initialize(host, port = PORT) def initialize(host, port = PORT, usessl = false, certs = nil, verify = false)
super() super()
@host = host @host = host
@port = port @port = port
@ -922,6 +935,23 @@ module Net
@tagno = 0 @tagno = 0
@parser = ResponseParser.new @parser = ResponseParser.new
@sock = TCPSocket.open(host, port) @sock = TCPSocket.open(host, port)
if usessl
unless defined?(OpenSSL)
raise "SSL extension not installed"
end
@usessl = true
@sock = SSLSocket.new(@sock)
# verify the server.
@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)
@sock.connect # start ssl session.
else
@usessl = false
end
@responses = Hash.new([].freeze) @responses = Hash.new([].freeze)
@tagged_responses = {} @tagged_responses = {}
@response_handlers = [] @response_handlers = []
@ -1975,24 +2005,36 @@ module Net
end end
def getquota_response def getquota_response
# If no quota set, get back # If quota never established, get back
# `NO Quota root does not exist'. # `NO Quota root does not exist'.
# If quota removed, get `()' after the
# folder spec with no mention of `STORAGE'.
token = match(T_ATOM) token = match(T_ATOM)
name = token.value.upcase name = token.value.upcase
match(T_SPACE) match(T_SPACE)
mailbox = astring mailbox = astring
match(T_SPACE) match(T_SPACE)
match(T_LPAR) match(T_LPAR)
match(T_ATOM) token = lookahead
match(T_SPACE) case token.symbol
token = match(T_NUMBER) when T_RPAR
usage = token.value shift_token
match(T_SPACE) data = MailboxQuota.new(mailbox, nil, nil)
token = match(T_NUMBER) return UntaggedResponse.new(name, data, @str)
quota = token.value when T_ATOM
match(T_RPAR) shift_token
data = MailboxQuota.new(mailbox, usage, quota) match(T_SPACE)
return UntaggedResponse.new(name, data, @str) token = match(T_NUMBER)
usage = token.value
match(T_SPACE)
token = match(T_NUMBER)
quota = token.value
match(T_RPAR)
data = MailboxQuota.new(mailbox, usage, quota)
return UntaggedResponse.new(name, data, @str)
else
parse_error("unexpected token %s", token.symbol)
end
end end
def getacl_response def getacl_response