Sha256: d85a8415033a9b8b0dca9b453302020028267b6391e9ec091764a1e749abd915

Contents?: true

Size: 871 Bytes

Versions: 1

Compression:

Stored size: 871 Bytes

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
imap_processor-1.2 lib/net/imap/idle.rb