lib/sup/draft.rb in sup-0.3 vs lib/sup/draft.rb in sup-0.4

- old
+ new

@@ -21,24 +21,24 @@ my_message = nil @source.each do |thisoffset, theselabels| m = Message.new :source => @source, :source_info => thisoffset, :labels => theselabels Index.sync_message m - UpdateManager.relay self, :add, m + UpdateManager.relay self, :added, m my_message = m if thisoffset == offset end my_message end - def discard mid - docid, entry = Index.load_entry_for_id mid - raise ArgumentError, "can't find entry for draft: #{mid.inspect}" unless entry - raise ArgumentError, "not a draft: source id #{entry[:source_id].inspect}, should be #{DraftManager.source_id.inspect} for #{mid.inspect} / docno #{docid}" unless entry[:source_id].to_i == DraftManager.source_id + def discard m + docid, entry = Index.load_entry_for_id m.id + raise ArgumentError, "can't find entry for draft: #{m.id.inspect}" unless entry + raise ArgumentError, "not a draft: source id #{entry[:source_id].inspect}, should be #{DraftManager.source_id.inspect} for #{m.id.inspect} / docno #{docid}" unless entry[:source_id].to_i == DraftManager.source_id Index.drop_entry docid File.delete @source.fn_for_offset(entry[:source_info]) - UpdateManager.relay self, :delete, mid + UpdateManager.relay self, :single_message_deleted, m end end class DraftLoader < Source attr_accessor :dir @@ -95,9 +95,15 @@ until f.eof? || (l = f.gets) =~ /^$/ ret += l end end ret + end + + def each_raw_message_line offset + File.open(fn_for_offset(offset)) do |f| + yield f.gets until f.eof? + end end def raw_message offset IO.readlines(fn_for_offset(offset)).join end