2007-10-03 [colin] 3.0.2cvs4
authorColin Leroy <colin@colino.net>
Wed, 3 Oct 2007 17:02:10 +0000 (17:02 +0000)
committerColin Leroy <colin@colino.net>
Wed, 3 Oct 2007 17:02:10 +0000 (17:02 +0000)
* src/matcher.c
* src/gtk/quicksearch.c
Fix bug 1340, 'Case insensitive searches with
non-ascii alphabets fail'.

ChangeLog
PATCHSETS
configure.ac
src/gtk/quicksearch.c
src/matcher.c

index 6471292..aaf7be3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-10-03 [colin]     3.0.2cvs4
+
+       * src/matcher.c
+       * src/gtk/quicksearch.c
+               Fix bug 1340, 'Case insensitive searches with 
+               non-ascii alphabets fail'.
+
 2007-10-03 [colin]     3.0.2cvs3
 
        * src/main.c
index 6113cb7..33034bb 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.42.2.35 -r 1.42.2.36 NEWS;  cvs diff -u -r 1.8.2.42 -r 1.8.2.43 README;  cvs diff -u -r 1.1.2.24 -r 1.1.2.25 RELEASE_NOTES;  cvs diff -u -r 1.654.2.2969 -r 1.654.2.2970 configure.ac;  ) > 3.0.2cvs1.patchset
 ( cvs diff -u -r 1.207.2.185 -r 1.207.2.186 src/folderview.c;  ) > 3.0.2cvs2.patchset
 ( cvs diff -u -r 1.115.2.167 -r 1.115.2.168 src/main.c;  cvs diff -u -r 1.36.2.114 -r 1.36.2.115 src/common/utils.c;  cvs diff -u -r 1.20.2.51 -r 1.20.2.52 src/common/utils.h;  ) > 3.0.2cvs3.patchset
+( cvs diff -u -r 1.75.2.48 -r 1.75.2.49 src/matcher.c;  cvs diff -u -r 1.1.2.78 -r 1.1.2.79 src/gtk/quicksearch.c;  ) > 3.0.2cvs4.patchset
index f8862be..c98f145 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=0
 MICRO_VERSION=2
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=3
+EXTRA_VERSION=4
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 4367efb..d3e5669 100644 (file)
@@ -147,11 +147,11 @@ static void prepare_matcher(QuickSearch *quicksearch)
                quicksearch->matcher_list = matcher_parser_get_cond(newstr, &quicksearch->is_fast);
                g_free(newstr);
                g_free(quicksearch->search_string);
-               quicksearch->search_string = g_strdup(search_string);
+               quicksearch->search_string = g_utf8_casefold(search_string, -1);
        } else {
                quicksearch->is_fast = TRUE;
                g_free(quicksearch->search_string);
-               quicksearch->search_string = g_strdup(search_string);
+               quicksearch->search_string = g_utf8_casefold(search_string, -1);
        }
 
        g_free(search_string);
@@ -915,21 +915,37 @@ gboolean quicksearch_match(QuickSearch *quicksearch, MsgInfo *msginfo)
 {
        gchar *searched_header = NULL;
        gboolean result = FALSE;
+       gchar *to = NULL, *from = NULL, *subject = NULL;
 
        if (!quicksearch->active)
                return TRUE;
 
        switch (prefs_common.summary_quicksearch_type) {
        case QUICK_SEARCH_SUBJECT:
-               searched_header = msginfo->subject;
+               if (msginfo->subject)
+                       searched_header = g_utf8_casefold(msginfo->subject, -1);
+               else
+                       return FALSE;
                break;
        case QUICK_SEARCH_FROM:
-               searched_header = msginfo->from;
+               if (msginfo->from)
+                       searched_header = g_utf8_casefold(msginfo->from, -1);
+               else
+                       return FALSE;
                break;
        case QUICK_SEARCH_TO:
-               searched_header = msginfo->to;
+               if (msginfo->to)
+                       searched_header = g_utf8_casefold(msginfo->to, -1);
+               else
+                       return FALSE;
                break;
        case QUICK_SEARCH_MIXED:
+               if (msginfo->to)
+                       to = g_utf8_casefold(msginfo->to, -1);
+               if (msginfo->from)
+                       from = g_utf8_casefold(msginfo->from, -1);
+               if (msginfo->subject)
+                       subject = g_utf8_casefold(msginfo->subject, -1);
                break;
        case QUICK_SEARCH_EXTENDED:
                break;
@@ -937,18 +953,19 @@ gboolean quicksearch_match(QuickSearch *quicksearch, MsgInfo *msginfo)
                debug_print("unknown search type (%d)\n", prefs_common.summary_quicksearch_type);
                break;
        }
+
        quicksearch->matching = TRUE;
        if (prefs_common.summary_quicksearch_type != QUICK_SEARCH_EXTENDED &&
            prefs_common.summary_quicksearch_type != QUICK_SEARCH_MIXED &&
            prefs_common.summary_quicksearch_type != QUICK_SEARCH_TAG &&
            quicksearch->search_string &&
-            searched_header && strcasestr(searched_header, quicksearch->search_string) != NULL)
+            searched_header && strstr(searched_header, quicksearch->search_string) != NULL)
                result = TRUE;
        else if (prefs_common.summary_quicksearch_type == QUICK_SEARCH_MIXED &&
                quicksearch->search_string && (
-               (msginfo->to && strcasestr(msginfo->to, quicksearch->search_string) != NULL) ||
-               (msginfo->from && strcasestr(msginfo->from, quicksearch->search_string) != NULL) ||
-               (msginfo->subject && strcasestr(msginfo->subject, quicksearch->search_string) != NULL) ||
+               (to && strstr(to, quicksearch->search_string) != NULL) ||
+               (from && strstr(from, quicksearch->search_string) != NULL) ||
+               (subject && strstr(subject, quicksearch->search_string) != NULL) ||
                ((quicksearch->matcher_list != NULL) &&
                 matcherlist_match(quicksearch->matcher_list, msginfo))  ))
                result = TRUE;
@@ -961,6 +978,11 @@ gboolean quicksearch_match(QuickSearch *quicksearch, MsgInfo *msginfo)
                prepare_matcher(quicksearch);
        }
 
+       g_free(to);
+       g_free(from);
+       g_free(subject);
+       g_free(searched_header);
+
        return result;
 }
 
@@ -1160,7 +1182,7 @@ static gchar *expand_tag_search_string(const gchar *search_string)
                        newstr = g_realloc(newstr,o_len+n_len+1);
                        strcpy(newstr+o_len, "|tag regexpcase \"");
                        strcpy(newstr+o_len+(s_len-1), words[i]);
-                       strcpy(newstr+o_len+s_len, "\"");
+                       strcpy(newstr+o_len+(n_len-1), "\"");
                }
                i++;
        }
index b2bbfcb..102d3ef 100644 (file)
@@ -256,7 +256,13 @@ MatcherProp *matcherprop_new(gint criteria, const gchar *header,
        prop = g_new0(MatcherProp, 1);
        prop->criteria = criteria;
        prop->header = header != NULL ? g_strdup(header) : NULL;
-       prop->expr = expr != NULL ? g_strdup(expr) : NULL;
+
+       if (matchtype == MATCHTYPE_MATCHCASE ||
+           matchtype == MATCHTYPE_REGEXPCASE)
+               prop->expr = expr != NULL ? g_utf8_casefold(expr, -1) : NULL;
+       else
+               prop->expr = expr != NULL ? g_strdup(expr) : NULL;
+
        prop->matchtype = matchtype;
        prop->preg = NULL;
        prop->value = value;
@@ -403,15 +409,23 @@ static gboolean match_with_addresses_in_addressbook
  *             matcher structure
  */
 static gboolean matcherprop_string_match(MatcherProp *prop, const gchar *str,
-                                                                               const gchar *debug_context)
+                                        const gchar *debug_context)
 {
        gchar *str1;
-       gchar *str2;
        gboolean ret = FALSE;
-
+       gboolean should_free = FALSE;
        if (str == NULL)
                return FALSE;
 
+       if (prop->matchtype == MATCHTYPE_REGEXPCASE ||
+           prop->matchtype == MATCHTYPE_MATCHCASE) {
+               str1 = g_utf8_casefold(str, -1);
+               should_free = TRUE;
+       } else {
+               str1 = (gchar *)str;
+               should_free = FALSE;
+       }
+
        switch (prop->matchtype) {
        case MATCHTYPE_REGEXPCASE:
        case MATCHTYPE_REGEXP:
@@ -430,7 +444,7 @@ static gboolean matcherprop_string_match(MatcherProp *prop, const gchar *str,
                if (prop->preg == NULL)
                        return FALSE;
                
-               if (regexec(prop->preg, str, 0, NULL, 0) == 0)
+               if (regexec(prop->preg, str1, 0, NULL, 0) == 0)
                        ret = TRUE;
                else
                        ret = FALSE;
@@ -443,19 +457,22 @@ static gboolean matcherprop_string_match(MatcherProp *prop, const gchar *str,
                        strretchomp(stripped);
                        if (ret) {
                                log_print(LOG_DEBUG_FILTERING,
-                                               "%s value [ %s ] matches regular expression [ %s ]\n",
-                                               debug_context, stripped, prop->expr);
+                                               "%s value [ %s ] matches regular expression [ %s ] (%s)\n",
+                                               debug_context, stripped, prop->expr,
+                                               prop->matchtype == MATCHTYPE_REGEXP ? _("Case sensitive"):_("Case unsensitive"));
                        } else {
                                log_print(LOG_DEBUG_FILTERING,
-                                               "%s value [ %s ] doesn't matches regular expression [ %s ]\n",
-                                               debug_context, stripped, prop->expr);
+                                               "%s value [ %s ] doesn't matches regular expression [ %s ] (%s)\n",
+                                               debug_context, stripped, prop->expr,
+                                               prop->matchtype == MATCHTYPE_REGEXP ? _("Case sensitive"):_("Case unsensitive"));
                        }
                        g_free(stripped);
                }
                break;
                        
+       case MATCHTYPE_MATCHCASE:
        case MATCHTYPE_MATCH:
-               ret = (strstr(str, prop->expr) != NULL);
+               ret = (strstr(str1, prop->expr) != NULL);
 
                /* debug output */
                if (debug_filtering_session
@@ -465,49 +482,26 @@ static gboolean matcherprop_string_match(MatcherProp *prop, const gchar *str,
                        strretchomp(stripped);
                        if (ret) {
                                log_print(LOG_DEBUG_FILTERING,
-                                               "%s value [ %s ] contains [ %s ] (case sensitive)\n",
-                                               debug_context, stripped, prop->expr);
+                                               "%s value [ %s ] contains [ %s ] (%s)\n",
+                                               debug_context, stripped, prop->expr,
+                                               prop->matchtype == MATCHTYPE_MATCH ? _("Case sensitive"):_("Case unsensitive"));
                        } else {
                                log_print(LOG_DEBUG_FILTERING,
-                                               "%s value [ %s ] doesn't contains [ %s ] (case sensitive)\n",
-                                               debug_context, stripped, prop->expr);
+                                               "%s value [ %s ] doesn't contains [ %s ] (%s)\n",
+                                               debug_context, stripped, prop->expr,
+                                               prop->matchtype == MATCHTYPE_MATCH ? _("Case sensitive"):_("Case unsensitive"));
                        }
                        g_free(stripped);
                }
                break;
 
-       /* FIXME: put upper in unesc_str */
-       case MATCHTYPE_MATCHCASE:
-               str2 = alloca(strlen(prop->expr) + 1);
-               strcpy(str2, prop->expr);
-               g_strup(str2);
-               str1 = alloca(strlen(str) + 1);
-               strcpy(str1, str);
-               g_strup(str1);
-               ret = (strstr(str1, str2) != NULL);
-
-               /* debug output */
-               if (debug_filtering_session
-                               && prefs_common.filtering_debug_level >= FILTERING_DEBUG_LEVEL_HIGH) {
-                       gchar *stripped = g_strdup(str);
-
-                       strretchomp(stripped);
-                       if (ret) {
-                               log_print(LOG_DEBUG_FILTERING,
-                                               "%s value [ %s ] contains [ %s ] (case insensitive)\n",
-                                               debug_context, stripped, prop->expr);
-                       } else {
-                               log_print(LOG_DEBUG_FILTERING,
-                                               "%s [ %s ] doesn't contains [ %s ] (case insensitive)\n",
-                                               debug_context, stripped, prop->expr);
-                       }
-                       g_free(stripped);
-               }
-               break;
-               
        default:
                break;
        }
+       
+       if (should_free) {
+               g_free(str1);
+       }
        return ret;
 }