Make combo search field work again.

Gentoo bug: https://bugs.gentoo.org/show_bug.cgi?id=455590
Upstream commit: http://www.claws-mail.org/tracker/getpatchset.php?ver=3.9.0cvs8
--- src/advsearch.c	24 Oct 2012 07:48:24 -0000	1.1.2.7
+++ src/advsearch.c	16 Nov 2012 13:10:05 -0000	1.1.2.8
@@ -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,51 @@
 	}
 }
 
+#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;
+	}
 
 	matcher = matcherprop_new(match_header, NULL, MATCHTYPE_MATCHCASE,
 			search->request.matchstring, 0);
@@ -373,10 +379,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 +412,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:

