[evolution-data-server/gnome-3-8] Bug #705288 - Custom header search produces error



commit 3215de85a137e5bbc53472f31f018acb4653e35c
Author: Milan Crha <mcrha redhat com>
Date:   Thu Aug 8 17:08:21 2013 +0200

    Bug #705288 - Custom header search produces error

 camel/camel-db.c              |    4 ++--
 camel/camel-folder-search.c   |   21 ++++++++++++---------
 camel/camel-search-sql-sexp.c |   31 ++++++++++++++++++++++++++-----
 3 files changed, 40 insertions(+), 16 deletions(-)
---
diff --git a/camel/camel-db.c b/camel/camel-db.c
index 851bbd1..6aebd61 100644
--- a/camel/camel-db.c
+++ b/camel/camel-db.c
@@ -2339,9 +2339,9 @@ camel_db_get_column_name (const gchar *raw_name)
                return g_strdup ("attachment");
        else if (!g_ascii_strcasecmp (raw_name, "x-camel-mlist"))
                return g_strdup ("mlist");
-       else
-               return g_strdup (raw_name);
 
+       /* indicate the header name is not part of the summary */
+       return NULL;
 }
 
 /**
diff --git a/camel/camel-folder-search.c b/camel/camel-folder-search.c
index 7fe13a9..0373c9b 100644
--- a/camel/camel-folder-search.c
+++ b/camel/camel-folder-search.c
@@ -1765,7 +1765,8 @@ camel_folder_search_set_body_index (CamelFolderSearch *search,
 
 static gboolean
 do_search_in_memory (CamelFolder *search_in_folder,
-                     const gchar *expr)
+                     const gchar *expr,
+                    gchar **psql_query)
 {
        /* if the expression contains any of these tokens, then perform a memory search, instead of the SQL 
one */
        const gchar *in_memory_tokens[] = {
@@ -1794,7 +1795,11 @@ do_search_in_memory (CamelFolder *search_in_folder,
                        return TRUE;
        }
 
-       return FALSE;
+       *psql_query = camel_sexp_to_sql_sexp (expr);
+
+       /* unknown column can cause NULL sql_query, then an in-memory
+          search is required */
+       return !*psql_query;
 }
 
 /**
@@ -1822,7 +1827,7 @@ camel_folder_search_count (CamelFolderSearch *search,
        GPtrArray *summary_set;
        gint i;
        CamelDB *cdb;
-       gchar *sql_query, *tmp, *tmp1;
+       gchar *sql_query = NULL, *tmp, *tmp1;
        GHashTable *results;
        guint32 count = 0;
 
@@ -1844,7 +1849,7 @@ camel_folder_search_count (CamelFolderSearch *search,
        p->error = error;
 
        /* We route body-contains search and thread based search through memory and not via db. */
-       if (do_search_in_memory (search->folder, expr)) {
+       if (do_search_in_memory (search->folder, expr, &sql_query)) {
                /* setup our search list only contains those we're interested in */
                search->summary = camel_folder_get_summary (search->folder);
                if (search->folder->summary)
@@ -1909,9 +1914,8 @@ camel_folder_search_count (CamelFolderSearch *search,
                camel_folder_summary_save_to_db (search->folder->summary, error);
 
                dd (printf ("sexp is : [%s]\n", expr));
-               sql_query = camel_sexp_to_sql_sexp (expr);
                tmp1 = camel_db_sqlize_string (full_name);
-               tmp = g_strdup_printf ("SELECT COUNT (*) FROM %s %s %s", tmp1, sql_query ? "WHERE":"", 
sql_query ? sql_query:"");
+               tmp = g_strdup_printf ("SELECT COUNT (*) FROM %s %s %s", tmp1, sql_query ? "WHERE" : "", 
sql_query ? sql_query : "");
                camel_db_free_sqlized_string (tmp1);
                g_free (sql_query);
                dd (printf ("Equivalent sql %s\n", tmp));
@@ -1978,7 +1982,7 @@ camel_folder_search_search (CamelFolderSearch *search,
        GPtrArray *matches = NULL, *summary_set;
        gint i;
        CamelDB *cdb;
-       gchar *sql_query, *tmp, *tmp1;
+       gchar *sql_query = NULL, *tmp, *tmp1;
        GHashTable *results;
 
        CamelFolderSearchPrivate *p;
@@ -1999,7 +2003,7 @@ camel_folder_search_search (CamelFolderSearch *search,
        p->error = error;
 
        /* We route body-contains / thread based search and uid search through memory and not via db. */
-       if (uids || do_search_in_memory (search->folder, expr)) {
+       if (uids || do_search_in_memory (search->folder, expr, &sql_query)) {
                /* setup our search list only contains those we're interested in */
                search->summary = camel_folder_get_summary (search->folder);
 
@@ -2078,7 +2082,6 @@ camel_folder_search_search (CamelFolderSearch *search,
                camel_folder_summary_save_to_db (search->folder->summary, error);
 
                dd (printf ("sexp is : [%s]\n", expr));
-               sql_query = camel_sexp_to_sql_sexp (expr);
                tmp1 = camel_db_sqlize_string (full_name);
                tmp = g_strdup_printf ("SELECT uid FROM %s %s %s", tmp1, sql_query ? "WHERE":"", sql_query ? 
sql_query:"");
                camel_db_free_sqlized_string (tmp1);
diff --git a/camel/camel-search-sql-sexp.c b/camel/camel-search-sql-sexp.c
index 4007e48..382089b 100644
--- a/camel/camel-search-sql-sexp.c
+++ b/camel/camel-search-sql-sexp.c
@@ -377,6 +377,12 @@ check_header (struct _CamelSExp *f,
 
                /* only a subset of headers are supported .. */
                headername = camel_db_get_column_name (argv[0]->value.string);
+               if (!headername) {
+                       gboolean *pcontains_unknown_column = (gboolean *) data;
+                       *pcontains_unknown_column = TRUE;
+
+                       headername = g_strdup ("unknown");
+               }
 
                /* performs an OR of all words */
                for (i = 1; i < argc; i++) {
@@ -482,9 +488,17 @@ header_exists (struct _CamelSExp *f,
        d (printf ("executing header-exists: %d", argc));
 
        headername = camel_db_get_column_name (argv[0]->value.string);
+       if (!headername) {
+               gboolean *pcontains_unknown_column = (gboolean *) data;
+               *pcontains_unknown_column = TRUE;
+
+               headername = g_strdup ("unknown");
+       }
+
        r = camel_sexp_result_new (f, CAMEL_SEXP_RES_STRING);
        r->value.string = g_strdup_printf ("(%s NOTNULL)", headername);
        g_free (headername);
+
        return r;
 }
 
@@ -553,6 +567,13 @@ system_flag (struct _CamelSExp *f,
                r->value.string = g_strdup ("(0)");
        } else {
                tstr = camel_db_get_column_name (argv[0]->value.string);
+               if (!tstr) {
+                       gboolean *pcontains_unknown_column = (gboolean *) data;
+                       *pcontains_unknown_column = TRUE;
+
+                       tstr = g_strdup ("unknown");
+               }
+
                r->value.string = g_strdup_printf ("(%s = 1)", tstr);
                g_free (tstr);
        }
@@ -716,17 +737,18 @@ camel_sexp_to_sql_sexp (const gchar *sql)
        CamelSExpResult *r;
        gint i;
        gchar *res = NULL;
+       gboolean contains_unknown_column = FALSE;
 
        sexp = camel_sexp_new ();
 
        for (i = 0; i < G_N_ELEMENTS (symbols); i++) {
                if (symbols[i].immediate)
                        camel_sexp_add_ifunction (sexp, 0, symbols[i].name,
-                                            (CamelSExpIFunc) symbols[i].func, NULL);
+                                            (CamelSExpIFunc) symbols[i].func, &contains_unknown_column);
                else
                        camel_sexp_add_function (
                                sexp, 0, symbols[i].name,
-                               symbols[i].func, NULL);
+                               symbols[i].func, &contains_unknown_column);
        }
 
        camel_sexp_input_text (sexp, sql, strlen (sql));
@@ -741,10 +763,9 @@ camel_sexp_to_sql_sexp (const gchar *sql)
                return NULL;
        }
 
-       if (r->type == CAMEL_SEXP_RES_STRING) {
+       if (!contains_unknown_column && r->type == CAMEL_SEXP_RES_STRING) {
                res = g_strdup (r->value.string);
-       } else
-               g_assert (0);
+       }
 
        camel_sexp_result_free (sexp, r);
        g_object_unref (sexp);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]