Project

General

Profile

« Previous | Next » 

Revision 63ff4d33

Added by Marc Dequènes over 10 years ago

[fix] rework the IMAP wait and read logic

View differences:

lib/cyborghood/imap.rb
end
def wait_and_read_mails(&message_handler)
until @stop_mail_check
begin
check_inbox(&message_handler)
# don't loop forever
return if @stop_mail_check
return if @config.debug.flags.include?('nomaildeletion')
end while waiting_mails?
if self.capabilities.include?("IDLE")
logger.debug "Waiting for new mails in idle mode"
until @stop_mail_check
return if @imap.nil? or not connected?
@imap.idle do |ev|
return if ev.kind_of? Net::IMAP::ContinuationRequest
return if ev.name == "OK"
@imap.idle_done
end
# restart IDLE after 5 min
t = Time.now.to_i
sleep(1) until Time.now.to_i - t >= 300 or @stop_mail_check or waiting_mails?
check_inbox(&message_handler)
if self.capabilities.include?("IDLE")
logger.debug "Waiting for new mails in idle mode"
until @stop_mail_check
return if @imap.nil? or not connected?
@imap.idle do |ev|
return if ev.kind_of? Net::IMAP::ContinuationRequest
return if ev.name == "OK"
@imap.idle_done
end
check_inbox(&message_handler)
end
end
end

Also available in: Unified diff