On Jul 3, 2009, at 01:16, Abhishiv Saxena wrote:

> 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?

NOTE: There's no need to post to the mailing list and the forum, they  
both come to the same place.

Try this:

require 'net/imap'

class Net::IMAP

   ##
   # Sends an IDLE command that waits for notifications of new or  
expunged
   # messages.  Yields responses from the server during the IDLE.
   #
   # Use +break+ in the response handler to leave IDLE.

   def idle(&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}"

       add_response_handler response_handler

       begin
         response = get_tagged_response tag
       rescue LocalJumpError # can't break cross-threads or something
       ensure
         unless response then
           put_string "DONE#{CRLF}"
           response = get_tagged_response tag
         end

         remove_response_handler response_handler
       end
     end

     response
   end

end