]> git.cworth.org Git - sup/blobdiff - lib/sup/source.rb
strip all spaces from message ids
[sup] / lib / sup / source.rb
index dce2f63501b344a5c308d0c64abf1cdc8f2002e0..50fc16327720a784c1442ab68a0b604d34991e1b 100644 (file)
@@ -5,15 +5,15 @@ class OutOfSyncSourceError < SourceError; end
 class FatalSourceError < SourceError; end
 
 class Source
-  ## Implementing a new source is typically quite easy, because Sup
-  ## only needs to be able to:
+  ## Implementing a new source should be easy, because Sup only needs
+  ## to be able to:
   ##  1. See how many messages it contains
-  ##  2. Get an arbirtrary message
+  ##  2. Get an arbitrary message
   ##  3. (optional) see whether the source has marked it read or not
   ##
   ## In particular, Sup doesn't need to move messages, mark them as
-  ## read, delete them, or anything else. (Well, at some point it will
-  ## need to delete them, but that will be an optional capability.)
+  ## read, delete them, or anything else. (Well, it's nice to be able
+  ## to delete them, but that is optional.)
   ##
   ## On the other hand, Sup assumes that you can assign each message a
   ## unique integer id, such that newer messages have higher ids than
@@ -31,9 +31,10 @@ class Source
   ## - load_header offset
   ## - load_message offset
   ## - raw_header offset
-  ## - raw_full_message offset
+  ## - raw_message offset
   ## - check
-  ## - next (or each, if you prefer)
+  ## - next (or each, if you prefer): should return a message and an
+  ##   array of labels.
   ##
   ## ... where "offset" really means unique id. (You can tell I
   ## started with mbox.)
@@ -46,7 +47,7 @@ class Source
   ## else (e.g. the imap server is down or the maildir is missing.)
   ##
   ## Finally, be sure the source is thread-safe, since it WILL be
-  ## pummeled from multiple threads at once.
+  ## pummelled from multiple threads at once.
   ##
   ## Examples for you to look at: mbox/loader.rb, imap.rb, and
   ## maildir.rb.
@@ -60,20 +61,24 @@ class Source
   attr_accessor :id
 
   def initialize uri, initial_offset=nil, usual=true, archived=false, id=nil
+    raise ArgumentError, "id must be an integer: #{id.inspect}" unless id.is_a? Fixnum if id
+
     @uri = uri
-    @cur_offset = initial_offset || start_offset
+    @cur_offset = initial_offset
     @usual = usual
     @archived = archived
     @id = id
     @dirty = false
   end
 
+  def file_path; nil end
+
   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 done?; (self.cur_offset ||= start_offset) >= end_offset; end
-  def is_source_for? uri; URI(self.uri) == URI(uri); end
+  def == o; o.uri == uri; end
+  def done?; start_offset.nil? || (self.cur_offset ||= start_offset) >= end_offset; end
+  def is_source_for? uri; uri == @uri; end
 
   ## check should throw a FatalSourceError or an OutOfSyncSourcError
   ## if it can detect a problem. it is called when the sup starts up
@@ -91,12 +96,14 @@ class Source
 
 protected
   
+  def Source.expand_filesystem_uri uri
+    uri.gsub "~", File.expand_path("~")
+  end
+
   def cur_offset= o
     @cur_offset = o
     @dirty = true
   end
 end
 
-Redwood::register_yaml(Source, %w(uri cur_offset usual archived id))
-
 end