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

lib/sup/imap.rb
lib/sup/index.rb
lib/sup/mbox/loader.rb
lib/sup/source.rb

index c2e9e6dfe39da851cff4794cb7f1b86c0629336a..86dc236ac37735b62b0358de430684c534f195cc 100644 (file)
@@ -5,7 +5,7 @@ require 'stringio'
 module Redwood
 
 class IMAP < Source
-  attr_reader :labels, :broken_msg
+  attr_reader :labels
   
   def initialize uri, username, password, last_uid=nil, usual=true, archived=false, id=nil
     raise ArgumentError, "username and password must be specified" unless username && password
@@ -48,10 +48,9 @@ class IMAP < Source
         @imap.examine mailbox
         Redwood::log "successfully connected to #{@parsed_uri}, mailbox #{mailbox}"
       rescue Exception => e
-        self.broken = true
+        self.broken = e.message.chomp # fucking chomp! fuck!!!
         @imap = nil
-        @broken_msg = e.message.chomp # fucking chomp! fuck!!!
-        Redwood::log "error connecting to IMAP server: #{@broken_msg}"
+        Redwood::log "error connecting to IMAP server: #{self.broken}"
       end
     end.join
 
@@ -73,7 +72,7 @@ class IMAP < Source
   ## load the full header text
   def raw_header uid
     begin
-      connect or return broken_msg
+      connect or return broken
     rescue Exception => e
       raise "wtf: #{e.inspect}"
     end
@@ -81,12 +80,12 @@ class IMAP < Source
   end
 
   def raw_full_message uid
-    connect or return broken_msg
+    connect or return broken
     @imap.uid_fetch(uid, 'RFC822')[0].attr['RFC822'].gsub(/\r\n/, "\n")
   end
   
   def each
-    connect or return broken_msg
+    connect or return broken
     uids = @imap.uid_search ['UID', "#{cur_offset}:#{end_offset}"]
     uids.each do |uid|
       @last_uid = uid
index 4288549ae46df30889a38bb9be5efce5db2ca61c..2dc2101ed64313361d16cc392d85176967506f7b 100644 (file)
@@ -220,7 +220,7 @@ An error occurred while loading this message. It is possible that the source
 has changed, or (in the case of remote sources) is down.
 
 The error message was:
-  #{source.broken_msg}
+  #{source.broken}
 EOS
     end
     m
index 340226bb8f0b0a2a61f6e04ce26ed3ca4c11c871..ca85b03fca2d0ce85801c4a0fb65c5227447b42f 100644 (file)
@@ -28,7 +28,10 @@ class Loader < Source
     @mutex.synchronize do
       @f.seek offset
       l = @f.gets
-      raise SourceError, "offset mismatch in mbox file offset #{offset.inspect}: #{l.inspect}. Run 'sup-import --rebuild #{to_s}' to correct this." unless l =~ BREAK_RE
+      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
+      end
       header = MBox::read_header @f
     end
     header
index 4dc2077bbfa6cec564320fa33768766a6a50e3dc..e3ea7b5393c014dad79f7484f62fdbd2e75210d8 100644 (file)
@@ -8,8 +8,8 @@ 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, :broken
-  attr_reader :cur_offset
+  bool_reader :usual, :archived, :dirty
+  attr_reader :cur_offset, :broken
   attr_accessor :id
 
   ## You should implement:
@@ -29,9 +29,10 @@ class Source
     @archived = archived
     @id = id
     @dirty = false
-    @broken = false
+    @broken = nil
   end
 
+  def broken?; !@broken.nil?; end
   def to_s; @uri; end
   def seek_to! o; self.cur_offset = o; end
   def reset!; seek_to! start_offset; end