Method: Net::IMAP#idle

Defined in:
lib/net/imap.rb

#idle(&response_handler) ⇒ Object

Sends an IDLE command that waits for notifications of new or expunged messages. Yields responses from the server during the IDLE.

Use #idle_done() to leave IDLE.

Raises:

  • (LocalJumpError)


910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
# File 'lib/net/imap.rb', line 910

def idle(&response_handler)
  raise LocalJumpError, "no block given" unless response_handler

  response = nil

  synchronize do
    tag = Thread.current[:net_imap_tag] = generate_tag
    put_string("#{tag} IDLE#{CRLF}")

    begin
      add_response_handler(response_handler)
      @idle_done_cond = new_cond
      @idle_done_cond.wait
      @idle_done_cond = nil
      if @receiver_thread_terminating
        raise Net::IMAP::Error, "connection closed"
      end
    ensure
      unless @receiver_thread_terminating
        remove_response_handler(response_handler)
        put_string("DONE#{CRLF}")
        response = get_tagged_response(tag, "IDLE")
      end
    end
  end

  return response
end