+ source_id =
+ if m.source.is_a? Integer
+ raise "Debugging: integer source set"
+ m.source
+ else
+ m.source.id or raise "unregistered source #{m.source} (id #{m.source.id.inspect})"
+ end
+
+ to = (m.to + m.cc + m.bcc).map { |x| x.email }.join(" ")
+ d = {
+ :message_id => m.id,
+ :source_id => source_id,
+ :source_info => m.source_info,
+ :date => m.date.to_indexable_s,
+ :body => m.content,
+ :snippet => m.snippet,
+ :label => m.labels.join(" "),
+ :from => m.from ? m.from.email : "",
+ :to => (m.to + m.cc + m.bcc).map { |x| x.email }.join(" "),
+ :subject => wrap_subj(Message.normalize_subj(m.subj)),
+ :refs => (m.refs + m.replytos).uniq.join(" "),
+ }
+
+ @index.delete docid if docid
+ @index.add_document d
+
+ docid, entry = load_entry_for_id m.id
+ ## this hasn't been triggered in a long time. TODO: decide whether it's still a problem.
+ raise "just added message #{m.id} but couldn't find it in a search" unless docid
+ true