class Net::IMAP
def idle(timeout = nil, &response_handler)
The server's capabilities must include +IDLE+
===== Capabilities
Related: #idle_done, #noop, #check
end
end
...
imap.idle(60) do |res|
loop do
checks the connection for each 60 seconds.
+timeout+ can be used for keep-alive. For example, the following code
If +timeout+ is given, this method returns after +timeout+ seconds passed.
Use #idle_done to leave IDLE.
responses from the server during the IDLE.
that waits for notifications of new or expunged messages. Yields
{[IMAP4rev2 §6.3.13]}[https://www.rfc-editor.org/rfc/rfc9051#section-6.3.13]
Sends an {IDLE command [RFC2177 §3]}[https://www.rfc-editor.org/rfc/rfc6851#section-3]
def idle(timeout = nil, &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(timeout) @idle_done_cond = nil if @receiver_thread_terminating raise @exception || Net::IMAP::Error.new("connection closed") end ensure unless @receiver_thread_terminating remove_response_handler(response_handler) put_string("DONE#{CRLF}") response = get_tagged_response(tag, "IDLE", @idle_response_timeout) end end end return response end