sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 735593960308648000dbe99d706221c24a306746
parent f72bb069cd77c4cc1376a85eeee8ca5cde5cdd79
Author: Dan Callaghan <djc@djc.id.au>
Date:   Mon,  5 Oct 2026 14:29:38 +1100

use MatchAll base query term instead of Kmail

Works around a spurious DatabaseCorruptError from Xapian, if no other
terms are added to the query (as in the "all mail" listing).

Xapian bug: https://trac.xapian.org/ticket/855

Fixes #628 (with a workaround).

Diffstat:
M Manifest.txt | 1 +
M lib/sup/index.rb | 4 +++-
A test/integration/test_index.rb | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 66 insertions(+), 1 deletion(-)
diff --git a/Manifest.txt b/Manifest.txt
@@ -173,6 +173,7 @@ test/gnupg_test_home/regen_keys.sh
 test/gnupg_test_home/secring.gpg
 test/gnupg_test_home/sup-test-2@foo.bar.asc
 test/integration/test_draft.rb
+test/integration/test_index.rb
 test/integration/test_maildir.rb
 test/integration/test_mbox.rb
 test/integration/test_sup-add.rb
diff --git a/lib/sup/index.rb b/lib/sup/index.rb
@@ -674,7 +674,9 @@ EOS
     neglabels = [:spam, :deleted, :killed].reject { |l| (labels.include? l) || opts.member?("load_#{l}".intern) }
     pos_terms, neg_terms = [], []
 
-    pos_terms << mkterm(:type, 'mail')
+    ## workaround for https://trac.xapian.org/ticket/855
+    #pos_terms << mkterm(:type, 'mail')
+    pos_terms << Q::MatchAll
     pos_terms.concat(labels.map { |l| mkterm(:label,l) })
     pos_terms << opts[:qobj] if opts[:qobj]
     pos_terms << mkterm(:source_id, opts[:source_id]) if opts[:source_id]
diff --git a/test/integration/test_index.rb b/test/integration/test_index.rb
@@ -0,0 +1,62 @@
+require "sup"
+require "test_helper"
+
+class TestIndexIntegration < Minitest::Test
+  include Redwood
+
+  def setup
+    @path = Dir.mktmpdir
+  end
+
+  def teardown
+    ObjectSpace.each_object(Class).select {|a| a < Redwood::Singleton}.each do |klass|
+      klass.deinstantiate! unless klass == Redwood::Logger
+    end
+    FileUtils.rm_r @path
+  end
+
+  def create_large_mbox n_messages
+    mbox = File.join @path, "big.mbox"
+    File.open(mbox, "w") do |f|
+      n_messages.times do |i|
+        ## spread the dates out so that the assigned docids are not
+        ## contiguous, as in a real index
+        date = Time.utc(2011) + i * 3600
+        f.write <<EOS
+From bob@example.com Sat Jan  1 00:00:00 2011
+From: Bob <bob@example.com>
+To: Joe <joe@example.com>
+Subject: message number #{i}
+Date: #{date.strftime "%a, %d %b %Y %H:%M:%S +0000"}
+Message-ID: <message-#{i}@example.com>
+
+Hi Bob, this is test message #{i}. From Joe.
+
+EOS
+      end
+    end
+    mbox
+  end
+
+  def start_sup_and_add_source source
+    start
+    Logger.remove_sink $stderr
+    Index.init @path
+    Index.load
+    SourceManager.instance.instance_eval '@sources = {}'
+    SourceManager.instance.add_source source
+    PollManager.poll_from source
+    Index.save_index
+  end
+
+  def test_all_mail_query
+    n_messages = 1200
+    mbox = create_large_mbox n_messages
+    start_sup_and_add_source MBox.new "mbox:#{mbox}"
+
+    ## the empty query is the "all mail" listing
+    ids = []
+    Index.each_id({}) { |id| ids << id }
+    assert_equal n_messages, ids.size
+  end
+end