]> git.cworth.org Git - sup/commitdiff
tweaked broken source handling
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sun, 10 Dec 2006 19:56:57 +0000 (19:56 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sun, 10 Dec 2006 19:56:57 +0000 (19:56 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@74 5c8cc53c-5e98-4d25-b20a-d8db53a31250

bin/sup-import
lib/sup/imap.rb
lib/sup/mbox/loader.rb
lib/sup/source.rb

index 6bbab93e652115beff09fa70e16fdfca75a2b319..391be89810764b3ff5d3e90dda2267500f4b7cdd 100644 (file)
@@ -117,6 +117,10 @@ found = {}
 start = Time.now
 begin
   sources.each do |source|
+    if source.broken?
+      puts "error loading messages from #{source}: #{source.broken_msg}"
+      next
+    end
     next if source.done?
     puts "loading from #{source}... "
     num = 0
index 86dc236ac37735b62b0358de430684c534f195cc..148b67f5f7673791b623210f23a50dec2d09f648 100644 (file)
@@ -48,9 +48,9 @@ class IMAP < Source
         @imap.examine mailbox
         Redwood::log "successfully connected to #{@parsed_uri}, mailbox #{mailbox}"
       rescue Exception => e
-        self.broken = e.message.chomp # fucking chomp! fuck!!!
+        self.broken_msg = e.message.chomp # fucking chomp! fuck!!!
         @imap = nil
-        Redwood::log "error connecting to IMAP server: #{self.broken}"
+        Redwood::log "error connecting to IMAP server: #{self.broken_msg}"
       end
     end.join
 
@@ -71,8 +71,9 @@ class IMAP < Source
 
   ## load the full header text
   def raw_header uid
+    connect or return broken_msg
     begin
-      connect or return broken
+      connect or return broken_msg
     rescue Exception => e
       raise "wtf: #{e.inspect}"
     end
@@ -80,12 +81,12 @@ class IMAP < Source
   end
 
   def raw_full_message uid
-    connect or return broken
+    connect or return broken_msg
     @imap.uid_fetch(uid, 'RFC822')[0].attr['RFC822'].gsub(/\r\n/, "\n")
   end
   
   def each
-    connect or return broken
+    connect or return broken_msg
     uids = @imap.uid_search ['UID', "#{cur_offset}:#{end_offset}"]
     uids.each do |uid|
       @last_uid = uid
index ca85b03fca2d0ce85801c4a0fb65c5227447b42f..31e221e093c4338cc936ffa89ea5c8decedc3784 100644 (file)
@@ -29,8 +29,8 @@ class Loader < Source
       @f.seek offset
       l = @f.gets
       unless l =~ BREAK_RE
-        self.broken = "offset mismatch in mbox file offset #{offset.inspect}: #{l.inspect}. Run 'sup-import --rebuild #{to_s}' to correct this." 
-        raise SourceError, self.broken
+        self.broken_msg = "offset mismatch in mbox file offset #{offset.inspect}: #{l.inspect}. Run 'sup-import --rebuild #{to_s}' to correct this." 
+        raise SourceError, self.broken_msg
       end
       header = MBox::read_header @f
     end
index e3ea7b5393c014dad79f7484f62fdbd2e75210d8..4ce1f9b9782988dfcf29d885b2bfd97ad74a0db5 100644 (file)
@@ -9,7 +9,7 @@ class Source
   ## broken? means no message can be loaded (e.g. IMAP server is
   ## down), so don't even bother.
   bool_reader :usual, :archived, :dirty
-  attr_reader :cur_offset, :broken
+  attr_reader :cur_offset, :broken_msg
   attr_accessor :id
 
   ## You should implement:
@@ -29,10 +29,10 @@ class Source
     @archived = archived
     @id = id
     @dirty = false
-    @broken = nil
+    @broken_msg = nil
   end
 
-  def broken?; !@broken.nil?; end
+  def broken?; !@broken_msg.nil?; end
   def to_s; @uri; end
   def seek_to! o; self.cur_offset = o; end
   def reset!; seek_to! start_offset; end
@@ -56,7 +56,7 @@ protected
     @dirty = true
   end
   
-  attr_writer :broken
+  attr_writer :broken_msg
 end
 
 Redwood::register_yaml(Source, %w(uri cur_offset usual archived id))