sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit c8f9f9d1bf408bf39f4b10682219cf2b129d3248
parent 7d0a5b942b6204d5077f3ac87101f6945bc9534a
Author: Rich Lane <rlane@club.cc.cmu.edu>
Date:   Mon, 24 May 2010 19:44:28 -0700

Merge branch 'maildir' into next

Diffstat:
M bin/sup-dump | 28 +++++++++++++++++++---------
M lib/sup/index.rb | 12 +++---------
2 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/bin/sup-dump b/bin/sup-dump
@@ -1,17 +1,21 @@
 #!/usr/bin/env ruby
 
 require 'rubygems'
+require 'xapian'
 require 'trollop'
-require "sup"; Redwood::check_library_version_against "git"
+
+BASE_DIR = ENV["SUP_BASE"] || File.join(ENV["HOME"], ".sup")
 
 $opts = Trollop::options do
-  version "sup-dump (sup #{Redwood::VERSION})"
+  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 Ferret upgrade breaks
-the index format. This happened, for example, at Ferret version 0.11.
+This tool is primarily useful in the event that a Sup upgrade breaks index
+format compatibility.
+
+This sup-dump supports index versions 0 through 4.
 
 Usage:
   sup-dump > <filename>
@@ -19,10 +23,16 @@ Usage:
 EOS
 end
 
-index = Redwood::Index.init
-Redwood::SourceManager.init
-index.load
+xapian = Xapian::Database.new File.join(BASE_DIR, 'xapian')
+db_version = xapian.get_metadata 'version'
+db_version = '0' if db_version.empty?
 
-index.each_message :load_spam => true, :load_deleted => true, :load_killed => true do |m|
-  puts "#{m.id} (#{m.labels.to_a.sort_by { |l| l.to_s } * ' '})"
+case db_version
+when '0', '1', '2', '3', '4'
+  xapian.postlist('Kmail').each do |x|
+    entry = Marshal.load(xapian.document(x.docid).data)
+    puts "#{entry[:message_id]} (#{entry[:labels].sort_by { |l| l.to_s } * ' '})"
+  end
+else
+  abort "unknown index version #{db_version.inspect}"
 end
diff --git a/lib/sup/index.rb b/lib/sup/index.rb
@@ -22,7 +22,7 @@ class Index
   include InteractiveLock
 
   STEM_LANGUAGE = "english"
-  INDEX_VERSION = '3'
+  INDEX_VERSION = '4'
 
   ## dates are converted to integers for xapian, and are used for document ids,
   ## so we must ensure they're reasonably valid. this typically only affect
@@ -105,7 +105,7 @@ EOS
       @xapian = Xapian::WritableDatabase.new(path, Xapian::DB_OPEN)
       db_version = @xapian.get_metadata 'version'
       db_version = '0' if db_version.empty?
-      if db_version == '1' || db_version == '2'
+      if false
         info "Upgrading index format #{db_version} to #{INDEX_VERSION}"
         @xapian.set_metadata 'version', INDEX_VERSION
       elsif db_version != INDEX_VERSION
@@ -766,13 +766,7 @@ end
 
 class Xapian::Document
   def entry
-    entry = Marshal.load data
-    if entry[:source_id]
-      entry[:locations] = [[entry[:source_id], entry[:source_info]]]
-      entry.delete :source_id
-      entry.delete :source_info
-    end
-    entry
+    Marshal.load data
   end
 
   def entry=(x)