sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 3889fb90d61b2218a968cc84aa001e3510decd89
parent 0a33287792fd6650cab5149e78ee9311760f2c64
Author: wmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Date:   Sat, 15 Sep 2007 03:36:23 +0000

expand twiddles for mbox and maildir uris (thanks to Magnus Therning)

git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@577 5c8cc53c-5e98-4d25-b20a-d8db53a31250

Diffstat:
M bin/sup-add | 1 -
M lib/sup/maildir.rb | 3 +++
M lib/sup/mbox/loader.rb | 8 ++++++--
M lib/sup/source.rb | 6 +++++-
4 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/bin/sup-add b/bin/sup-add
@@ -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
diff --git a/lib/sup/maildir.rb b/lib/sup/maildir.rb
@@ -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
diff --git a/lib/sup/mbox/loader.rb b/lib/sup/mbox/loader.rb
@@ -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
diff --git a/lib/sup/source.rb b/lib/sup/source.rb
@@ -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