def add_message message
el = @messages[message.id]
return if el.message
el.message = message
oldroot = el.root
(message.refs + [el.id]).inject(nil) do |prev, ref_id|
ref = @messages[ref_id]
link prev, ref if prev
ref
end
message.replytos.each do |ref_id|
ref = @messages[ref_id]
link ref, el, true
break
end
root = el.root
key =
if thread_by_subj?
Message.normalize_subj root.subj
else
root.id
end
if root.thread
if @threads.member?(key) && @threads[key] != root.thread
@threads.delete key
end
else
thread = @threads[key]
thread << root
root.thread = thread
end
@num_messages += 1
end