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; "sent"; end
- def self.source_id; 9998; end
- def new_source; @source = SentLoader.new @fn; end
-
- def write_sent_message date, from_email
- need_blank = File.exists?(@fn) && !File.zero?(@fn)
- File.open(@fn, "a") do |f|
- if need_blank
- @source.increment_offset if @source.offset == f.tell
- f.puts
- end
- f.puts "From #{from_email} #{date}"
- yield f
- end
- @source.each do |offset, labels|
- m = Message.new @source, offset, labels
- Index.add_message m
- UpdateManager.relay :add, m
+ def source_id; @source.id; 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
+
+ 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
+ PollManager.add_new_message m
end
end
end
class SentLoader < MBox::Loader
- def initialize filename, end_offset=0
- File.open(filename, "w") { } unless File.exists? filename
- super filename, end_offset, true, true
+ yaml_properties :cur_offset
+
+ def initialize cur_offset=0
+ @filename = Redwood::SENT_FN
+ File.open(@filename, "w") { } unless File.exists? @filename
+ super "mbox://" + @filename, cur_offset, true, true
end
- def increment_offset; @end_offset += 1; end
- def offset; @end_offset; end
- def id; SentManager.source_id; end
- def to_s; SentManager.source_name; end
+ def file_path; @filename end
- def labels; [:sent, :inbox]; end
-end
+ def to_s; 'sup://sent'; end
+ def uri; 'sup://sent' end
-Redwood::register_yaml(SentLoader, %w(filename end_offset))
+ def id; 9998; end
+ def labels; [:inbox, :sent]; end
+end
end