- d =
- {
- :message_id => (entry[:message_id] || m.id),
- :source_id => (entry[:source_id] || source_id),
- :source_info => (entry[:source_info] || m.source_info),
+ labels = m.labels.uniq # override because this is the new state, unless...
+
+ ## if we are a later version of a message, ignore what's in the index,
+ ## but merge in the labels.
+ if entry[:source_id] && entry[:source_info] && entry[:label] &&
+ ((entry[:source_id].to_i > source_id) || (entry[:source_info].to_i < m.source_info))
+ labels = (entry[:label].symbolistize + m.labels).uniq
+ #Redwood::log "found updated version of message #{m.id}: #{m.subj}"
+ #Redwood::log "previous version was at #{entry[:source_id].inspect}:#{entry[:source_info].inspect}, this version at #{source_id.inspect}:#{m.source_info.inspect}"
+ #Redwood::log "merged labels are #{labels.inspect} (index #{entry[:label].inspect}, message #{m.labels.inspect})"
+ entry = {}
+ end
+
+ ## if force_overwite is true, ignore what's in the index. this is used
+ ## primarily by sup-sync to force index updates.
+ entry = {} if opts[:force_overwrite]
+
+ d = {
+ :message_id => m.id,
+ :source_id => source_id,
+ :source_info => m.source_info,