]> git.cworth.org Git - sup/blobdiff - lib/sup/mbox/loader.rb
finally do imap flags the right way, and clean up mbox and imap source flag duplicati...
[sup] / lib / sup / mbox / loader.rb
index b2162c078d04da00b449c07a3980e99554a4989c..c1392654e17aa7e00fe471efa2c978e41458d46b 100644 (file)
@@ -10,24 +10,25 @@ class Loader < Source
   ## uri_or_fp is horrific. need to refactor.
   def initialize uri_or_fp, start_offset=nil, usual=true, archived=false, id=nil, labels=[]
     @mutex = Mutex.new
-    @labels = (labels || []).freeze
+    @labels = ((labels || []) - LabelManager::RESERVED_LABELS).uniq.freeze
 
     case uri_or_fp
     when String
-      uri_or_fp = Source.expand_filesystem_uri uri_or_fp
-      uri = URI(uri_or_fp)
+      uri = URI(Source.expand_filesystem_uri(uri_or_fp))
       raise ArgumentError, "not an mbox uri" unless uri.scheme == "mbox"
       raise ArgumentError, "mbox uri ('#{uri}') cannot have a host: #{uri.host}" if uri.host
       @f = File.open uri.path
+      @path = uri.path
     else
       @f = uri_or_fp
+      @path = uri_or_fp.path
     end
 
     super uri_or_fp, start_offset, usual, archived, id
   end
 
-  def file_path; URI(uri).path end
-  def is_source_for? uri; super || (URI(Source.expand_filesystem_uri(uri)) == URI(self.uri)); end
+  def file_path; @path end
+  def is_source_for? uri; super || (self.uri.is_a?(String) && (URI(Source.expand_filesystem_uri(uri)) == URI(Source.expand_filesystem_uri(self.uri)))) end
 
   def self.suggest_labels_for path
     ## heuristic: use the filename as a label, unless the file
@@ -85,19 +86,19 @@ class Loader < Source
     ret
   end
 
-  def raw_full_message offset
+  def raw_message offset
     ret = ""
-    each_raw_full_message_line(offset) { |l| ret += l }
+    each_raw_message_line(offset) { |l| ret += l }
     ret
   end
 
   ## apparently it's a million times faster to call this directly if
   ## we're just moving messages around on disk, than reading things
-  ## into memory with raw_full_message.
+  ## into memory with raw_message.
   ##
   ## i hoped never to have to move shit around on disk but
   ## sup-sync-back has to do it.
-  def each_raw_full_message_line offset
+  def each_raw_message_line offset
     @mutex.synchronize do
       @f.seek offset
       yield @f.gets
@@ -141,7 +142,7 @@ class Loader < Source
     end
 
     self.cur_offset = next_offset
-    [returned_offset, @labels]
+    [returned_offset, (@labels + [:unread]).uniq]
   end
 end