IO.foreach opts[:restore] do |l|
l =~ /^(\S+) \((.*?)\)$/ or raise "Can't read dump line: #{l.inspect}"
mid, labels = $1, $2
- dump[mid] = labels.split(" ").map { |x| x.intern }
+ dump[mid] = labels.symbolistize
end
$stderr.puts "Read #{dump.size} entries from dump file."
dump
next if target == :changed && entry && entry[:source_id].to_i == source.id && entry[:source_info].to_i == offset
## get the state currently in the index
- index_state = entry[:label].split(/\s+/).map { |x| x.intern } if entry
+ index_state = entry[:label].symbolistize if entry
## skip if we're operating on restored messages, and this one
## ain't.
## to default source state modification flags.
m.labels -= [:inbox] if opts[:archive]
m.labels -= [:unread] if opts[:read]
- m.labels += opts[:extra_labels].split(/\s*,\s*/).map { |x| x.intern } if opts[:extra_labels]
+ 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
num_scanned += 1
if entry
- labels = entry[:label].split.map { |x| x.intern }.to_boolean_h
+ labels = entry[:label].symbolistize.to_boolean_h
if labels.member? :deleted
if opts[:drop_deleted]
return unless answer
- user_labels = answer.split(/\s+/).map { |l| l.intern }
+ user_labels = answer.symbolistize
user_labels.each do |l|
if forbidden_labels.include?(l) || LabelManager::RESERVED_LABELS.include?(l)
BufferManager.flash "'#{l}' is a reserved label!"
## 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].split(/\s+/).map { |l| l.intern } + m.labels).uniq
+ 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})"
}
Message.new :source => source, :source_info => doc[:source_info].to_i,
- :labels => doc[:label].split(" ").map { |s| s.intern },
+ :labels => doc[:label].symbolistize,
:snippet => doc[:snippet], :header => fake_header
end
end
numi = 0
add_messages_from source do |m, offset, entry|
## always preserve the labels on disk.
- m.labels = ((m.labels - [:unread, :inbox]) + entry[:label].split(/\s+/).map { |x| x.intern }).uniq if entry
+ m.labels = ((m.labels - [:unread, :inbox]) + entry[:label].symbolistize).uniq if entry
yield "Found message at #{offset} with labels {#{m.labels * ', '}}"
unless entry
num += 1
def normalize_whitespace
gsub(/\t/, " ").gsub(/\r/, "")
end
+
+ ## takes a space-separated list of words, and returns an array of symbols.
+ ## typically used in Sup for translating Ferret's representation of a list
+ ## of labels (a string) to an array of label symbols.
+ def symbolistize; split.map { |x| x.intern } end
end
class Numeric