X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=bin%2Fsup-sync-back;h=56ac4eb51c05545e8879c976fcbf8b9c4d695c65;hb=43ccf339799293ab02e2c69b584ca3fe7bf2fb86;hp=4f1387e7f1e62d9ec13c03833d0670c9e87e4531;hpb=01316aff4da1e7ff74dc3fac4578251b80807528;p=sup diff --git a/bin/sup-sync-back b/bin/sup-sync-back old mode 100644 new mode 100755 index 4f1387e..56ac4eb --- a/bin/sup-sync-back +++ b/bin/sup-sync-back @@ -4,6 +4,7 @@ require 'rubygems' require 'uri' require 'tempfile' require 'trollop' +require 'enumerator' require "sup" ## save a message 'm' to an open file pointer 'fp' @@ -14,6 +15,10 @@ def die msg $stderr.puts "Error: #{msg}" exit(-1) end +def has_any_from_source_with_label? index, source, label + query = { :source_id => source.id, :label => label, :limit => 1, :load_spam => true, :load_deleted => true, :load_killed => true } + not Enumerable::Enumerator.new(index, :each_id, query).map.empty? +end opts = Trollop::options do version "sup-sync-back (sup #{Redwood::VERSION})" @@ -75,13 +80,13 @@ begin index.load sources = ARGV.map do |uri| - s = index.source_for(uri) or die "unknown source: #{uri}. Did you add it with sup-add first?" + s = Redwood::SourceManager.source_for(uri) or die "unknown source: #{uri}. Did you add it with sup-add first?" s.is_a?(Redwood::MBox::Loader) or die "#{uri} is not an mbox source." s end if sources.empty? - sources = index.usual_sources.select { |s| s.is_a? Redwood::MBox::Loader } + sources = Redwood::SourceManager.usual_sources.select { |s| s.is_a? Redwood::MBox::Loader } end unless sources.all? { |s| s.file_path.nil? } || File.executable?(dotlockfile) || opts[:dont_use_dotlockfile] @@ -96,7 +101,7 @@ EOS sources.each do |source| $stderr.puts "Scanning #{source}..." - unless ((opts[:drop_deleted] || opts[:move_deleted]) && index.has_any_from_source_with_label?(source, :deleted)) || ((opts[:drop_spam] || opts[:move_spam]) && index.has_any_from_source_with_label?(source, :spam)) + unless ((opts[:drop_deleted] || opts[:move_deleted]) && has_any_from_source_with_label?(index, source, :deleted)) || ((opts[:drop_spam] || opts[:move_spam]) && has_any_from_source_with_label?(index, source, :spam)) $stderr.puts "Nothing to do from this source; skipping" next end @@ -105,11 +110,11 @@ EOS num_dropped = num_moved = num_scanned = 0 out_fp = Tempfile.new "sup-sync-back-#{source.id}" - Redwood::PollManager.add_messages_from source do |m, offset, entry| + Redwood::PollManager.add_messages_from source do |m_old, m, offset| num_scanned += 1 - if entry - labels = entry[:label].symbolistize.to_boolean_h + if m_old + labels = m_old.labels if labels.member? :deleted if opts[:drop_deleted]