X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lib%2Fsup%2Fsent.rb;h=9203dd666816a770d8537c18c6281ae8f17ed14a;hb=46f8e5116f38c8248fdc8553db18f8d2132a1f46;hp=ee843c7dc54837acbcc39daab851509037692bb0;hpb=7d7498d9903604c8c3cd5c649a62625cef7959ea;p=sup diff --git a/lib/sup/sent.rb b/lib/sup/sent.rb index ee843c7..9203dd6 100644 --- a/lib/sup/sent.rb +++ b/lib/sup/sent.rb @@ -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 date, 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} #{date}" - 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