def receive_responses
      while true
        begin
          resp = get_response
        rescue Exception
          @sock.close
          @client_thread.raise($!)
          break
        end
        break unless resp
        begin
          synchronize do
            case resp
            when TaggedResponse
              @tagged_responses[resp.tag] = resp
              @response_arrival.broadcast
              if resp.tag == @logout_command_tag
                return
              end
            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
              if resp.name == "BYE" && @logout_command_tag.nil?
                @sock.close
                raise ByeResponseError, resp.raw_data
              end
            when ContinuationRequest
              @continuation_request = resp
              @response_arrival.broadcast
            end
            @response_handlers.each do |handler|
              handler.call(resp)
            end
          end
        rescue Exception
          @client_thread.raise($!)
        end
      end
    end
def receive_responses
      while true
        begin
          resp = get_response
        rescue Exception
          @sock.close
          @client_thread.raise($!)
          break
        end
        break unless resp
        begin
          synchronize do
            case resp
            when TaggedResponse
              @tagged_responses[resp.tag] = resp
              @response_arrival.broadcast
              if resp.tag == @logout_command_tag
                return
              end
            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
              if resp.name == "BYE" && @logout_command_tag.nil?
                @sock.close
                raise ByeResponseError, resp.raw_data
              end
            when ContinuationRequest
              @continuation_request = resp
              @response_arrival.broadcast
            end
            @response_handlers.each do |handler|
              handler.call(resp)
            end
          end
        rescue Exception
          @client_thread.raise($!)
        end
      end
    end
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.