X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;ds=sidebyside;f=lib%2Fsup%2Fsent.rb;h=9203dd666816a770d8537c18c6281ae8f17ed14a;hb=69f515653ecdfb20dd3f01f33249e9c7569ce6db;hp=05b2f70c7bc5105ecda90560824f7945aa87ebd0;hpb=de735be892fed323b46931e6f677548b8c4953fe;p=sup diff --git a/lib/sup/sent.rb b/lib/sup/sent.rb index 05b2f70..9203dd6 100644 --- a/lib/sup/sent.rb +++ b/lib/sup/sent.rb @@ -3,44 +3,53 @@ 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 = 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 - @source.each do |offset, labels| - m = Message.new :source => @source, :source_info => offset, :labels => labels - Index.add_message m - UpdateManager.relay :add, m + 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 + 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 + @filename = Redwood::SENT_FN + File.open(@filename, "w") { } unless File.exists? @filename + super "mbox://" + @filename, cur_offset, true, true end - def to_s; SentManager.source_name; end - def id; SentManager.source_id; end - def labels; [:sent, :inbox]; end -end + def file_path; @filename end -Redwood::register_yaml(SentLoader, %w(cur_offset)) + def to_s; 'sup://sent'; end + def uri; 'sup://sent' end + + def id; 9998; end + def labels; [:inbox, :sent]; end +end end