-
Notifications
You must be signed in to change notification settings - Fork 31
Open
Description
Hi,
require 'em-imap'
EM.run do
client = EM::IMAP.new("imap.gmail.com",993,true)
client.connect.bind! do
client.login("[email protected]","some_gmail_password")
end.bind! do
client.select("INBOX")
end.bind! do
idler = client.idle
idler.listen do |response|
if (response == "stop" rescue nil)
puts "Stop"
idler.stop
idler.callback do
puts "Stop: Callback"
end
elsif (response == "start" rescue nil)
puts "Still Listening"
elsif (response.name == "EXISTS" rescue nil)
puts "Ooh, new emails!"
idler.stop
idler.callback do
# ... process new emails
end
end
end.errback do |e|
puts "Idler recieved an error: #{e}"
end
EM.add_periodic_timer(2) do
idler.receive_event "start"
end
EM.add_timer(6) do
idler.receive_event "stop"
end
end
endOutput:
Still Listening
Still Listening
Stop
Still Listening
Stop: Callback
Still Listening
Still Listening
Still Listening
Still Listening
...
...
...
Listener is active even after stopped, is this normal behavior ?
Thanks
Metadata
Metadata
Assignees
Labels
No labels