2012-11-18 [colin] 3.9.0cvs5-stable
authorColin Leroy <colin@colino.net>
Sun, 18 Nov 2012 16:38:56 +0000 (16:38 +0000)
committerColin Leroy <colin@colino.net>
Sun, 18 Nov 2012 16:38:56 +0000 (16:38 +0000)
* src/advsearch.c
Backport 3.9.0cvs8 and 3.9.0cvs9:
Fix missing initialisation of bool_and which could
lead to From/To/Subject/Tag searches searching with
binary and.
Also clean up tag expansion. No need to create a
matcher string and re-parse it.
Also initialize is_fast.

ChangeLog
PATCHSETS
configure.ac
src/advsearch.c

index 6ff8ddd..044ab94 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2012-11-18 [colin]     3.9.0cvs5-stable
+
+       * src/advsearch.c
+               Backport 3.9.0cvs8 and 3.9.0cvs9:
+               Fix missing initialisation of bool_and which could
+               lead to From/To/Subject/Tag searches searching with
+               binary and.
+               Also clean up tag expansion. No need to create a
+               matcher string and re-parse it.
+               Also initialize is_fast.
+
 2012-11-18 [colin]     3.9.0cvs4-stable
 
        * po/de.po
index 34614a4..3da15c9 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.1.2.40 -r 1.1.2.41 commitHelper;  cvs diff -u -r 1.9.2.25 -r 1.9.2.26 po/cs.po;  cvs diff -u -r 1.1.2.28 -r 1.1.2.29 po/fi.po;  cvs diff -u -r 1.2.2.36 -r 1.2.2.37 po/sk.po;  ) > 3.9.0cvs2-stable.patchset
 ( cvs diff -u -r 1.395.2.456 -r 1.395.2.457 src/summaryview.c;  ) > 3.9.0cvs3-stable.patchset
 ( cvs diff -u -r 1.58.2.51 -r 1.58.2.52 po/de.po;  ) > 3.9.0cvs4-stable.patchset
+( cvs diff -u -r 1.1.2.7 -r 1.1.2.8 src/advsearch.c;  ) > 3.9.0cvs5-stable.patchset
index 7be7b27..ab2edd4 100644 (file)
@@ -12,7 +12,7 @@ MINOR_VERSION=9
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=4
+EXTRA_VERSION=5
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=-stable
 
index ae14b59..ed806e2 100644 (file)
@@ -314,32 +314,6 @@ gchar *advsearch_expand_search_string(const gchar *search_string)
        return returnstr;
 }
 
-// --------------------------
-
-static gchar *expand_tag_search_string(const gchar *search_string)
-{
-       gchar *newstr = NULL;
-       gchar **words = search_string ? g_strsplit(search_string, " ", -1):NULL;
-       gint i = 0;
-       while (words && words[i] && *words[i]) {
-               g_strstrip(words[i]);
-               if (!newstr) {
-                       newstr = g_strdup_printf("tag matchcase \"%s\"", words[i]);
-               } else {
-                       gint o_len = strlen(newstr);
-                       gint s_len = 17; /* strlen("|tag matchcase \"\"") */
-                       gint n_len = s_len + strlen(words[i]);
-                       newstr = g_realloc(newstr, o_len + n_len + 1);
-                       strcpy(newstr + o_len, "|tag matchcase \"");
-                       strcpy(newstr + o_len + (s_len - 1), words[i]);
-                       strcpy(newstr + o_len + (n_len - 1), "\"");
-               }
-               i++;
-       }
-       g_strfreev(words);
-       return newstr;
-}
-
 static void prepare_matcher_extended(AdvancedSearch *search)
 {
        gchar *newstr = advsearch_expand_search_string(search->request.matchstring);
@@ -350,19 +324,52 @@ static void prepare_matcher_extended(AdvancedSearch *search)
        }
 }
 
+#define debug_matcher_list(prefix, list)                                       \
+do {                                                                           \
+       gchar *str = list ? matcherlist_to_string(list) : g_strdup("(NULL)");   \
+                                                                               \
+       debug_print("%s: %s\n", prefix, str);                                   \
+                                                                               \
+       g_free(str);                                                            \
+} while(0)
+
 static void prepare_matcher_tag(AdvancedSearch *search)
 {
-       char *newstr = expand_tag_search_string(search->request.matchstring);
-       search->predicate = matcher_parser_get_cond(newstr, &search->is_fast);
-       g_free(newstr);
+       gchar **words = search->request.matchstring 
+                       ? g_strsplit(search->request.matchstring, " ", -1)
+                       : NULL;
+       gint i = 0;
+
+       if (search->predicate == NULL) {
+               search->predicate = g_new0(MatcherList, 1);
+               search->predicate->bool_and = FALSE;
+               search->is_fast = TRUE;
+       }
+
+       while (words && words[i] && *words[i]) {
+               MatcherProp *matcher;
+
+               g_strstrip(words[i]);
+
+               matcher = matcherprop_new(MATCHCRITERIA_TAG, NULL,
+                                         MATCHTYPE_MATCHCASE, words[i], 0);
+
+               search->predicate->matchers = g_slist_prepend(search->predicate->matchers, matcher);
+
+               i++;
+       }
+       g_strfreev(words);
 }
 
 static void prepare_matcher_header(AdvancedSearch *search, gint match_header)
 {
        MatcherProp *matcher;
 
-       if (search->predicate == NULL)
+       if (search->predicate == NULL) {
                search->predicate = g_new0(MatcherList, 1);
+               search->predicate->bool_and = FALSE;
+               search->is_fast = TRUE;
+       }
 
        matcher = matcherprop_new(match_header, NULL, MATCHTYPE_MATCHCASE,
                        search->request.matchstring, 0);
@@ -373,10 +380,18 @@ static void prepare_matcher_header(AdvancedSearch *search, gint match_header)
 static void prepare_matcher_mixed(AdvancedSearch *search)
 {
        prepare_matcher_tag(search);
+       debug_matcher_list("tag matcher list", search->predicate);
+
+       /* we want an OR search */
+       if (search->predicate)
+               search->predicate->bool_and = FALSE;
 
        prepare_matcher_header(search, MATCHCRITERIA_SUBJECT);
+       debug_matcher_list("tag + subject matcher list", search->predicate);
        prepare_matcher_header(search, MATCHCRITERIA_FROM);
+       debug_matcher_list("tag + subject + from matcher list", search->predicate);
        prepare_matcher_header(search, MATCHCRITERIA_TO);
+       debug_matcher_list("tag + subject + from + to matcher list", search->predicate);
 }
 
 static void prepare_matcher(AdvancedSearch *search)
@@ -398,26 +413,32 @@ static void prepare_matcher(AdvancedSearch *search)
        switch (search->request.type) {
                case ADVANCED_SEARCH_SUBJECT:
                        prepare_matcher_header(search, MATCHCRITERIA_SUBJECT);
+                       debug_matcher_list("subject search", search->predicate);
                        break;
 
                case ADVANCED_SEARCH_FROM:
                        prepare_matcher_header(search, MATCHCRITERIA_FROM);
+                       debug_matcher_list("from search", search->predicate);
                        break;
 
                case ADVANCED_SEARCH_TO:
                        prepare_matcher_header(search, MATCHCRITERIA_TO);
+                       debug_matcher_list("to search", search->predicate);
                        break;
 
                case ADVANCED_SEARCH_TAG:
-                       prepare_matcher_header(search, MATCHCRITERIA_TAG);
+                       prepare_matcher_tag(search);
+                       debug_matcher_list("tag search", search->predicate);
                        break;
 
                case ADVANCED_SEARCH_MIXED:
                        prepare_matcher_mixed(search);
+                       debug_matcher_list("mixed search", search->predicate);
                        break;
 
                case ADVANCED_SEARCH_EXTENDED:
                        prepare_matcher_extended(search);
+                       debug_matcher_list("extended search", search->predicate);
                        break;
 
                default: