* lib/net/pop.rb: do not use class variables.
* lib/net/pop.rb (do_start): ensure to clean up connection when authentication failed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d4f7c8ccef
commit
6562d8732d
@ -1,3 +1,10 @@
|
|||||||
|
Wed Apr 21 18:01:47 2004 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
|
* lib/net/pop.rb: do not use class variables.
|
||||||
|
|
||||||
|
* lib/net/pop.rb (do_start): ensure to clean up connection when
|
||||||
|
authentication failed.
|
||||||
|
|
||||||
Wed Apr 21 17:23:59 2004 Minero Aoki <aamine@loveruby.net>
|
Wed Apr 21 17:23:59 2004 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
* lib/net/http.rb (HTTP#connect): CONNECT must precede SSL connect.
|
* lib/net/http.rb (HTTP#connect): CONNECT must precede SSL connect.
|
||||||
|
@ -224,10 +224,6 @@ module Net
|
|||||||
# Class Parameters
|
# Class Parameters
|
||||||
#
|
#
|
||||||
|
|
||||||
@@usessl = false
|
|
||||||
@@verify = nil
|
|
||||||
@@certs = nil
|
|
||||||
|
|
||||||
def POP3.default_port
|
def POP3.default_port
|
||||||
default_pop3_port()
|
default_pop3_port()
|
||||||
end
|
end
|
||||||
@ -340,6 +336,44 @@ module Net
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# SSL
|
||||||
|
#
|
||||||
|
|
||||||
|
@use_ssl = false
|
||||||
|
@verify = nil
|
||||||
|
@certs = nil
|
||||||
|
|
||||||
|
# Enable SSL for all new instances.
|
||||||
|
# +verify+ is the type of verification to do on the Server Cert; Defaults
|
||||||
|
# to OpenSSL::SSL::VERIFY_PEER.
|
||||||
|
# +certs+ is a file or directory holding CA certs to use to verify the
|
||||||
|
# server cert; Defaults to nil.
|
||||||
|
def POP3.enable_ssl(verify = OpenSSL::SSL::VERIFY_PEER, certs = nil)
|
||||||
|
@use_ssl = true
|
||||||
|
@verify = verify
|
||||||
|
@certs = certs
|
||||||
|
end
|
||||||
|
|
||||||
|
# Disable SSL for all new instances.
|
||||||
|
def POP3.disable_ssl
|
||||||
|
@use_ssl = nil
|
||||||
|
@verify = nil
|
||||||
|
@certs = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def POP3.use_ssl?
|
||||||
|
@use_ssl
|
||||||
|
end
|
||||||
|
|
||||||
|
def POP3.verify
|
||||||
|
@verify
|
||||||
|
end
|
||||||
|
|
||||||
|
def POP3.certs
|
||||||
|
@certs
|
||||||
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Session management
|
# Session management
|
||||||
#
|
#
|
||||||
@ -364,24 +398,6 @@ module Net
|
|||||||
isapop = false, &block) # :yield: pop
|
isapop = false, &block) # :yield: pop
|
||||||
new(address, port, isapop).start(account, password, &block)
|
new(address, port, isapop).start(account, password, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Enable SSL for all new instances.
|
|
||||||
# +verify+ is the type of verification to do on the Server Cert; Defaults
|
|
||||||
# to OpenSSL::SSL::VERIFY_PEER.
|
|
||||||
# +certs+ is a file or directory holding CA certs to use to verify the
|
|
||||||
# server cert; Defaults to nil.
|
|
||||||
def POP3.enable_ssl(verify = OpenSSL::SSL::VERIFY_PEER, certs = nil)
|
|
||||||
@@usessl = true
|
|
||||||
@@verify = verify
|
|
||||||
@@certs = certs
|
|
||||||
end
|
|
||||||
|
|
||||||
# Disable SSL for all new instances.
|
|
||||||
def POP3.disable_ssl
|
|
||||||
@@usessl = nil
|
|
||||||
@@verify = nil
|
|
||||||
@@certs = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
# Creates a new POP3 object.
|
# Creates a new POP3 object.
|
||||||
# +addr+ is the hostname or ip address of your POP3 server.
|
# +addr+ is the hostname or ip address of your POP3 server.
|
||||||
@ -391,11 +407,11 @@ module Net
|
|||||||
# This method does *not* open the TCP connection.
|
# This method does *not* open the TCP connection.
|
||||||
def initialize(addr, port = nil, isapop = false)
|
def initialize(addr, port = nil, isapop = false)
|
||||||
@address = addr
|
@address = addr
|
||||||
@usessl = @@usessl
|
@use_ssl = POP3.use_ssl?
|
||||||
@port = port || (@usessl ? POP3.default_pop3s_port : POP3.default_pop3_port)
|
@port = port || (POP3.use_ssl? ? POP3.default_pop3s_port : POP3.default_pop3_port)
|
||||||
@apop = isapop
|
@apop = isapop
|
||||||
@certs = @@certs
|
@certs = POP3.certs
|
||||||
@verify = @@verify
|
@verify = POP3.verify
|
||||||
|
|
||||||
@command = nil
|
@command = nil
|
||||||
@socket = nil
|
@socket = nil
|
||||||
@ -416,7 +432,7 @@ module Net
|
|||||||
|
|
||||||
# does this instance use SSL?
|
# does this instance use SSL?
|
||||||
def use_ssl?
|
def use_ssl?
|
||||||
@usessl
|
@use_ssl
|
||||||
end
|
end
|
||||||
|
|
||||||
# Enables SSL for this instance. Must be called before the connection is
|
# Enables SSL for this instance. Must be called before the connection is
|
||||||
@ -428,14 +444,14 @@ module Net
|
|||||||
# +port+ is port to establish the SSL connection on; Defaults to 995.
|
# +port+ is port to establish the SSL connection on; Defaults to 995.
|
||||||
def enable_ssl(verify = OpenSSL::SSL::VERIFY_PEER, certs = nil,
|
def enable_ssl(verify = OpenSSL::SSL::VERIFY_PEER, certs = nil,
|
||||||
port = POP3.default_pop3s_port)
|
port = POP3.default_pop3s_port)
|
||||||
@usessl = true
|
@use_ssl = true
|
||||||
@verify = verify
|
@verify = verify
|
||||||
@certs = certs
|
@certs = certs
|
||||||
@port = port
|
@port = port
|
||||||
end
|
end
|
||||||
|
|
||||||
def disable_ssl
|
def disable_ssl
|
||||||
@usessl = nil
|
@use_ssl = false
|
||||||
@verify = nil
|
@verify = nil
|
||||||
@certs = nil
|
@certs = nil
|
||||||
end
|
end
|
||||||
@ -513,26 +529,24 @@ module Net
|
|||||||
|
|
||||||
def do_start(account, password)
|
def do_start(account, password)
|
||||||
s = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
|
s = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
|
||||||
if @usessl
|
if use_ssl?
|
||||||
raise 'SSL extension not installed' unless defined?(OpenSSL)
|
raise 'openssl library not installed' unless defined?(OpenSSL)
|
||||||
sslctx = OpenSSL::SSL::SSLContext.new
|
context = OpenSSL::SSL::SSLContext.new
|
||||||
sslctx.verify_mode = @verify
|
context.verify_mode = @verify
|
||||||
if @certs
|
if @certs
|
||||||
if File.file?(@certs)
|
if File.file?(@certs)
|
||||||
sslctx.ca_file = @certs
|
context.ca_file = @certs
|
||||||
elsif File.directory?(@certs)
|
elsif File.directory?(@certs)
|
||||||
sslctx.ca_path = @certs
|
context.ca_path = @certs
|
||||||
else
|
else
|
||||||
raise ArgumentError, "certs path is not file/directory: #{@certs}"
|
raise ArgumentError, "certs path is not file/directory: #{@certs}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
s = OpenSSL::SSL::SSLSocket.new(s, sslctx)
|
s = OpenSSL::SSL::SSLSocket.new(s, context)
|
||||||
s.sync_close = true
|
s.sync_close = true
|
||||||
s.connect
|
s.connect
|
||||||
end
|
end
|
||||||
|
|
||||||
@socket = InternetMessageIO.new(s)
|
@socket = InternetMessageIO.new(s)
|
||||||
|
|
||||||
logging "POP session started: #{@address}:#{@port} (#{@apop ? 'APOP' : 'POP'})"
|
logging "POP session started: #{@address}:#{@port} (#{@apop ? 'APOP' : 'POP'})"
|
||||||
@socket.read_timeout = @read_timeout
|
@socket.read_timeout = @read_timeout
|
||||||
@socket.debug_output = @debug_output
|
@socket.debug_output = @debug_output
|
||||||
@ -545,8 +559,12 @@ module Net
|
|||||||
end
|
end
|
||||||
@started = true
|
@started = true
|
||||||
ensure
|
ensure
|
||||||
s.close if s and not s.closed?
|
# Authentication failed, clean up connection.
|
||||||
do_finish unless @started
|
unless @started
|
||||||
|
s.close if s and not s.closed?
|
||||||
|
@socket = nil
|
||||||
|
@command = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
private :do_start
|
private :do_start
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user