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