From 451d7111c21d7d35fea451dc3aa08d70bf543b15 Mon Sep 17 00:00:00 2001 From: wmorgan Date: Sat, 30 Dec 2006 15:21:29 +0000 Subject: [PATCH] wrapped all imap errors so that they turn into source errors git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@123 5c8cc53c-5e98-4d25-b20a-d8db53a31250 --- lib/sup/imap.rb | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/sup/imap.rb b/lib/sup/imap.rb index a0a7267..ac3082a 100644 --- a/lib/sup/imap.rb +++ b/lib/sup/imap.rb @@ -50,8 +50,8 @@ class IMAP < Source @imap.examine mailbox Redwood::log "successfully connected to #{@parsed_uri}, mailbox #{mailbox}" @uid_validity ||= @imap.responses["UIDVALIDITY"][-1] - raise SourceError, "Your shitty IMAP server has kindly invalidated all 'unique' ids for the folder '#{mailbox}'. You will have to rescan this folder manually." if @imap.responses["UIDVALIDITY"][-1] != @uid_validity - rescue Exception => e + raise SourceError, "Your shitty IMAP server has taken advantage of the shitty IMAP spec and invalidated all supposedly 'unique' ids for the folder '#{mailbox}'. You will have to rescan this folder manually by running sup-import --rebuild #{self}" if @imap.responses["UIDVALIDITY"][-1] != @uid_validity + rescue Net::IMAP::Error, SourceError => e self.broken_msg = e.message.chomp # fucking chomp! fuck!!! @imap = nil Redwood::log "error connecting to IMAP server: #{self.broken_msg}" @@ -87,7 +87,12 @@ class IMAP < Source end def get_imap_field uid, field - f = @imap.uid_fetch uid, field + f = + begin + @imap.uid_fetch uid, field + rescue Net::IMAP::Error => e + raise SourceError, e.message + end raise SourceError, "null IMAP field '#{field}' for message with uid #{uid}" if f.nil? f[0].attr[field] end @@ -95,7 +100,13 @@ class IMAP < Source def each connect or raise SourceError, broken_msg - uids = @imap.uid_search ['UID', "#{cur_offset}:#{end_offset}"] + uids = + begin + @imap.uid_search ['UID', "#{cur_offset}:#{end_offset}"] + rescue Net::IMAP::Error => e + raise SourceError, e.message + end + uids.each do |uid| @last_uid = uid @dirty = true @@ -107,7 +118,11 @@ class IMAP < Source def start_offset; 1; end def end_offset connect or return start_offset - @imap.uid_search(['ALL']).last + begin + @imap.uid_search(['ALL']).last + rescue Net::IMAP::Error => e + raise SourceError, e.message + end end end -- 2.45.2