]> git.notmuchmail.org Git - sup/blobdiff - lib/sup/index.rb
reply-mode bugfix thanks to Marcus Williams
[sup] / lib / sup / index.rb
index 6ff7e5a936822ecbcccf72c95c8bec881ef1fd1e..6a499c9e72ae2d04d73fcf5f7ab0f8fd64ebcfe0 100644 (file)
@@ -18,6 +18,7 @@ class Index
   include Singleton
 
   attr_reader :index
+  alias ferret index
   def initialize dir=BASE_DIR
     @dir = dir
     @sources = {}
@@ -154,7 +155,7 @@ EOS
     docid, entry = load_entry_for_id m.id unless docid && entry
 
     raise "no source info for message #{m.id}" unless m.source && m.source_info
-    raise "trying to delete non-corresponding entry #{docid}" if docid && @index[docid][:message_id] != m.id
+    raise "trying to delete non-corresponding entry #{docid} with index message-id #{@index[docid][:message_id].inspect} and parameter message id #{m.id.inspect}" if docid && @index[docid][:message_id] != m.id
 
     source_id = 
       if m.source.is_a? Integer
@@ -225,7 +226,9 @@ EOS
   ## message-building lambdas, so that building an unwanted message
   ## can be skipped in the block if desired.
   ##
-  ## stops loading any thread if a message with a :killed flag is found.
+  ## only two options, :limit and :skip_killed. if :skip_killed is
+  ## true, stops loading any thread if a message with a :killed flag
+  ## is found.
   SAME_SUBJECT_DATE_LIMIT = 7
   def each_message_in_thread_for m, opts={}
     #Redwood::log "Building thread for #{m.id}: #{m.subj}"
@@ -261,15 +264,13 @@ EOS
       q.add_query Ferret::Search::TermQuery.new(:message_id, id), :should
       q.add_query Ferret::Search::TermQuery.new(:refs, id), :should
 
-      ## load_killed is true so that we can abort if any message in
-      ## the thread has the killed label.
-      q = build_query :qobj => q, :load_killed => true
+      q = build_query :qobj => q
 
       num_queries += 1
       killed = false
       @index.search_each(q, :limit => :all) do |docid, score|
         break if opts[:limit] && messages.size >= opts[:limit]
-        if @index[docid][:label].split(/\s+/).include?("killed") && !opts[:load_killed]
+        if @index[docid][:label].split(/\s+/).include?("killed") && opts[:skip_killed]
           killed = true
           break
         end
@@ -305,7 +306,7 @@ EOS
       "from" => doc[:from],
       "to" => doc[:to],
       "message-id" => doc[:message_id],
-      "references" => doc[:refs],
+      "references" => doc[:refs].split(/\s+/).map { |x| "<#{x}>" }.join(" "),
     }
 
     Message.new :source => source, :source_info => doc[:source_info].to_i, 
@@ -400,7 +401,7 @@ protected
         
     query.add_query Ferret::Search::TermQuery.new("label", "spam"), :must_not unless opts[:load_spam] || labels.include?(:spam)
     query.add_query Ferret::Search::TermQuery.new("label", "deleted"), :must_not unless opts[:load_deleted] || labels.include?(:deleted)
-    query.add_query Ferret::Search::TermQuery.new("label", "killed"), :must_not unless opts[:load_killed] || labels.include?(:killed)
+    query.add_query Ferret::Search::TermQuery.new("label", "killed"), :must_not if opts[:skip_killed]
     query
   end