Can someone explain to me how IMAP IDLE works? Does it fork a new process for each connection that it opens? Can I somehow use eventmachine with it?
I am trying to implement it in ruby on heroku with background workers. Any thoughts?
Can someone explain to me how IMAP IDLE works? Does it fork a new process for each connection that it opens? Can I somehow use eventmachine with it?
I am trying to implement it in ruby on heroku with background workers. Any thoughts?
In Ruby 2.0 and up, there's an idle method that accepts a code block that will be called every time you get an untagged response. Once you got this response, you need to break out and pull the emails that came in. The idle call is also blocking, so you need to do this in a thread if you want to keep it asynchronous.
Here's a sample (@mailbox is an instance of Net::IMAP in this case):
IMAP IDLE is a feature that mail server implementations can support which allows real-time notifications. [Wikipedia]
[RFC 2177 - IMAP4 IDLE command]