sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit b4e18ee0ac14e000a3fa0664ebfe86ba3be6c3c2
parent 2415791769c8944f5085d023de0c47cf5d1fbc2e
Author: William Morgan <wmorgan-sup@masanjin.net>
Date:   Sat, 23 Jan 2010 07:48:43 -0500

Merge branch 'xapian-updates' into next

Diffstat:
M lib/sup/buffer.rb | 2 +-
M lib/sup/xapian_index.rb | 31 +++++++++++++++++--------------
2 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb
@@ -537,7 +537,7 @@ EOS
   end
 
   def ask_for_contacts domain, question, default_contacts=[]
-    default = default_contacts.map { |s| s.to_s }.join(" ")
+    default = default_contacts.is_a?(String) ? default_contacts : default_contacts.map { |s| s.to_s }.join(", ")
     default += " " unless default.empty?
 
     recent = Index.load_contacts(AccountManager.user_emails, :num => 10).map { |c| [c.full_address, c.email] }
diff --git a/lib/sup/xapian_index.rb b/lib/sup/xapian_index.rb
@@ -10,7 +10,7 @@ module Redwood
 # for searching due to precomputing thread membership.
 class XapianIndex < BaseIndex
   STEM_LANGUAGE = "english"
-  INDEX_VERSION = '1'
+  INDEX_VERSION = '2'
 
   ## 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
@@ -37,7 +37,10 @@ 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 != INDEX_VERSION
+      if db_version == '1'
+        info "Upgrading index format 1 to 2"
+        @xapian.set_metadata 'version', INDEX_VERSION
+      elsif db_version != INDEX_VERSION
         fail "This Sup version expects a v#{INDEX_VERSION} index, but you have an existing v#{db_version} index. Please downgrade to your previous version and dump your labels before upgrading to this version (then run sup-sync --restore)."
       end
     else
@@ -263,9 +266,9 @@ EOS
     qp.stemming_strategy = Xapian::QueryParser::STEM_SOME
     qp.default_op = Xapian::Query::OP_AND
     qp.add_valuerangeprocessor(Xapian::NumberValueRangeProcessor.new(DATE_VALUENO, 'date:', true))
-    NORMAL_PREFIX.each { |k,v| qp.add_prefix k, v }
-    BOOLEAN_PREFIX.each { |k,v| qp.add_boolean_prefix k, v }
-    xapian_query = qp.parse_query(subs, Xapian::QueryParser::FLAG_PHRASE|Xapian::QueryParser::FLAG_BOOLEAN|Xapian::QueryParser::FLAG_LOVEHATE|Xapian::QueryParser::FLAG_WILDCARD, PREFIX['body'])
+    NORMAL_PREFIX.each { |k,vs| vs.each { |v| qp.add_prefix k, v } }
+    BOOLEAN_PREFIX.each { |k,vs| vs.each { |v| qp.add_boolean_prefix k, v } }
+    xapian_query = qp.parse_query(subs, Xapian::QueryParser::FLAG_PHRASE|Xapian::QueryParser::FLAG_BOOLEAN|Xapian::QueryParser::FLAG_LOVEHATE|Xapian::QueryParser::FLAG_WILDCARD)
 
     debug "parsed xapian query: #{xapian_query.description}"
 
@@ -283,8 +286,10 @@ EOS
     'body' => 'B',
     'from_name' => 'FN',
     'to_name' => 'TN',
-    'name' => 'N',
+    'name' => %w(FN TN),
     'attachment' => 'A',
+    'email_text' => 'E',
+    '' => %w(S B FN TN A E),
   }
 
   # Unstemmed
@@ -292,12 +297,13 @@ EOS
     'type' => 'K',
     'from_email' => 'FE',
     'to_email' => 'TE',
-    'email' => 'E',
+    'email' => %w(FE TE),
     'date' => 'D',
     'label' => 'L',
     'source_id' => 'I',
     'attachment_extension' => 'O',
     'msgid' => 'Q',
+    'id' => 'Q',
     'thread' => 'H',
     'ref' => 'R',
   }
@@ -464,10 +470,9 @@ EOS
     # Person names are indexed with several prefixes
     person_termer = lambda do |d|
       lambda do |p|
-        ["#{d}_name", "name", "body"].each do |x|
-          doc.index_text p.name, PREFIX[x]
-        end if p.name
-        [d, :any].each { |x| doc.add_term mkterm(:email, x, p.email) }
+        doc.index_text p.name, PREFIX["#{d}_name"] if p.name
+        doc.index_text p.email, PREFIX['email_text']
+        doc.add_term mkterm(:email, d, p.email)
       end
     end
 
@@ -478,7 +483,6 @@ EOS
     subject_text = m.indexable_subject
     body_text = m.indexable_body
     doc.index_text subject_text, PREFIX['subject']
-    doc.index_text subject_text, PREFIX['body']
     doc.index_text body_text, PREFIX['body']
     m.attachments.each { |a| doc.index_text a, PREFIX['attachment'] }
 
@@ -561,7 +565,6 @@ EOS
       case args[0]
       when :from then PREFIX['from_email']
       when :to then PREFIX['to_email']
-      when :any then PREFIX['email']
       else raise "Invalid email term type #{args[0]}"
       end + args[1].to_s.downcase
     when :source_id
@@ -597,7 +600,7 @@ class Xapian::Document
   alias old_add_term add_term
   def add_term term
     if term.length <= Redwood::XapianIndex::MAX_TERM_LENGTH
-      old_add_term term
+      old_add_term term, 0
     else
       warn "dropping excessively long term #{term}"
     end