]> git.cworth.org Git - sup/blobdiff - lib/sup/sent.rb
Merge branch 'xapian-updates'
[sup] / lib / sup / sent.rb
index d4fcc2bc37dafdcd6e2b37beb3d6ec71cbbff716..9203dd666816a770d8537c18c6281ae8f17ed14a 100644 (file)
@@ -3,28 +3,33 @@ module Redwood
 class SentManager
   include Singleton
 
-  attr_accessor :source
-  def initialize fn
-    @fn = fn
+  attr_reader :source, :source_uri
+
+  def initialize source_uri
     @source = nil
-    self.class.i_am_the_instance self
+    @source_uri = source_uri
   end
 
-  def self.source_name; "sup://sent"; end
-  def self.source_id; 9998; end
-  def new_source; @source = Recoverable.new SentLoader.new; end
+  def source_id; @source.id; end
 
-  def write_sent_message time, from_email
-    need_blank = File.exists?(@fn) && !File.zero?(@fn)
-    File.open(@fn, "a") do |f|
-      f.puts if need_blank
-      f.puts "From #{from_email} #{time.asctime}"
-      yield f
-    end
+  def source= s
+    raise FatalSourceError.new("Configured sent_source [#{s.uri}] can't store mail.  Correct your configuration.") unless s.respond_to? :store_message
+    @souce_uri = s.uri
+    @source = s
+  end
 
-    PollManager.add_messages_from(@source) do |m, o, e|
+  def default_source
+    @source = Recoverable.new SentLoader.new
+    @source_uri = @source.uri
+    @source
+  end
+
+  def write_sent_message date, from_email, &block
+    @source.store_message date, from_email, &block
+
+    PollManager.each_message_from(@source) do |m|
       m.remove_label :unread
-      m
+      PollManager.add_new_message m
     end
   end
 end
@@ -40,10 +45,11 @@ class SentLoader < MBox::Loader
 
   def file_path; @filename end
 
-  def uri; SentManager.source_name; end
-  def to_s; SentManager.source_name; end
-  def id; SentManager.source_id; end
-  def labels; [:sent, :inbox]; end
+  def to_s; 'sup://sent'; end
+  def uri; 'sup://sent' end
+
+  def id; 9998; end
+  def labels; [:inbox, :sent]; end
 end
 
 end