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"
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]
: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
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
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