]> git.cworth.org Git - sup/commitdiff
expand twiddles for mbox and maildir uris (thanks to Magnus Therning)
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sat, 15 Sep 2007 03:36:23 +0000 (03:36 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sat, 15 Sep 2007 03:36:23 +0000 (03:36 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@577 5c8cc53c-5e98-4d25-b20a-d8db53a31250

bin/sup-add
lib/sup/maildir.rb
lib/sup/mbox/loader.rb
lib/sup/source.rb

index 78df02220dfa705bf59077daadc8f33197fa77c6..2070e371e7ec0cdfd3caffa35908cc1c0b8c7649 100644 (file)
@@ -93,7 +93,6 @@ begin
     end
 
     parsed_uri = URI(uri)
-    Trollop::die "no path component to uri: #{parsed_uri}" unless parsed_uri.path
 
     source = 
       case parsed_uri.scheme
index cc487d75b1b15632c768d957ecc8bfd430441694..2ecfbe7d67383f24af53c6c1c0689fa9e554f7e1 100644 (file)
@@ -11,8 +11,10 @@ module Redwood
 class Maildir < Source
   SCAN_INTERVAL = 30 # seconds
 
+  ## remind me never to use inheritance again.
   yaml_properties :uri, :cur_offset, :usual, :archived, :id, :labels
   def initialize uri, last_date=nil, usual=true, archived=false, id=nil, labels=[]
+    uri = Source.expand_filesystem_uri uri
     super uri, last_date, usual, archived, id
     uri = URI(uri)
 
@@ -29,6 +31,7 @@ class Maildir < Source
 
   def file_path; @dir end
   def self.suggest_labels_for path; [] end
+  def is_source_for? uri; super || (URI(Source.expand_filesystem_uri(uri)) == URI(self.uri)); end
 
   def check
     scan_mailbox
index 3105f4a40967f471f4140f2b6fc2de183b0ab15b..b2162c078d04da00b449c07a3980e99554a4989c 100644 (file)
@@ -6,14 +6,15 @@ module MBox
 
 class Loader < Source
   yaml_properties :uri, :cur_offset, :usual, :archived, :id, :labels
-  def initialize uri_or_fp, start_offset=nil, usual=true, archived=false, id=nil, labels=[]
-    super uri_or_fp, start_offset, usual, archived, id
 
+  ## 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
 
     case uri_or_fp
     when String
+      uri_or_fp = Source.expand_filesystem_uri uri_or_fp
       uri = 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
@@ -21,9 +22,12 @@ class Loader < Source
     else
       @f = uri_or_fp
     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 self.suggest_labels_for path
     ## heuristic: use the filename as a label, unless the file
index 2724b75ce99a7396bef06051c19f9c7f328a2023..db91d11f664cbdc585cb481f8d98a3117401662c 100644 (file)
@@ -78,7 +78,7 @@ class Source
   def reset!; seek_to! start_offset; 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
+  def is_source_for? uri; 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
@@ -96,6 +96,10 @@ class Source
 
 protected
   
+  def Source.expand_filesystem_uri uri
+    uri.gsub "~", File.expand_path("~")
+  end
+
   def cur_offset= o
     @cur_offset = o
     @dirty = true