Sha256: cf64c39b37283db68da39470ea0888f9b2ec26f1636ecfe39e321d0f8f3dda84

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 KB

Contents

#!/usr/bin/env ruby

$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])

require 'xapian'
require 'optimist'
require 'set'

BASE_DIR = ENV["SUP_BASE"] || File.join(ENV["HOME"], ".sup")

$opts = Optimist::options do
  version "sup-dump"
  banner <<EOS
Dumps all message state from the sup index to standard out. You can
later use sup-sync --restored --restore <filename> to recover the index.

This tool is primarily useful in the event that a Sup upgrade breaks index
format compatibility.

Usage:
  sup-dump > <filename>
  sup-dump | bzip2 > <filename> # even better
EOS
end

xapian = Xapian::Database.new File.join(BASE_DIR, 'xapian')
version = xapian.get_metadata 'rescue-version'
version = '0' if version.empty?

case version
when '0'
  xapian.postlist('Kmail').each do |x|
    begin
      entry = Marshal.load(xapian.document(x.docid).data)
      puts "#{entry[:message_id]} (#{entry[:labels].sort_by { |l| l.to_s } * ' '})"
    rescue
      $stderr.puts "failed to dump document #{x.docid}"
    end
  end
else
  abort "this sup-dump version doesn't understand your index"
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sup-1.2 bin/sup-dump
sup-1.1 bin/sup-dump
sup-1.0 bin/sup-dump
sup-0.23 bin/sup-dump