- ## skip if we're operating only on changed messages, the message
- ## is in the index, and it's unchanged from what the source is
- ## reporting.
- next if target == :changed && m_old && m_old.source.id == source.id && m_old.source_info == offset
-
- ## get the state currently in the index
- index_state = m_old.labels.dup if m_old
-
- ## skip if we're operating on restored messages, and this one
- ## ain't.
- next if target == :restored && (!restored_state[m.id] || (index_state && restored_state[m.id].sort_by { |s| s.to_s } == index_state.sort_by { |s| s.to_s }))
-
- ## m.labels is the default source labels. tweak these according
- ## to default source state modification flags.
- m.labels -= [:inbox] if opts[:archive]
- m.labels -= [:unread] if opts[:read]
- m.labels += opts[:extra_labels].strip.split(/\s*,\s*/).map { |x| x.intern } if opts[:extra_labels]
-
- ## assign message labels based on the operation we're performing
- case op
- when :asis
- m.labels = ((m.labels - [:unread, :inbox]) + index_state).uniq if index_state
- when :restore
- ## if the entry exists on disk
- if restored_state[m.id]
- m.labels = restored_state[m.id]
+ ## tweak source labels according to commandline arguments if necessary
+ m.labels.delete :inbox if opts[:archive]
+ m.labels.delete :unread if opts[:read]
+ m.labels += opts[:extra_labels].to_set_of_symbols(",")
+
+ ## decide what to do based on message labels and the operation we're performing
+ dothis, new_labels = case
+ when (op == :restore) && restored_state[m.id]
+ if old_m && (old_m.labels != restored_state[m.id])
+ num_restored += 1
+ [:update_message_state, restored_state[m.id]]
+ elsif old_m.nil?