new(host, port = PORT, usessl = false, certs = nil, verify = false)
public
Creates a new Net::IMAP object and connects it to the specified
port (143 by default) on the named host. If
usessl is true, then an attempt will be made to use SSL (now TLS)
to connect to the server. For this to work OpenSSL [OSSL] and the Ruby
OpenSSL [RSSL] extensions need to be installed. The certs
parameter indicates the path or file containing the CA cert of the server,
and the verify parameter is for the OpenSSL verification callback.
The most common errors are:
Errno::ECONNREFUSED |
connection refused by host or an intervening firewall.
|
Errno::ETIMEDOUT |
connection timed out (possibly due to packets being dropped by an
intervening firewall).
|
Errno::ENETUNREACH |
there is no route to that network.
|
SocketError |
hostname not known or other socket error.
|
Net::IMAP::ByeResponseError |
we connected to the host, but they immediately said goodbye to us.
|
Show source
def initialize(host, port = PORT, usessl = false, certs = nil, verify = false)
super()
@host = host
@port = port
@tag_prefix = "RUBY"
@tagno = 0
@parser = ResponseParser.new
@sock = TCPSocket.open(host, port)
if usessl
unless defined?(OpenSSL)
raise "SSL extension not installed"
end
@usessl = true
context = SSLContext::new()
context.ca_file = certs if certs && FileTest::file?(certs)
context.ca_path = certs if certs && FileTest::directory?(certs)
context.verify_mode = VERIFY_PEER if verify
if defined?(VerifyCallbackProc)
context.verify_callback = VerifyCallbackProc
end
@sock = SSLSocket.new(@sock, context)
@sock.sync_close = true
@sock.connect
@sock.post_connection_check(@host) if verify
else
@usessl = false
end
@responses = Hash.new([].freeze)
@tagged_responses = {}
@response_handlers = []
@response_arrival = new_cond
@continuation_request = nil
@logout_command_tag = nil
@debug_output_bol = true
@exception = nil
@greeting = get_response
if @greeting.name == "BYE"
@sock.close
raise ByeResponseError, @greeting.raw_data
end
@client_thread = Thread.current
@receiver_thread = Thread.start {
receive_responses
}
end