Support for IMAP IDLE in ruby
imap, ruby, ruby-on-rails
Solution
I came across this old question and wanted to solve it myself. The original asker has disappeared - oh well.
Here's how you get IMAP idle working on Ruby (this is super cool). This uses the quoted block in the original question, and the documentation here.
imap = Net::IMAP.new SERVER, :ssl => true
imap.login USERNAME, PW
imap.select 'INBOX'
imap.add_response_handler do |resp|
# modify this to do something more interesting.
# called every time a response arrives from the server.
if resp.kind_of?(Net::IMAP::UntaggedResponse) and resp.name == "EXISTS"
puts "Mailbox now has #{resp.data} messages"
end
end
imap.idle # necessary to tell the server to start forwarding requests.
Problem
Ok, I have been suck on it for hours. I thought net/imap.rb with ruby 1.9 supported the idle command, but not yet. Can anyone help me in implementing that? From here, I though this would work: ``` class Net::IMAP def idle cmd = "IDLE" synchronize do tag = generate_tag put_string(tag + " " + cmd) put_string(CRLF) end end def done cmd = "DONE" synchronize do put_string(cmd) put_string(CRLF) end end end ``` But imap.idle with that just return nil.