sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit b2d78427be803808497aca1a8fcf868e3c778e0e
parent 06ee8f7d84485d7b5b545c76cb32395601a1e032
Author: William Morgan <wmorgan-sup@masanjin.net>
Date:   Wed, 26 Dec 2007 12:44:37 -0800

make explicitly searching for "label:spam" and "label:deleted" work
see comments for how this is possible without implementing our own
full-blown Ferret query parser.

Diffstat:
M lib/sup/index.rb | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/lib/sup/index.rb b/lib/sup/index.rb
@@ -383,7 +383,7 @@ EOS
   end
 
   def has_any_from_source_with_label? source, label
-    q = Ferret::Search::BooleanQuery.new
+    q = erret::Search::BooleanQuery.new
     q.add_query Ferret::Search::TermQuery.new("source_id", source.id.to_s), :must
     q.add_query Ferret::Search::TermQuery.new("label", label.to_s), :must
     index.search(q, :limit => 1).total_hits > 0
@@ -417,8 +417,24 @@ protected
         [field, name]
       end.join(":")
     end
-    
-    # gmail style "is" operator
+
+    ## if we see a label:deleted or a label:spam term anywhere in the query
+    ## string, we set the extra load_spam or load_deleted options to true.
+    ## bizarre? well, because the query allows arbitrary parenthesized boolean
+    ## expressions, without fully parsing the query, we can't tell whether
+    ## the user is explicitly directing us to search spam messages or not.
+    ## e.g. if the string is -(-(-(-(-label:spam)))), does the user want to
+    ## search spam messages or not?
+    ##
+    ## so, we rely on the fact that turning these extra options ON turns OFF
+    ## the adding of "-label:deleted" or "-label:spam" terms at the very
+    ## final stage of query processing. if the user wants to search spam
+    ## messages, not adding that is the right thing; if he doesn't want to
+    ## search spam messages, then not adding it won't have any effect.
+    extraopts[:load_spam] = true if subs =~ /\blabel:spam\b/
+    extraopts[:load_deleted] = true if subs =~ /\blabel:deleted\b/
+
+    ## gmail style "is" operator
     subs = subs.gsub(/\b(is):(\S+)\b/) do
       field, label = $1, $2
       case label