]> git.notmuchmail.org Git - sup/blob - lib/sup/sent.rb
0761bbc1573264c3c656ad05d3c66493db4ed246
[sup] / lib / sup / sent.rb
1 module Redwood
2
3 class SentManager
4   include Singleton
5
6   attr_accessor :source
7   def initialize fn
8     @fn = fn
9     @source = nil
10     self.class.i_am_the_instance self
11   end
12
13   def self.source_name; "sup://sent"; end
14   def self.source_id; 9998; end
15   def new_source; @source = SentLoader.new; end
16
17   def write_sent_message date, from_email
18     need_blank = File.exists?(@fn) && !File.zero?(@fn)
19     File.open(@fn, "a") do |f|
20       f.puts if need_blank
21       f.puts "From #{from_email} #{date}"
22       yield f
23     end
24     @source.each do |offset, labels|
25       m = Message.new :source => @source, :source_info => offset, :labels => self.labels
26       Index.add_message m
27       UpdateManager.relay self, :add, m
28     end
29   end
30 end
31
32 class SentLoader < MBox::Loader
33   def initialize cur_offset=0
34     filename = Redwood::SENT_FN
35     File.open(filename, "w") { } unless File.exists? filename
36     super "mbox://" + filename, cur_offset, true, true
37   end
38
39   def uri; SentManager.source_name; end
40   def to_s; SentManager.source_name; end
41   def id; SentManager.source_id; end
42   def labels; [:sent, :inbox]; end
43 end
44
45 Redwood::register_yaml(SentLoader, %w(cur_offset))
46
47 end