X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=bin%2Fsup-tweak-labels;h=90f6a57ddb0cbebd037f4a74dd1692a191de522e;hb=93ed1a68e1b4321b62bfd15600b04d3adb6f7c57;hp=a8115ea6a2973c21b15191de97677dd12d0a3ac1;hpb=5ffac00720d64525c44ce959cd3c780e9624e72c;p=sup diff --git a/bin/sup-tweak-labels b/bin/sup-tweak-labels index a8115ea..90f6a57 100755 --- a/bin/sup-tweak-labels +++ b/bin/sup-tweak-labels @@ -38,8 +38,8 @@ be seen by running "sup-add --help". Options: EOS - opt :add, "One or more labels (comma-separated) to add to every message from the specified sources", :type => String - opt :remove, "One or more labels (comma-separated) to remove from every message from the specified sources, if those labels are present", :type => String + opt :add, "One or more labels (comma-separated) to add to every message from the specified sources", :default => "" + opt :remove, "One or more labels (comma-separated) to remove from every message from the specified sources, if those labels are present", :default => "" opt :query, "A Sup search query", :type => String text < true, :load_deleted => true, :load_killed => true ids = Enumerable::Enumerator.new(index, :each_id, parsed_query).map num_total = ids.size @@ -94,18 +96,17 @@ begin num_scanned += 1 m = index.build_message id - old_labels = m.labels.clone + old_labels = m.labels.dup m.labels += add_labels m.labels -= remove_labels - m.labels = m.labels.uniq - unless m.labels.sort_by { |s| s.to_s } == old_labels.sort_by { |s| s.to_s } + unless m.labels == old_labels num_changed += 1 puts "From #{m.from}, subject: #{m.subj}" if opts[:very_verbose] - puts "#{m.id}: {#{old_labels.join ','}} => {#{m.labels.join ','}}" if opts[:verbose] + puts "#{m.id}: {#{old_labels.to_a.join ','}} => {#{m.labels.to_a.join ','}}" if opts[:verbose] puts if opts[:very_verbose] - index.sync_message m unless opts[:dry_run] + index.update_message_state m unless opts[:dry_run] end if Time.now - last_info_time > 60