Revision 7bb2ac7f
Added by Marc Dequènes over 14 years ago
- ID 7bb2ac7f1d9ca7b827fed1e85b4f12d169f23947
lib/cyborghood/imap.rb | ||
---|---|---|
authenticate &&
|
||
listen_to_events &&
|
||
wait_and_read_mails(&message_handler)
|
||
rescue SocketError, Net::IMAP::NoResponseError => e
|
||
logger.warn "IMAP or Network error: " + e.message
|
||
rescue Net::IMAP::NoResponseError => e
|
||
logger.warn "IMAP error: " + e.message.strip
|
||
rescue Net::IMAP::Error => e
|
||
raise CyberError.new(:unrecoverable, "protocol/imap", e.message)
|
||
logger.error "IMAP error: " + e.message.strip
|
||
ensure
|
||
begin
|
||
disconnect
|
||
... | ... | |
def check_mails(&message_handler)
|
||
@stop_mail_check = false
|
||
until @stop_mail_check
|
||
t = Time.now.to_i
|
||
r = check_mails_once(&message_handler)
|
||
t2 = Time.now.to_i
|
||
begin
|
||
t = Time.now.to_i
|
||
r = check_mails_once(&message_handler)
|
||
t2 = Time.now.to_i
|
||
|
||
sleep_time = @min_check_interval - (t2 - t)
|
||
rescue SocketError, Errno::EPIPE, Errno::ECONNREFUSED, Errno::ETIMEDOUT, Errno::ENETUNREACH => e
|
||
logger.warn "Network error: " + e.message.strip
|
||
sleep_time = @min_check_interval
|
||
rescue
|
||
raise CyberError.new(:unrecoverable, "protocol/imap", e.message)
|
||
end
|
||
|
||
# wait before new check either if the IMAP server does not support IDLE mode
|
||
# or if an error occured
|
||
sleep_time = @min_check_interval - (t2 - t)
|
||
if sleep_time > 0 and not @stop_mail_check
|
||
logger.debug "Having a break before new check..."
|
||
t = Time.now.to_i
|
||
... | ... | |
def disconnect
|
||
return unless @imap
|
||
|
||
@imap.logout if @is_loggued
|
||
|
||
@imap.disconnect
|
||
logger.debug "Disconnected from IMAP server"
|
||
@imap = nil
|
||
@is_loggued = false
|
||
@imap_capab = nil
|
||
begin
|
||
@imap.logout if @is_loggued
|
||
|
||
logger.debug "Disconnecting from IMAP server..."
|
||
@imap.disconnect
|
||
logger.debug "Disconnected from IMAP server"
|
||
rescue IOError
|
||
logger.debug "Already diconnected from IMAP server"
|
||
ensure
|
||
@imap = nil
|
||
@is_loggued = false
|
||
@imap_capab = nil
|
||
end
|
||
end
|
||
end
|
||
end
|
Also available in: Unified diff
[evol/fix] IMAP: improved error handling and ensure to properly reconnect if appropriate