File: sup-dump

package info (click to toggle)
sup-mail 0.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,112 kB
  • ctags: 1,522
  • sloc: ruby: 12,724; sh: 18; makefile: 6
file content (43 lines) | stat: -rwxr-xr-x 1,107 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env ruby

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

#require 'rubygems'
require 'xapian'
require 'trollop'
require 'set'

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

$opts = Trollop::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