Whitespace cleanups.
[platform/upstream/evolution-data-server.git] / camel / camel-folder-search.c
index a4f88e6..c72acc8 100644 (file)
 #define r(x)
 #define dd(x) if (camel_debug("search")) x
 
+#define CAMEL_FOLDER_SEARCH_GET_PRIVATE(obj) \
+       (G_TYPE_INSTANCE_GET_PRIVATE \
+       ((obj), CAMEL_TYPE_FOLDER_SEARCH, CamelFolderSearchPrivate))
+
 struct _CamelFolderSearchPrivate {
+       GCancellable *cancellable;
        GError **error;
 
        CamelFolderThread *threads;
        GHashTable *threads_hash;
 };
 
-static ESExpResult *search_not (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *search);
-
-static ESExpResult *search_header_contains (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *search);
-static ESExpResult *search_header_matches (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *search);
-static ESExpResult *search_header_starts_with (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *search);
-static ESExpResult *search_header_ends_with (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *search);
-static ESExpResult *search_header_exists (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *search);
-static ESExpResult *search_header_soundex (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *search);
-static ESExpResult *search_header_regex (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *search);
-static ESExpResult *search_header_full_regex (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *search);
-static ESExpResult *search_match_all (struct _ESExp *f, gint argc, struct _ESExpTerm **argv, CamelFolderSearch *search);
-static ESExpResult *search_match_threads (struct _ESExp *f, gint argc, struct _ESExpTerm **argv, CamelFolderSearch *s);
-static ESExpResult *search_body_contains (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *search);
-static ESExpResult *search_body_regex (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *search);
-static ESExpResult *search_user_flag (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
-static ESExpResult *search_user_tag (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
-static ESExpResult *search_system_flag (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
-static ESExpResult *search_get_sent_date (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
-static ESExpResult *search_get_received_date (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
-static ESExpResult *search_get_current_date (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
-static ESExpResult *search_get_relative_months (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
-static ESExpResult *search_get_size (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
-static ESExpResult *search_uid (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
-static ESExpResult *search_message_location (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
-
-static ESExpResult *search_dummy (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *search);
+static CamelSExpResult *search_not (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *search);
+
+static CamelSExpResult *search_header_contains (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *search);
+static CamelSExpResult *search_header_matches (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *search);
+static CamelSExpResult *search_header_starts_with (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *search);
+static CamelSExpResult *search_header_ends_with (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *search);
+static CamelSExpResult *search_header_exists (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *search);
+static CamelSExpResult *search_header_soundex (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *search);
+static CamelSExpResult *search_header_regex (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *search);
+static CamelSExpResult *search_header_full_regex (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *search);
+static CamelSExpResult *search_match_all (struct _CamelSExp *f, gint argc, struct _CamelSExpTerm **argv, CamelFolderSearch *search);
+static CamelSExpResult *search_match_threads (struct _CamelSExp *f, gint argc, struct _CamelSExpTerm **argv, CamelFolderSearch *s);
+static CamelSExpResult *search_body_contains (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *search);
+static CamelSExpResult *search_body_regex (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *search);
+static CamelSExpResult *search_user_flag (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *s);
+static CamelSExpResult *search_user_tag (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *s);
+static CamelSExpResult *search_system_flag (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *s);
+static CamelSExpResult *search_get_sent_date (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *s);
+static CamelSExpResult *search_get_received_date (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *s);
+static CamelSExpResult *search_get_current_date (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *s);
+static CamelSExpResult *search_get_relative_months (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *s);
+static CamelSExpResult *search_get_size (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *s);
+static CamelSExpResult *search_uid (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *s);
+static CamelSExpResult *search_message_location (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *s);
+
+static CamelSExpResult *search_dummy (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *search);
 
 static gint read_uid_callback (gpointer  ref, gint ncol, gchar ** cols, gchar **name);
 
@@ -101,7 +106,7 @@ folder_search_dispose (GObject *object)
        CamelFolderSearch *search = CAMEL_FOLDER_SEARCH (object);
 
        if (search->sexp != NULL) {
-               e_sexp_unref (search->sexp);
+               g_object_unref (search->sexp);
                search->sexp = NULL;
        }
 
@@ -159,9 +164,8 @@ camel_folder_search_class_init (CamelFolderSearchClass *class)
 static void
 camel_folder_search_init (CamelFolderSearch *search)
 {
-       search->priv = G_TYPE_INSTANCE_GET_PRIVATE (
-               search, CAMEL_TYPE_FOLDER_SEARCH, CamelFolderSearchPrivate);
-       search->sexp = e_sexp_new ();
+       search->priv = CAMEL_FOLDER_SEARCH_GET_PRIVATE (search);
+       search->sexp = camel_sexp_new ();
 }
 
 static struct {
@@ -222,9 +226,9 @@ camel_folder_search_construct (CamelFolderSearch *search)
                }
                if (func != NULL) {
                        if (builtins[i].flags&2) {
-                               e_sexp_add_ifunction (search->sexp, 0, builtins[i].name, (ESExpIFunc *) func, search);
+                               camel_sexp_add_ifunction (search->sexp, 0, builtins[i].name, (CamelSExpIFunc) func, search);
                        } else {
-                               e_sexp_add_function (search->sexp, 0, builtins[i].name, (ESExpFunc *) func, search);
+                               camel_sexp_add_function (search->sexp, 0, builtins[i].name, (CamelSExpFunc) func, search);
                        }
                }
        }
@@ -266,6 +270,9 @@ void
 camel_folder_search_set_folder (CamelFolderSearch *search,
                                 CamelFolder *folder)
 {
+       g_return_if_fail (CAMEL_IS_FOLDER_SEARCH (search));
+       g_return_if_fail (CAMEL_IS_FOLDER (folder));
+
        search->folder = folder;
 }
 
@@ -283,13 +290,15 @@ void
 camel_folder_search_set_summary (CamelFolderSearch *search,
                                  GPtrArray *summary)
 {
+       g_return_if_fail (CAMEL_IS_FOLDER_SEARCH (search));
+
        search->summary = summary;
 }
 
 /**
  * camel_folder_search_set_body_index:
  * @search:
- * @index:
+ * @body_index:
  *
  * Set the index representing the contents of all messages
  * in this folder.  If this is not set, then the folder implementation
@@ -298,120 +307,26 @@ camel_folder_search_set_summary (CamelFolderSearch *search,
  **/
 void
 camel_folder_search_set_body_index (CamelFolderSearch *search,
-                                    CamelIndex *index)
+                                    CamelIndex *body_index)
 {
-       if (search->body_index)
-               g_object_unref (search->body_index);
-       search->body_index = index;
-       if (index)
-               g_object_ref (index);
-}
+       g_return_if_fail (CAMEL_IS_FOLDER_SEARCH (search));
 
-/**
- * camel_folder_search_execute_expression:
- * @search:
- * @expr:
- * @error: return location for a #GError, or %NULL
- *
- * Execute the search expression @expr, returning an array of
- * all matches as a GPtrArray of uid's of matching messages.
- *
- * Note that any settings such as set_body_index(), set_folder(),
- * and so on are reset to %NULL once the search has completed.
- *
- * TODO: The interface should probably return summary items instead
- * (since they are much more useful to any client).
- *
- * Returns: A GPtrArray of strings of all matching messages.
- * This must only be freed by camel_folder_search_free_result.
- **/
-GPtrArray *
-camel_folder_search_execute_expression (CamelFolderSearch *search,
-                                        const gchar *expr,
-                                        GError **error)
-{
-       ESExpResult *r;
-       GPtrArray *matches;
-       gint i;
-       GHashTable *results;
-       CamelFolderSearchPrivate *p = search->priv;
-
-       p->error = error;
-
-       /* only re-parse if the search has changed */
-       if (search->last_search == NULL
-           || strcmp (search->last_search, expr)) {
-               e_sexp_input_text (search->sexp, expr, strlen (expr));
-               if (e_sexp_parse (search->sexp) == -1) {
-                       g_set_error (
-                               error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
-                               _("Cannot parse search expression: %s:\n%s"),
-                               e_sexp_error (search->sexp), expr);
-                       return NULL;
-               }
-
-               g_free (search->last_search);
-               search->last_search = g_strdup (expr);
-       }
-       r = e_sexp_eval (search->sexp);
-       if (r == NULL) {
-               g_set_error (
-                       error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
-                       _("Error executing search expression: %s:\n%s"),
-                       e_sexp_error (search->sexp), expr);
-               return NULL;
+       if (body_index != NULL) {
+               g_return_if_fail (CAMEL_IS_INDEX (body_index));
+               g_object_ref (body_index);
        }
 
-       matches = g_ptr_array_new ();
-
-       /* now create a folder summary to return?? */
-       if (r->type == ESEXP_RES_ARRAY_PTR) {
-               d(printf("got result ...\n"));
-               if (search->summary) {
-                       /* reorder result in summary order */
-                       results = g_hash_table_new (g_str_hash, g_str_equal);
-                       for (i = 0; i < r->value.ptrarray->len; i++) {
-                               d(printf("adding match: %s\n", (gchar *)g_ptr_array_index(r->value.ptrarray, i)));
-                               g_hash_table_insert (results, g_ptr_array_index (r->value.ptrarray, i), GINT_TO_POINTER (1));
-                       }
-                       for (i = 0; i < search->summary->len; i++) {
-                               gchar *uid = g_ptr_array_index (search->summary, i);
-                               if (g_hash_table_lookup (results, uid)) {
-                                       g_ptr_array_add (matches, (gpointer) camel_pstring_strdup (uid));
-                               }
-                       }
-                       g_hash_table_destroy (results);
-               } else {
-                       for (i = 0; i < r->value.ptrarray->len; i++) {
-                               d(printf("adding match: %s\n", (gchar *)g_ptr_array_index(r->value.ptrarray, i)));
-                               g_ptr_array_add (matches, (gpointer) camel_pstring_strdup (g_ptr_array_index (r->value.ptrarray, i)));
-                       }
-               }
-       } else {
-               g_warning("Search returned an invalid result type");
-       }
-
-       e_sexp_result_free (search->sexp, r);
-
-       if (p->threads)
-               camel_folder_thread_messages_unref (p->threads);
-       if (p->threads_hash)
-               g_hash_table_destroy (p->threads_hash);
-
-       p->threads = NULL;
-       p->threads_hash = NULL;
-       search->folder = NULL;
-       search->summary = NULL;
-       search->current = NULL;
-       search->body_index = NULL;
+       if (search->body_index != NULL)
+               g_object_unref (search->body_index);
 
-       return matches;
+       search->body_index = body_index;
 }
 
 /**
  * camel_folder_search_count:
  * @search:
  * @expr:
+ * @cancellable: a #GCancellable
  * @error: return location for a #GError, or %NULL
  *
  * Run a search.  Search must have had Folder already set on it, and
@@ -425,9 +340,10 @@ camel_folder_search_execute_expression (CamelFolderSearch *search,
 guint32
 camel_folder_search_count (CamelFolderSearch *search,
                            const gchar *expr,
+                           GCancellable *cancellable,
                            GError **error)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        GPtrArray *summary_set;
        gint i;
        CamelDB *cdb;
@@ -435,10 +351,15 @@ camel_folder_search_count (CamelFolderSearch *search,
        GHashTable *results;
        guint32 count = 0;
 
-       CamelFolderSearchPrivate *p = search->priv;
+       CamelFolderSearchPrivate *p;
+
+       g_return_val_if_fail (search != NULL, 0);
+
+       p = search->priv;
 
        g_assert (search->folder);
 
+       p->cancellable = cancellable;
        p->error = error;
 
        /* We route body-contains search and thread based search through memory and not via db. */
@@ -451,29 +372,29 @@ camel_folder_search_count (CamelFolderSearch *search,
                /* only re-parse if the search has changed */
                if (search->last_search == NULL
                    || strcmp (search->last_search, expr)) {
-                       e_sexp_input_text (search->sexp, expr, strlen (expr));
-                       if (e_sexp_parse (search->sexp) == -1) {
+                       camel_sexp_input_text (search->sexp, expr, strlen (expr));
+                       if (camel_sexp_parse (search->sexp) == -1) {
                                g_set_error (
                                        error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
                                        _("Cannot parse search expression: %s:\n%s"),
-                                       e_sexp_error (search->sexp), expr);
+                                       camel_sexp_error (search->sexp), expr);
                                goto fail;
                        }
 
                        g_free (search->last_search);
                        search->last_search = g_strdup (expr);
                }
-               r = e_sexp_eval (search->sexp);
+               r = camel_sexp_eval (search->sexp);
                if (r == NULL) {
                        g_set_error (
                                error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
                                _("Error executing search expression: %s:\n%s"),
-                               e_sexp_error (search->sexp), expr);
+                               camel_sexp_error (search->sexp), expr);
                        goto fail;
                }
 
                /* now create a folder summary to return?? */
-               if (r->type == ESEXP_RES_ARRAY_PTR) {
+               if (r->type == CAMEL_SEXP_RES_ARRAY_PTR) {
                        d(printf("got result\n"));
 
                        /* reorder result in summary order */
@@ -491,7 +412,7 @@ camel_folder_search_count (CamelFolderSearch *search,
                        g_hash_table_destroy (results);
                }
 
-               e_sexp_result_free (search->sexp, r);
+               camel_sexp_result_free (search->sexp, r);
 
        } else {
                CamelStore *parent_store;
@@ -540,6 +461,8 @@ fail:
        if (search->summary)
                camel_folder_free_summary (search->folder, search->summary);
 
+       p->cancellable = NULL;
+       p->error = NULL;
        p->threads = NULL;
        p->threads_hash = NULL;
        search->folder = NULL;
@@ -555,7 +478,17 @@ static gboolean
 do_search_in_memory (const gchar *expr)
 {
        /* if the expression contains any of these tokens, then perform a memory search, instead of the SQL one */
-       const gchar *in_memory_tokens[] = { "body-contains", "body-regex", "match-threads", "message-location", "header-soundex", "header-regex", "header-full-regex", "header-contains", NULL };
+       const gchar *in_memory_tokens[] = {
+               "body-contains",
+               "body-regex",
+               "match-threads",
+               "message-location",
+               "header-soundex",
+               "header-regex",
+               "header-full-regex",
+               "header-contains",
+               "header-has-words",
+               NULL };
        gint i;
 
        if (!expr)
@@ -574,6 +507,7 @@ do_search_in_memory (const gchar *expr)
  * @search:
  * @expr:
  * @uids: to search against, NULL for all uid's.
+ * @cancellable: a #GCancellable
  * @error: return location for a #GError, or %NULL
  *
  * Run a search.  Search must have had Folder already set on it, and
@@ -585,19 +519,25 @@ GPtrArray *
 camel_folder_search_search (CamelFolderSearch *search,
                             const gchar *expr,
                             GPtrArray *uids,
+                            GCancellable *cancellable,
                             GError **error)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        GPtrArray *matches = NULL, *summary_set;
        gint i;
        CamelDB *cdb;
        gchar *sql_query, *tmp, *tmp1;
        GHashTable *results;
 
-       CamelFolderSearchPrivate *p = search->priv;
+       CamelFolderSearchPrivate *p;
+
+       g_return_val_if_fail (search != NULL, NULL);
+
+       p = search->priv;
 
        g_assert (search->folder);
 
+       p->cancellable = cancellable;
        p->error = error;
 
        /* We route body-contains / thread based search and uid search through memory and not via db. */
@@ -622,31 +562,31 @@ camel_folder_search_search (CamelFolderSearch *search,
                /* only re-parse if the search has changed */
                if (search->last_search == NULL
                    || strcmp (search->last_search, expr)) {
-                       e_sexp_input_text (search->sexp, expr, strlen (expr));
-                       if (e_sexp_parse (search->sexp) == -1) {
+                       camel_sexp_input_text (search->sexp, expr, strlen (expr));
+                       if (camel_sexp_parse (search->sexp) == -1) {
                                g_set_error (
                                        error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
                                        _("Cannot parse search expression: %s:\n%s"),
-                                       e_sexp_error (search->sexp), expr);
+                                       camel_sexp_error (search->sexp), expr);
                                goto fail;
                        }
 
                        g_free (search->last_search);
                        search->last_search = g_strdup (expr);
                }
-               r = e_sexp_eval (search->sexp);
+               r = camel_sexp_eval (search->sexp);
                if (r == NULL) {
                        g_set_error (
                                error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
                                _("Error executing search expression: %s:\n%s"),
-                               e_sexp_error (search->sexp), expr);
+                               camel_sexp_error (search->sexp), expr);
                        goto fail;
                }
 
                matches = g_ptr_array_new ();
 
                /* now create a folder summary to return?? */
-               if (r->type == ESEXP_RES_ARRAY_PTR) {
+               if (r->type == CAMEL_SEXP_RES_ARRAY_PTR) {
                        d(printf("got result\n"));
 
                        /* reorder result in summary order */
@@ -664,7 +604,7 @@ camel_folder_search_search (CamelFolderSearch *search,
                        g_hash_table_destroy (results);
                }
 
-               e_sexp_result_free (search->sexp, r);
+               camel_sexp_result_free (search->sexp, r);
 
        } else {
                CamelStore *parent_store;
@@ -717,6 +657,8 @@ fail:
        if (search->summary)
                camel_folder_free_summary (search->folder, search->summary);
 
+       p->cancellable = NULL;
+       p->error = NULL;
        p->threads = NULL;
        p->threads_hash = NULL;
        search->folder = NULL;
@@ -735,19 +677,19 @@ void camel_folder_search_free_result (CamelFolderSearch *search, GPtrArray *resu
 }
 
 /* dummy function, returns false always, or an empty match array */
-static ESExpResult *
-search_dummy (struct _ESExp *f,
+static CamelSExpResult *
+search_dummy (struct _CamelSExp *f,
               gint argc,
-              struct _ESExpResult **argv,
+              struct _CamelSExpResult **argv,
               CamelFolderSearch *search)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
 
        if (search->current == NULL) {
-               r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
                r->value.boolean = FALSE;
        } else {
-               r = e_sexp_result_new (f, ESEXP_RES_ARRAY_PTR);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_ARRAY_PTR);
                r->value.ptrarray = g_ptr_array_new ();
        }
 
@@ -755,21 +697,21 @@ search_dummy (struct _ESExp *f,
 }
 
 /* impelemnt an 'array not', i.e. everything in the summary, not in the supplied array */
-static ESExpResult *
-search_not (struct _ESExp *f,
+static CamelSExpResult *
+search_not (struct _CamelSExp *f,
             gint argc,
-            struct _ESExpResult **argv,
+            struct _CamelSExpResult **argv,
             CamelFolderSearch *search)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        gint i;
 
        if (argc > 0) {
-               if (argv[0]->type == ESEXP_RES_ARRAY_PTR) {
+               if (argv[0]->type == CAMEL_SEXP_RES_ARRAY_PTR) {
                        GPtrArray *v = argv[0]->value.ptrarray;
                        const gchar *uid;
 
-                       r = e_sexp_result_new (f, ESEXP_RES_ARRAY_PTR);
+                       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_ARRAY_PTR);
                        r->value.ptrarray = g_ptr_array_new ();
 
                        /* not against a single message?*/
@@ -809,28 +751,28 @@ search_not (struct _ESExp *f,
                } else {
                        gint res = TRUE;
 
-                       if (argv[0]->type == ESEXP_RES_BOOL)
+                       if (argv[0]->type == CAMEL_SEXP_RES_BOOL)
                                res = !argv[0]->value.boolean;
 
-                       r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+                       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
                        r->value.boolean = res;
                }
        } else {
-               r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
                r->value.boolean = TRUE;
        }
 
        return r;
 }
 
-static ESExpResult *
-search_match_all (struct _ESExp *f,
+static CamelSExpResult *
+search_match_all (struct _CamelSExp *f,
                   gint argc,
-                  struct _ESExpTerm **argv,
+                  struct _CamelSExpTerm **argv,
                   CamelFolderSearch *search)
 {
        gint i;
-       ESExpResult *r, *r1;
+       CamelSExpResult *r, *r1;
        gchar *error_msg;
        GPtrArray *v;
 
@@ -842,28 +784,28 @@ search_match_all (struct _ESExp *f,
        if (search->current) {
                d(printf("matching against 1 message: %s\n", camel_message_info_subject(search->current)));
 
-               r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
                r->value.boolean = FALSE;
 
                if (argc > 0) {
-                       r1 = e_sexp_term_eval (f, argv[0]);
-                       if (r1->type == ESEXP_RES_BOOL) {
+                       r1 = camel_sexp_term_eval (f, argv[0]);
+                       if (r1->type == CAMEL_SEXP_RES_BOOL) {
                                r->value.boolean = r1->value.boolean;
                        } else {
                                g_warning("invalid syntax, matches require a single bool result");
                                /* Translators: The '%s' is an element type name, part of an expressing language */
                                error_msg = g_strdup_printf(_("(%s) requires a single bool result"), "match-all");
-                               e_sexp_fatal_error (f, error_msg);
+                               camel_sexp_fatal_error (f, error_msg);
                                g_free (error_msg);
                        }
-                       e_sexp_result_free (f, r1);
+                       camel_sexp_result_free (f, r1);
                } else {
                        r->value.boolean = TRUE;
                }
                return r;
        }
 
-       r = e_sexp_result_new (f, ESEXP_RES_ARRAY_PTR);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_ARRAY_PTR);
        r->value.ptrarray = g_ptr_array_new ();
 
        if (search->summary == NULL) {
@@ -879,7 +821,7 @@ search_match_all (struct _ESExp *f,
                camel_folder_summary_prepare_fetch_all (search->folder->summary, search->priv->error);
        }
 
-       for (i = 0; i < v->len; i++) {
+       for (i = 0; i < v->len && !g_cancellable_is_cancelled (search->priv->cancellable); i++) {
                const gchar *uid;
 
                search->current = camel_folder_summary_get (search->folder->summary, v->pdata[i]);
@@ -888,18 +830,18 @@ search_match_all (struct _ESExp *f,
                uid = camel_message_info_uid (search->current);
 
                if (argc > 0) {
-                       r1 = e_sexp_term_eval (f, argv[0]);
-                       if (r1->type == ESEXP_RES_BOOL) {
+                       r1 = camel_sexp_term_eval (f, argv[0]);
+                       if (r1->type == CAMEL_SEXP_RES_BOOL) {
                                if (r1->value.boolean)
                                        g_ptr_array_add (r->value.ptrarray, (gchar *) uid);
                        } else {
                                g_warning("invalid syntax, matches require a single bool result");
                                /* Translators: The '%s' is an element type name, part of an expressing language */
                                error_msg = g_strdup_printf(_("(%s) requires a single bool result"), "match-all");
-                               e_sexp_fatal_error (f, error_msg);
+                               camel_sexp_fatal_error (f, error_msg);
                                g_free (error_msg);
                        }
-                       e_sexp_result_free (f, r1);
+                       camel_sexp_result_free (f, r1);
                } else {
                        g_ptr_array_add (r->value.ptrarray, (gchar *) uid);
                }
@@ -941,13 +883,13 @@ add_results (gchar *uid,
        g_ptr_array_add (result, uid);
 }
 
-static ESExpResult *
-search_match_threads (struct _ESExp *f,
+static CamelSExpResult *
+search_match_threads (struct _CamelSExp *f,
                       gint argc,
-                      struct _ESExpTerm **argv,
+                      struct _CamelSExpTerm **argv,
                       CamelFolderSearch *search)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        CamelFolderSearchPrivate *p = search->priv;
        gint i, type;
        GHashTable *results;
@@ -957,22 +899,22 @@ search_match_threads (struct _ESExp *f,
        if (search->current) {
                /* Translators: Each '%s' is an element type name, part of an expressing language */
                error_msg = g_strdup_printf(_("(%s) not allowed inside %s"), "match-threads", "match-all");
-               e_sexp_fatal_error (f, error_msg);
+               camel_sexp_fatal_error (f, error_msg);
                g_free (error_msg);
        }
 
        if (argc == 0) {
                /* Translators: The '%s' is an element type name, part of an expressing language */
                error_msg = g_strdup_printf(_("(%s) requires a match type string"), "match-threads");
-               e_sexp_fatal_error (f, error_msg);
+               camel_sexp_fatal_error (f, error_msg);
                g_free (error_msg);
        }
 
-       r = e_sexp_term_eval (f, argv[0]);
-       if (r->type != ESEXP_RES_STRING) {
+       r = camel_sexp_term_eval (f, argv[0]);
+       if (r->type != CAMEL_SEXP_RES_STRING) {
                /* Translators: The '%s' is an element type name, part of an expressing language */
                error_msg = g_strdup_printf(_("(%s) requires a match type string"), "match-threads");
-               e_sexp_fatal_error (f, error_msg);
+               camel_sexp_fatal_error (f, error_msg);
                g_free (error_msg);
        }
 
@@ -987,20 +929,20 @@ search_match_threads (struct _ESExp *f,
                type = 3;
        else if (!strcmp(r->value.string, "single"))
                type = 4;
-       e_sexp_result_free (f, r);
+       camel_sexp_result_free (f, r);
 
        /* behave as (begin does */
        r = NULL;
        for (i = 1; i < argc; i++) {
                if (r)
-                       e_sexp_result_free (f, r);
-               r = e_sexp_term_eval (f, argv[i]);
+                       camel_sexp_result_free (f, r);
+               r = camel_sexp_term_eval (f, argv[i]);
        }
 
-       if (r == NULL || r->type != ESEXP_RES_ARRAY_PTR) {
+       if (r == NULL || r->type != CAMEL_SEXP_RES_ARRAY_PTR) {
                /* Translators: The '%s' is an element type name, part of an expressing language */
                error_msg = g_strdup_printf(_("(%s) expects an array result"), "match-threads");
-               e_sexp_fatal_error (f, error_msg);
+               camel_sexp_fatal_error (f, error_msg);
                g_free (error_msg);
        }
 
@@ -1010,7 +952,7 @@ search_match_threads (struct _ESExp *f,
        if (search->folder == NULL) {
                /* Translators: The '%s' is an element type name, part of an expressing language */
                error_msg = g_strdup_printf(_("(%s) requires the folder set"), "match-threads");
-               e_sexp_fatal_error (f, error_msg);
+               camel_sexp_fatal_error (f, error_msg);
                g_free (error_msg);
        }
 
@@ -1053,9 +995,9 @@ search_match_threads (struct _ESExp *f,
                                add_thread_results (node->child, results);
                }
        }
-       e_sexp_result_free (f, r);
+       camel_sexp_result_free (f, r);
 
-       r = e_sexp_result_new (f, ESEXP_RES_ARRAY_PTR);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_ARRAY_PTR);
        r->value.ptrarray = g_ptr_array_new ();
 
        g_hash_table_foreach (results, (GHFunc) add_results, r->value.ptrarray);
@@ -1070,26 +1012,25 @@ get_current_message (CamelFolderSearch *search)
        if (!search || !search->folder || !search->current)
                return NULL;
 
-       /* FIXME Pass a GCancellable */
        return camel_folder_get_message_sync (
-               search->folder, search->current->uid, NULL, NULL);
+               search->folder, search->current->uid, search->priv->cancellable, NULL);
 }
 
-static ESExpResult *
-check_header (struct _ESExp *f,
+static CamelSExpResult *
+check_header (struct _CamelSExp *f,
               gint argc,
-              struct _ESExpResult **argv,
+              struct _CamelSExpResult **argv,
               CamelFolderSearch *search,
               camel_search_match_t how)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        gint truth = FALSE;
 
        r(printf("executing check-header %d\n", how));
 
        /* are we inside a match-all? */
        if (search->current && argc > 1
-           && argv[0]->type == ESEXP_RES_STRING) {
+           && argv[0]->type == CAMEL_SEXP_RES_STRING) {
                gchar *headername;
                const gchar *header = NULL, *charset = NULL;
                gchar strbuf[32];
@@ -1136,7 +1077,7 @@ check_header (struct _ESExp *f,
 
                /* performs an OR of all words */
                for (i = 1; i < argc && !truth; i++) {
-                       if (argv[i]->type == ESEXP_RES_STRING) {
+                       if (argv[i]->type == CAMEL_SEXP_RES_STRING) {
                                if (argv[i]->value.string[0] == 0) {
                                        truth = TRUE;
                                } else if (how == CAMEL_SEARCH_MATCH_CONTAINS) {
@@ -1175,7 +1116,7 @@ check_header (struct _ESExp *f,
        }
        /* TODO: else, find all matches */
 
-       r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
        r->value.boolean = truth;
 
        return r;
@@ -1189,81 +1130,81 @@ printf("%s\t", node);
 }
 */
 
-static ESExpResult *
-search_header_contains (struct _ESExp *f,
+static CamelSExpResult *
+search_header_contains (struct _CamelSExp *f,
                         gint argc,
-                        struct _ESExpResult **argv,
+                        struct _CamelSExpResult **argv,
                         CamelFolderSearch *search)
 {
        return check_header (f, argc, argv, search, CAMEL_SEARCH_MATCH_CONTAINS);
 }
 
-static ESExpResult *
-search_header_matches (struct _ESExp *f,
+static CamelSExpResult *
+search_header_matches (struct _CamelSExp *f,
                        gint argc,
-                       struct _ESExpResult **argv,
+                       struct _CamelSExpResult **argv,
                        CamelFolderSearch *search)
 {
        return check_header (f, argc, argv, search, CAMEL_SEARCH_MATCH_EXACT);
 }
 
-static ESExpResult *
-search_header_starts_with (struct _ESExp *f,
+static CamelSExpResult *
+search_header_starts_with (struct _CamelSExp *f,
                            gint argc,
-                           struct _ESExpResult **argv,
+                           struct _CamelSExpResult **argv,
                            CamelFolderSearch *search)
 {
        return check_header (f, argc, argv, search, CAMEL_SEARCH_MATCH_STARTS);
 }
 
-static ESExpResult *
-search_header_ends_with (struct _ESExp *f,
+static CamelSExpResult *
+search_header_ends_with (struct _CamelSExp *f,
                          gint argc,
-                         struct _ESExpResult **argv,
+                         struct _CamelSExpResult **argv,
                          CamelFolderSearch *search)
 {
        return check_header (f, argc, argv, search, CAMEL_SEARCH_MATCH_ENDS);
 }
 
-static ESExpResult *
-search_header_exists (struct _ESExp *f,
+static CamelSExpResult *
+search_header_exists (struct _CamelSExp *f,
                       gint argc,
-                      struct _ESExpResult **argv,
+                      struct _CamelSExpResult **argv,
                       CamelFolderSearch *search)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
 
        r(printf ("executing header-exists\n"));
 
        if (search->current) {
-               r = e_sexp_result_new (f, ESEXP_RES_BOOL);
-               if (argc == 1 && argv[0]->type == ESEXP_RES_STRING)
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
+               if (argc == 1 && argv[0]->type == CAMEL_SEXP_RES_STRING)
                        r->value.boolean = camel_medium_get_header (CAMEL_MEDIUM (search->current), argv[0]->value.string) != NULL;
 
        } else {
-               r = e_sexp_result_new (f, ESEXP_RES_ARRAY_PTR);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_ARRAY_PTR);
                r->value.ptrarray = g_ptr_array_new ();
        }
 
        return r;
 }
 
-static ESExpResult *
-search_header_soundex (struct _ESExp *f,
+static CamelSExpResult *
+search_header_soundex (struct _CamelSExp *f,
                        gint argc,
-                       struct _ESExpResult **argv,
+                       struct _CamelSExpResult **argv,
                        CamelFolderSearch *search)
 {
        return check_header (f, argc, argv, search, CAMEL_SEARCH_MATCH_SOUNDEX);
 }
 
-static ESExpResult *
-search_header_regex (struct _ESExp *f,
+static CamelSExpResult *
+search_header_regex (struct _CamelSExp *f,
                      gint argc,
-                     struct _ESExpResult **argv,
+                     struct _CamelSExpResult **argv,
                      CamelFolderSearch *search)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        CamelMimeMessage *msg;
 
        msg = get_current_message (search);
@@ -1272,9 +1213,9 @@ search_header_regex (struct _ESExp *f,
                regex_t pattern;
                const gchar *contents;
 
-               r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
 
-               if (argc > 1 && argv[0]->type == ESEXP_RES_STRING
+               if (argc > 1 && argv[0]->type == CAMEL_SEXP_RES_STRING
                    && (contents = camel_medium_get_header (CAMEL_MEDIUM (msg), argv[0]->value.string))
                    && camel_search_build_match_regex (&pattern, CAMEL_SEARCH_MATCH_REGEX | CAMEL_SEARCH_MATCH_ICASE, argc - 1, argv + 1, search->priv->error) == 0) {
                        r->value.boolean = regexec (&pattern, contents, 0, NULL, 0) == 0;
@@ -1284,7 +1225,7 @@ search_header_regex (struct _ESExp *f,
 
                g_object_unref (msg);
        } else {
-               r = e_sexp_result_new (f, ESEXP_RES_ARRAY_PTR);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_ARRAY_PTR);
                r->value.ptrarray = g_ptr_array_new ();
        }
 
@@ -1313,13 +1254,13 @@ get_full_header (CamelMimeMessage *message)
        return g_string_free (str, FALSE);
 }
 
-static ESExpResult *
-search_header_full_regex (struct _ESExp *f,
+static CamelSExpResult *
+search_header_full_regex (struct _CamelSExp *f,
                           gint argc,
-                          struct _ESExpResult **argv,
+                          struct _CamelSExpResult **argv,
                           CamelFolderSearch *search)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        CamelMimeMessage *msg;
 
        msg = get_current_message (search);
@@ -1327,7 +1268,7 @@ search_header_full_regex (struct _ESExp *f,
        if (msg) {
                regex_t pattern;
 
-               r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
 
                if (camel_search_build_match_regex (&pattern, CAMEL_SEARCH_MATCH_REGEX | CAMEL_SEARCH_MATCH_ICASE | CAMEL_SEARCH_MATCH_NEWLINE, argc, argv, search->priv->error) == 0) {
                        gchar *contents;
@@ -1342,7 +1283,7 @@ search_header_full_regex (struct _ESExp *f,
 
                g_object_unref (msg);
        } else {
-               r = e_sexp_result_new (f, ESEXP_RES_ARRAY_PTR);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_ARRAY_PTR);
                r->value.ptrarray = g_ptr_array_new ();
        }
 
@@ -1461,7 +1402,8 @@ match_words_index (CamelFolderSearch *search,
 static gboolean
 match_words_1message (CamelDataWrapper *object,
                       struct _camel_search_words *words,
-                      guint32 *mask)
+                      guint32 *mask,
+                      GCancellable *cancellable)
 {
        CamelDataWrapper *containee;
        gint truth = FALSE;
@@ -1478,11 +1420,11 @@ match_words_1message (CamelDataWrapper *object,
                for (i = 0; i < parts && truth == FALSE; i++) {
                        CamelDataWrapper *part = (CamelDataWrapper *) camel_multipart_get_part (CAMEL_MULTIPART (containee), i);
                        if (part)
-                               truth = match_words_1message (part, words, mask);
+                               truth = match_words_1message (part, words, mask, cancellable);
                }
        } else if (CAMEL_IS_MIME_MESSAGE (containee)) {
                /* for messages we only look at its contents */
-               truth = match_words_1message ((CamelDataWrapper *) containee, words, mask);
+               truth = match_words_1message ((CamelDataWrapper *) containee, words, mask, cancellable);
        } else if (camel_content_type_is(CAMEL_DATA_WRAPPER (containee)->mime_type, "text", "*")) {
                /* for all other text parts, we look inside, otherwise we dont care */
                CamelStream *stream;
@@ -1492,9 +1434,8 @@ match_words_1message (CamelDataWrapper *object,
                stream = camel_stream_mem_new_with_byte_array (byte_array);
 
                /* FIXME The match should be part of a stream op */
-               /* FIXME Pass a GCancellable and GError here. */
                camel_data_wrapper_decode_to_stream_sync (
-                       containee, stream, NULL, NULL);
+                       containee, stream, cancellable, NULL);
                camel_stream_write (stream, "", 1, NULL, NULL);
                for (i = 0; i < words->len; i++) {
                        /* FIXME: This is horridly slow, and should use a real search algorithm */
@@ -1526,7 +1467,7 @@ match_words_message (CamelFolder *folder,
        msg = camel_folder_get_message_sync (folder, uid, cancellable, error);
        if (msg) {
                mask = 0;
-               truth = match_words_1message ((CamelDataWrapper *) msg, words, &mask);
+               truth = match_words_1message ((CamelDataWrapper *) msg, words, &mask, cancellable);
                g_object_unref (msg);
        }
 
@@ -1576,16 +1517,16 @@ match_words_messages (CamelFolderSearch *search,
        return matches;
 }
 
-static ESExpResult *
-search_body_contains (struct _ESExp *f,
+static CamelSExpResult *
+search_body_contains (struct _CamelSExp *f,
                       gint argc,
-                      struct _ESExpResult **argv,
+                      struct _CamelSExpResult **argv,
                       CamelFolderSearch *search)
 {
        gint i, j;
        GError **error = search->priv->error;
        struct _camel_search_words *words;
-       ESExpResult *r;
+       CamelSExpResult *r;
        struct IterData lambdafoo;
 
        if (search->current) {
@@ -1595,7 +1536,7 @@ search_body_contains (struct _ESExp *f,
                        truth = TRUE;
                } else {
                        for (i = 0; i < argc && !truth; i++) {
-                               if (argv[i]->type == ESEXP_RES_STRING) {
+                               if (argv[i]->type == CAMEL_SEXP_RES_STRING) {
                                        words = camel_search_words_split ((const guchar *) argv[i]->value.string);
                                        truth = TRUE;
                                        if ((words->type & CAMEL_SEARCH_WORD_COMPLEX) == 0 && search->body_index) {
@@ -1603,17 +1544,16 @@ search_body_contains (struct _ESExp *f,
                                                        truth = match_message_index (search->body_index, camel_message_info_uid (search->current), words->words[j]->word, error);
                                        } else {
                                                /* TODO: cache current message incase of multiple body search terms */
-                                               /* FIXME Pass a GCancellable */
-                                               truth = match_words_message (search->folder, camel_message_info_uid (search->current), words, NULL, error);
+                                               truth = match_words_message (search->folder, camel_message_info_uid (search->current), words, search->priv->cancellable, error);
                                        }
                                        camel_search_words_free (words);
                                }
                        }
                }
-               r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
                r->value.boolean = truth;
        } else {
-               r = e_sexp_result_new (f, ESEXP_RES_ARRAY_PTR);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_ARRAY_PTR);
                r->value.ptrarray = g_ptr_array_new ();
 
                if (argc == 1 && argv[0]->value.string[0] == 0) {
@@ -1629,13 +1569,12 @@ search_body_contains (struct _ESExp *f,
                        GPtrArray *matches;
 
                        for (i = 0; i < argc; i++) {
-                               if (argv[i]->type == ESEXP_RES_STRING) {
+                               if (argv[i]->type == CAMEL_SEXP_RES_STRING) {
                                        words = camel_search_words_split ((const guchar *) argv[i]->value.string);
                                        if ((words->type & CAMEL_SEARCH_WORD_COMPLEX) == 0 && search->body_index) {
                                                matches = match_words_index (search, words, error);
                                        } else {
-                                               /* FIXME Pass a GCancellable */
-                                               matches = match_words_messages (search, words, NULL, error);
+                                               matches = match_words_messages (search, words, search->priv->cancellable, error);
                                        }
                                        for (j = 0; j < matches->len; j++) {
                                                g_hash_table_insert (ht, matches->pdata[j], matches->pdata[j]);
@@ -1653,19 +1592,19 @@ search_body_contains (struct _ESExp *f,
        return r;
 }
 
-static ESExpResult *
-search_body_regex (struct _ESExp *f,
+static CamelSExpResult *
+search_body_regex (struct _CamelSExp *f,
                    gint argc,
-                   struct _ESExpResult **argv,
+                   struct _CamelSExpResult **argv,
                    CamelFolderSearch *search)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        CamelMimeMessage *msg = get_current_message (search);
 
        if (msg) {
                regex_t pattern;
 
-               r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
 
                if (camel_search_build_match_regex (&pattern, CAMEL_SEARCH_MATCH_ICASE | CAMEL_SEARCH_MATCH_REGEX | CAMEL_SEARCH_MATCH_NEWLINE, argc, argv, search->priv->error) == 0) {
                        r->value.boolean = camel_search_message_body_contains ((CamelDataWrapper *) msg, &pattern);
@@ -1677,7 +1616,7 @@ search_body_regex (struct _ESExp *f,
        } else {
                regex_t pattern;
 
-               r = e_sexp_result_new (f, ESEXP_RES_ARRAY_PTR);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_ARRAY_PTR);
                r->value.ptrarray = g_ptr_array_new ();
 
                if (camel_search_build_match_regex (&pattern, CAMEL_SEARCH_MATCH_ICASE | CAMEL_SEARCH_MATCH_REGEX | CAMEL_SEARCH_MATCH_NEWLINE, argc, argv, search->priv->error) == 0) {
@@ -1685,12 +1624,11 @@ search_body_regex (struct _ESExp *f,
                        GPtrArray *v = search->summary_set ? search->summary_set : search->summary;
                        CamelMimeMessage *message;
 
-                       for (i = 0; i < v->len; i++) {
+                       for (i = 0; i < v->len && !g_cancellable_is_cancelled (search->priv->cancellable); i++) {
                                gchar *uid = g_ptr_array_index (v, i);
 
-                               /* FIXME Pass a GCancellable */
                                message = camel_folder_get_message_sync (
-                                       search->folder, uid, NULL, NULL);
+                                       search->folder, uid, search->priv->cancellable, NULL);
                                if (message) {
                                        if (camel_search_message_body_contains ((CamelDataWrapper *) message, &pattern)) {
                                                g_ptr_array_add (r->value.ptrarray, uid);
@@ -1707,13 +1645,13 @@ search_body_regex (struct _ESExp *f,
        return r;
 }
 
-static ESExpResult *
-search_user_flag (struct _ESExp *f,
+static CamelSExpResult *
+search_user_flag (struct _CamelSExp *f,
                   gint argc,
-                  struct _ESExpResult **argv,
+                  struct _CamelSExpResult **argv,
                   CamelFolderSearch *search)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        gint i;
 
        r(printf("executing user-flag\n"));
@@ -1723,29 +1661,29 @@ search_user_flag (struct _ESExp *f,
                gint truth = FALSE;
                /* performs an OR of all words */
                for (i = 0; i < argc && !truth; i++) {
-                       if (argv[i]->type == ESEXP_RES_STRING
+                       if (argv[i]->type == CAMEL_SEXP_RES_STRING
                            && camel_message_info_user_flag (search->current, argv[i]->value.string)) {
                                truth = TRUE;
                                break;
                        }
                }
-               r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
                r->value.boolean = truth;
        } else {
-               r = e_sexp_result_new (f, ESEXP_RES_ARRAY_PTR);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_ARRAY_PTR);
                r->value.ptrarray = g_ptr_array_new ();
        }
 
        return r;
 }
 
-static ESExpResult *
-search_system_flag (struct _ESExp *f,
+static CamelSExpResult *
+search_system_flag (struct _CamelSExp *f,
                     gint argc,
-                    struct _ESExpResult **argv,
+                    struct _CamelSExpResult **argv,
                     CamelFolderSearch *search)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
 
        r(printf ("executing system-flag\n"));
 
@@ -1755,149 +1693,149 @@ search_system_flag (struct _ESExp *f,
                if (argc == 1)
                        truth = camel_system_flag_get (camel_message_info_flags (search->current), argv[0]->value.string);
 
-               r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
                r->value.boolean = truth;
        } else {
-               r = e_sexp_result_new (f, ESEXP_RES_ARRAY_PTR);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_ARRAY_PTR);
                r->value.ptrarray = g_ptr_array_new ();
        }
 
        return r;
 }
 
-static ESExpResult *
-search_user_tag (struct _ESExp *f,
+static CamelSExpResult *
+search_user_tag (struct _CamelSExp *f,
                  gint argc,
-                 struct _ESExpResult **argv,
+                 struct _CamelSExpResult **argv,
                  CamelFolderSearch *search)
 {
        const gchar *value = NULL;
-       ESExpResult *r;
+       CamelSExpResult *r;
 
        r(printf("executing user-tag\n"));
 
        if (search->current && argc == 1)
                value = camel_message_info_user_tag (search->current, argv[0]->value.string);
 
-       r = e_sexp_result_new (f, ESEXP_RES_STRING);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_STRING);
        r->value.string = g_strdup (value ? value : "");
 
        return r;
 }
 
-static ESExpResult *
-search_get_sent_date (struct _ESExp *f,
+static CamelSExpResult *
+search_get_sent_date (struct _CamelSExp *f,
                       gint argc,
-                      struct _ESExpResult **argv,
+                      struct _CamelSExpResult **argv,
                       CamelFolderSearch *s)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
 
        r(printf("executing get-sent-date\n"));
 
        /* are we inside a match-all? */
        if (s->current) {
-               r = e_sexp_result_new (f, ESEXP_RES_INT);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_INT);
 
                r->value.number = camel_message_info_date_sent (s->current);
        } else {
-               r = e_sexp_result_new (f, ESEXP_RES_ARRAY_PTR);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_ARRAY_PTR);
                r->value.ptrarray = g_ptr_array_new ();
        }
 
        return r;
 }
 
-static ESExpResult *
-search_get_received_date (struct _ESExp *f,
+static CamelSExpResult *
+search_get_received_date (struct _CamelSExp *f,
                           gint argc,
-                          struct _ESExpResult **argv,
+                          struct _CamelSExpResult **argv,
                           CamelFolderSearch *s)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
 
        r(printf("executing get-received-date\n"));
 
        /* are we inside a match-all? */
        if (s->current) {
-               r = e_sexp_result_new (f, ESEXP_RES_INT);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_INT);
 
                r->value.number = camel_message_info_date_received (s->current);
        } else {
-               r = e_sexp_result_new (f, ESEXP_RES_ARRAY_PTR);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_ARRAY_PTR);
                r->value.ptrarray = g_ptr_array_new ();
        }
 
        return r;
 }
 
-static ESExpResult *
-search_get_current_date (struct _ESExp *f,
+static CamelSExpResult *
+search_get_current_date (struct _CamelSExp *f,
                          gint argc,
-                         struct _ESExpResult **argv,
+                         struct _CamelSExpResult **argv,
                          CamelFolderSearch *s)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
 
        r(printf("executing get-current-date\n"));
 
-       r = e_sexp_result_new (f, ESEXP_RES_INT);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_INT);
        r->value.number = time (NULL);
        return r;
 }
 
-static ESExpResult *
-search_get_relative_months (struct _ESExp *f,
+static CamelSExpResult *
+search_get_relative_months (struct _CamelSExp *f,
                             gint argc,
-                            struct _ESExpResult **argv,
+                            struct _CamelSExpResult **argv,
                             CamelFolderSearch *s)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
 
        r(printf("executing get-relative-months\n"));
 
-       if (argc != 1 || argv[0]->type != ESEXP_RES_INT) {
-               r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+       if (argc != 1 || argv[0]->type != CAMEL_SEXP_RES_INT) {
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
                r->value.boolean = FALSE;
 
                g_debug ("%s: Expecting 1 argument, an integer, but got %d arguments", G_STRFUNC, argc);
        } else {
-               r = e_sexp_result_new (f, ESEXP_RES_INT);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_INT);
                r->value.number = camel_folder_search_util_add_months (time (NULL), argv[0]->value.number);
        }
 
        return r;
 }
 
-static ESExpResult *
-search_get_size (struct _ESExp *f,
+static CamelSExpResult *
+search_get_size (struct _CamelSExp *f,
                  gint argc,
-                 struct _ESExpResult **argv,
+                 struct _CamelSExpResult **argv,
                  CamelFolderSearch *s)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
 
        r(printf("executing get-size\n"));
 
        /* are we inside a match-all? */
        if (s->current) {
-               r = e_sexp_result_new (f, ESEXP_RES_INT);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_INT);
                r->value.number = camel_message_info_size (s->current) / 1024;
        } else {
-               r = e_sexp_result_new (f, ESEXP_RES_ARRAY_PTR);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_ARRAY_PTR);
                r->value.ptrarray = g_ptr_array_new ();
        }
 
        return r;
 }
 
-static ESExpResult *
-search_uid (struct _ESExp *f,
+static CamelSExpResult *
+search_uid (struct _CamelSExp *f,
             gint argc,
-            struct _ESExpResult **argv,
+            struct _CamelSExpResult **argv,
             CamelFolderSearch *search)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        gint i;
 
        r(printf("executing uid\n"));
@@ -1909,19 +1847,19 @@ search_uid (struct _ESExp *f,
 
                /* performs an OR of all words */
                for (i = 0; i < argc && !truth; i++) {
-                       if (argv[i]->type == ESEXP_RES_STRING
+                       if (argv[i]->type == CAMEL_SEXP_RES_STRING
                            && !strcmp (uid, argv[i]->value.string)) {
                                truth = TRUE;
                                break;
                        }
                }
-               r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
                r->value.boolean = truth;
        } else {
-               r = e_sexp_result_new (f, ESEXP_RES_ARRAY_PTR);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_ARRAY_PTR);
                r->value.ptrarray = g_ptr_array_new ();
                for (i = 0; i < argc; i++) {
-                       if (argv[i]->type == ESEXP_RES_STRING)
+                       if (argv[i]->type == CAMEL_SEXP_RES_STRING)
                                g_ptr_array_add (r->value.ptrarray, argv[i]->value.string);
                }
        }
@@ -1943,16 +1881,16 @@ read_uid_callback (gpointer ref,
        return 0;
 }
 
-static ESExpResult *
-search_message_location (struct _ESExp *f,
+static CamelSExpResult *
+search_message_location (struct _CamelSExp *f,
                          gint argc,
-                         struct _ESExpResult **argv,
+                         struct _CamelSExpResult **argv,
                          CamelFolderSearch *search)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        gboolean same = FALSE;
 
-       if (argc == 1 && argv[0]->type == ESEXP_RES_STRING) {
+       if (argc == 1 && argv[0]->type == CAMEL_SEXP_RES_STRING) {
                if (argv[0]->value.string && search->folder) {
                        CamelStore *store;
                        const gchar *name;
@@ -1972,10 +1910,10 @@ search_message_location (struct _ESExp *f,
        }
 
        if (search->current) {
-               r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
                r->value.boolean = same ? TRUE : FALSE;
        } else {
-               r = e_sexp_result_new (f, ESEXP_RES_ARRAY_PTR);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_ARRAY_PTR);
                r->value.ptrarray = g_ptr_array_new ();
 
                if (same) {