def each_message_in_thread_for m, opts={}
return unless doc = find_doc(m.id)
queue = doc.value(THREAD_VALUENO).split(',')
msgids = [m.id]
seen_threads = Set.new
seen_messages = Set.new [m.id]
while not queue.empty?
thread_id = queue.pop
next if seen_threads.member? thread_id
return false if opts[:skip_killed] && thread_killed?(thread_id)
seen_threads << thread_id
docs = term_docids(mkterm(:thread, thread_id)).map { |x| @xapian.document x }
docs.each do |doc|
msgid = doc.value MSGID_VALUENO
next if seen_messages.member? msgid
msgids << msgid
seen_messages << msgid
queue.concat doc.value(THREAD_VALUENO).split(',')
end
end
msgids.each { |id| yield id, lambda { build_message id } }
true
end