nu7hatch/gmail — pull request #93 by wstrinz (2013-10-04 15:24:06+00:00)
Title: add imap idle method to wait for new messages

I added a small feature that uses IMAP IDLE, which has a method supporting it in the standard library IMAP implementation. I've written it to return when a new message is received, so you can use it to avoid repeatedly polling your inbox. You should also be able to pass a block that gets executed on new messages, but I didn't have time to write a test for it so I'm not sure if that bit works.

There's also the issue of IDLE timing out after 30 min, the code I adapted this from wraps the whole `imap.idle` block in a loop and has a separate thread that closes and reopens the connection -

````
loop do
Thread.new do
puts "Starting timer"
sleep 29 * 60
imap.idle_done
end

imap.idle do |r|
# etc
end
end
````

but I'm not sure this is the best way to handle it, so I've left the timeout handling out here.