]> git.notmuchmail.org Git - sup/commitdiff
wrapped all imap errors so that they turn into source errors
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sat, 30 Dec 2006 15:21:29 +0000 (15:21 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sat, 30 Dec 2006 15:21:29 +0000 (15:21 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@123 5c8cc53c-5e98-4d25-b20a-d8db53a31250

lib/sup/imap.rb

index a0a7267a68f885a2608930cd09887d32ad6a463f..ac3082a4927d46c8fd45c5967cd0c8391c532ef1 100644 (file)
@@ -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