# Net/imap idle

**URL:** <https://www.ruby-forum.com/t/net-imap-idle/93327>\
**Category:** Ruby\
**Created:** [January 5, 2006, 8:51pm UTC](https://www.ruby-forum.com/t/net-imap-idle/93327 "2006-01-05T20:51:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Payton\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/74df32/32.png) [@Payton\_S](https://www.ruby-forum.com/u/Payton_S)\
**Post date:** [January 5, 2006, 8:51pm UTC](https://www.ruby-forum.com/t/net-imap-idle/93327/1 "2006-01-05T20:51:37Z")

</div>

Perhaps there’s another way to do this without polling, but I added the  
IMAP IDLE (and associated DONE) command to Shugo M.'s excellent  
net/imap API.

For those unaware, RFC 2177 adds the IDLE command to the IMAP  
specification which allows the server to notify clients when a mailbox  
has changed state (particularly when new mail has arrived).

When issued, an IDLE command requires a DONE to complete it, which  
should be issued at least every 29 minutes, to prevent a timeout.

Anyway, here’s the (tiny) piece of code I wrote to implement this; I  
hope it’s useful. Feel free to tell me what I did wrong.

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

-Payton
