[Commits] advsearch.c 1.1.2.7 1.1.2.7.2.1

colin at claws-mail.org colin at claws-mail.org
Sun Nov 18 17:38:55 CET 2012


Update of /home/claws-mail/claws/src
In directory srv:/tmp/cvs-serv23099/src

Modified Files:
      Tag: stable_3_9
	advsearch.c 
Log Message:
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.

Index: advsearch.c
===================================================================
RCS file: /home/claws-mail/claws/src/Attic/advsearch.c,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.7.2.1
diff -u -d -r1.1.2.7 -r1.1.2.7.2.1
--- advsearch.c	24 Oct 2012 07:48:24 -0000	1.1.2.7
+++ advsearch.c	18 Nov 2012 16:38:53 -0000	1.1.2.7.2.1
@@ -314,32 +314,6 @@
 	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 @@
 	}
 }
 
+#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_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 @@
 	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:



More information about the Commits mailing list