]> git.cworth.org Git - sup/commitdiff
misc. source-related bugfixes
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sun, 1 Apr 2007 21:36:44 +0000 (21:36 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sun, 1 Apr 2007 21:36:44 +0000 (21:36 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@359 5c8cc53c-5e98-4d25-b20a-d8db53a31250

doc/TODO
lib/sup/draft.rb
lib/sup/maildir.rb
lib/sup/mbox/loader.rb
lib/sup/poll.rb
lib/sup/sent.rb
lib/sup/source.rb

index 87ccb520593783ee9e84a81e6cbc0443e53e4a36..42c97e0dcd26b9bbfe8d0da1ed84dff197290338 100644 (file)
--- a/doc/TODO
+++ b/doc/TODO
@@ -9,7 +9,7 @@ _ bugfix: triggering a pageup when cursor scrolling up jumps to the
 _ bugfix: add new message counts until keypress
 _ bugfix: attachment filenames sometimes not detected (filename=)
 _ bugfix: final logging messages to stdout?
-_ bugfix: mbox directory shouldn't generate an exception, just an error
+x bugfix: mbox directory shouldn't generate an exception, just an error
 x bugfix: m in thread-view-mode when a person is not selected should open up a
 x bugfix: stars on messages with blue backgrounds still have green bgs
 x ferret upgrade script (dump & restore)
index 4beaf3e764df8b746894f4634ff3769b275a5179..59eef8c85b688e1849e370e5cb8cd02e6861d20b 100644 (file)
@@ -12,7 +12,7 @@ class DraftManager
 
   def self.source_name; "sup://drafts"; end
   def self.source_id; 9999; end
-  def new_source; @source = DraftLoader.new; end
+  def new_source; @source = Recoverable.new DraftLoader.new; end
 
   def write_draft
     offset = @source.gen_offset
index 5bc884b7ba84d31532e790a72ea8ea7fd4372c7e..58be5962c385c6d08f6e5acec4440cd6596fdd21 100644 (file)
@@ -13,8 +13,12 @@ class Maildir < Source
 
   def initialize uri, last_date=nil, usual=true, archived=false, id=nil
     super
+    uri = URI(uri)
 
-    @dir = URI(uri).path
+    raise ArgumentError, "not a maildir URI" unless uri.scheme == "maildir"
+    raise ArgumentError, "maildir URI cannot have a host: #{uri.host}" if uri.host
+
+    @dir = uri.path
     @ids = []
     @ids_to_fns = {}
     @last_scan = nil
@@ -52,6 +56,9 @@ class Maildir < Source
 
     cdir = File.join(@dir, 'cur')
     ndir = File.join(@dir, 'new')
+    
+    raise FatalSourceError, "#{cdir} not a directory" unless File.directory? cdir
+    raise FatalSourceError, "#{ndir} not a directory" unless File.directory? ndir
 
     begin
       @ids, @ids_to_fns = @mutex.synchronize do
@@ -61,6 +68,7 @@ class Maildir < Source
           ids << id
           ids_to_fns[id] = fn
         end
+        p [ids.sort, ids_to_fns]
         [ids.sort, ids_to_fns]
       end
     rescue SystemCallError => e
index dfca5b284d3e72444f2e1f401e3faf9ccfa67e66..6c9c7019c2ed2515d556d76902ce7a3e053eb14f 100644 (file)
@@ -13,13 +13,13 @@ class Loader < Source
 
     case uri_or_fp
     when String
-      raise ArgumentError, "not an mbox uri" unless uri_or_fp =~ %r!mbox://!
-
-      fn = URI(uri_or_fp).path
+      uri = URI(uri_or_fp)
+      raise ArgumentError, "not an mbox uri" unless uri.scheme == "mbox"
+      raise ArgumentError, "mbox uri cannot have a host: #{uri.host}" if uri.host
       ## heuristic: use the filename as a label, unless the file
       ## has a path that probably represents an inbox.
-      @labels << File.basename(fn).intern unless File.dirname(fn) =~ /\b(var|usr|spool)\b/
-      @f = File.open fn
+      @labels << File.basename(uri.path).intern unless File.dirname(uri.path) =~ /\b(var|usr|spool)\b/
+      @f = File.open uri.path
     else
       @f = uri_or_fp
     end
index cae97aea3c9c156313ed23820108b301ec87b53a..adf1d06d0719df10659e533ca52bc4926379f9f5 100644 (file)
@@ -43,7 +43,14 @@ class PollManager
     @mutex.synchronize do
       Index.usual_sources.each do |source|
 #        yield "source #{source} is done? #{source.done?} (cur_offset #{source.cur_offset} >= #{source.end_offset})"
-        yield "Loading from #{source}... " unless source.done? || source.has_errors?
+        begin
+          yield "Loading from #{source}... " unless source.done? || source.has_errors?
+        rescue SourceError => e
+          Redwood::log "problem getting messages from #{source}: #{e.message}"
+          Redwood::report_broken_sources
+          next
+        end
+
         num = 0
         numi = 0
         add_messages_from source do |m, offset, entry|
@@ -82,9 +89,9 @@ class PollManager
   ## the index labels, if they exist, so that state is not lost when
   ## e.g. a new version of a message from a mailing list comes in.
   def add_messages_from source
-    return if source.done? || source.has_errors?
-
     begin
+      return if source.done? || source.has_errors?
+      
       source.each do |offset, labels|
         if source.has_errors?
           Redwood::log "error loading messages from #{source}: #{source.broken_msg}"
index 37b9524db36c345c11c58ef7db4af8e92eabd90b..8a546b67e768166d63acccf261bbde0f46f47bd3 100644 (file)
@@ -12,7 +12,7 @@ class SentManager
 
   def self.source_name; "sup://sent"; end
   def self.source_id; 9998; end
-  def new_source; @source = SentLoader.new; end
+  def new_source; @source = Recoverable.new SentLoader.new; end
 
   def write_sent_message date, from_email
     need_blank = File.exists?(@fn) && !File.zero?(@fn)
index dce2f63501b344a5c308d0c64abf1cdc8f2002e0..55e1baca890f7f9c9968e5a4cf79efe64a8de2b9 100644 (file)
@@ -61,7 +61,7 @@ class Source
 
   def initialize uri, initial_offset=nil, usual=true, archived=false, id=nil
     @uri = uri
-    @cur_offset = initial_offset || start_offset
+    @cur_offset = initial_offset
     @usual = usual
     @archived = archived
     @id = id
@@ -71,7 +71,7 @@ class Source
   def to_s; @uri.to_s; end
   def seek_to! o; self.cur_offset = o; end
   def reset!; seek_to! start_offset; end
-  def == o; o.to_s == to_s; end
+  def == o; o.uri == uri; end
   def done?; (self.cur_offset ||= start_offset) >= end_offset; end
   def is_source_for? uri; URI(self.uri) == URI(uri); end