From 5057149d9c3b57c6b5c4d0964a0aae9d490aaa38 Mon Sep 17 00:00:00 2001 From: Ben Walton Date: Wed, 6 May 2009 22:44:24 -0400 Subject: [PATCH] SentManager: rework handling to allow for user specified source * The handling of SentManager now allows for a parameter in config.yaml called sent_source. This parameter should be the URI of the source that the users wishes to store outbound mail in. * The default is sup://sent * A FatalSourceError is raised in the event that sent_source is set to a source type that doesn't support the store_message() method. * SentManager and SentLoader have been somewhat decoupled. Signed-off-by: Ben Walton --- bin/sup | 5 ++--- lib/sup.rb | 3 ++- lib/sup/sent.rb | 42 ++++++++++++++++++++++++++---------------- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/bin/sup b/bin/sup index 0af3d11..9abe1b5 100755 --- a/bin/sup +++ b/bin/sup @@ -168,11 +168,10 @@ begin Index.add_source DraftManager.new_source end - if(s = Index.source_for SentManager.source_name) + if(s = Index.source_for SentManager.source_uri) SentManager.source = s else - Redwood::log "no sent mail source, auto-adding..." - Index.add_source SentManager.new_source + Index.add_source SentManager.default_source end HookManager.run "startup" diff --git a/lib/sup.rb b/lib/sup.rb index 96510b2..4f59eaa 100644 --- a/lib/sup.rb +++ b/lib/sup.rb @@ -101,7 +101,7 @@ module Redwood end def start - Redwood::SentManager.new Redwood::SENT_FN + Redwood::SentManager.new $config[:sent_source] || 'sup://sent' Redwood::ContactManager.new Redwood::CONTACT_FN Redwood::LabelManager.new Redwood::LABEL_FN Redwood::AccountManager.new $config[:accounts] @@ -207,6 +207,7 @@ else :confirm_top_posting => true, :discard_snippets_from_encrypted_messages => false, :default_attachment_save_dir => "", + :sent_source => "sup://sent" } begin FileUtils.mkdir_p Redwood::BASE_DIR diff --git a/lib/sup/sent.rb b/lib/sup/sent.rb index ee843c7..bad2083 100644 --- a/lib/sup/sent.rb +++ b/lib/sup/sent.rb @@ -3,24 +3,33 @@ module Redwood class SentManager include Singleton - attr_accessor :source - def initialize fn - @fn = fn + attr_reader :source + attr_reader :source_uri + + def initialize source_uri @source = nil + @source_uri = source_uri self.class.i_am_the_instance self + Redwood::log "SentManager intialized with 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 + + def default_source + @source = Recoverable.new SentLoader.new + Redwood::log "SentManager initializing default source: #@source." + @source_uri = @source.uri + @source + end + + def write_sent_message date, from_email, &block + @source.store_message date, from_email, &block PollManager.add_messages_from(@source) do |m, o, e| m.remove_label :unread @@ -40,9 +49,10 @@ 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 to_s; 'sup://sent'; end + def uri; 'sup://sent' end + + def id; 9998; end def labels; [:sent, :inbox]; end end -- 2.45.2