Idler receive email only for first time #7

nazarhussain opened this Issue Nov 19, 2012 · 2 comments

2 participants



I want to write IMAP script which reads the emails from gmail IMAP as they arrived. I wrote the script give below. It works perfectly fine. But the issue is It will only read email for first time. I run the script and then send an email to and it appears on the console but it will never work for next email.

I tried to remove the line idler.stop but this will also block the fetch callback. Please look at the code and guide me the issue in it. do
  client =['host'], config['port'], true)
  client.connect.bind! do
    client.login(', 'my_password')
  end.bind! do"INBOX")
  end.bind! do
    idler = client.idle
    puts idler.inspect
    idler.listen do |response|
      if ( == "EXISTS" rescue nil)
        puts "Ooh, new emails!"
        client.fetch( do |email|
          puts email.inspect
    end.errback do |e|
      puts "Idler recieved an error: #{e}"
  Signal.trap("INT") { client.disconnect; EM.stop }
  Signal.trap("TERM") { client.disconnect; EM.stop }

I've made a new API for IDLE: Hopefully it's easier to use! You can also use wait_for_one_email if you only want one.


Thanks. It really will help a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment