]> git.notmuchmail.org Git - sup/blob - lib/sup/sent.rb
make >From thing work correctly
[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 = Recoverable.new 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
25     @source.each do |offset, labels|
26       m = Message.new :source => @source, :source_info => offset, :labels => @source.labels
27       Index.sync_message m
28       UpdateManager.relay self, :add, m
29     end
30   end
31 end
32
33 class SentLoader < MBox::Loader
34   yaml_properties :cur_offset
35
36   def initialize cur_offset=0
37     @filename = Redwood::SENT_FN
38     File.open(@filename, "w") { } unless File.exists? @filename
39     super "mbox://" + @filename, cur_offset, true, true
40   end
41
42   def file_path; @filename end
43
44   def uri; SentManager.source_name; end
45   def to_s; SentManager.source_name; end
46   def id; SentManager.source_id; end
47   def labels; [:sent, :inbox]; end
48 end
49
50 end