lib/sup/sent.rb in sup-0.8.1 vs lib/sup/sent.rb in sup-0.9
- old
+ new
@@ -1,32 +1,38 @@
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
+ m.add_label :sent
+ PollManager.add_new_message m
end
end
end
class SentLoader < MBox::Loader
@@ -38,12 +44,13 @@
super "mbox://" + @filename, cur_offset, true, true
end
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