Add CamelSExp (copy of ESExp).
authorMatthew Barnes <mbarnes@redhat.com>
Tue, 15 Nov 2011 02:53:02 +0000 (21:53 -0500)
committerMatthew Barnes <mbarnes@redhat.com>
Tue, 15 Nov 2011 04:14:42 +0000 (23:14 -0500)
15 files changed:
camel/Makefile.am
camel/camel-filter-driver.c
camel/camel-filter-search.c
camel/camel-folder-search.c
camel/camel-folder-search.h
camel/camel-search-private.c
camel/camel-search-private.h
camel/camel-search-sql-sexp.c
camel/camel-sexp.c [new file with mode: 0644]
camel/camel-sexp.h [new file with mode: 0644]
camel/camel.h
camel/providers/imap/camel-imap-search.c
docs/reference/camel/camel-docs.sgml
docs/reference/camel/camel-sections.txt
docs/reference/camel/camel.types

index 5d90f3a..79700c8 100644 (file)
@@ -140,6 +140,7 @@ libcamel_1_2_la_SOURCES =                   \
        camel-service.c                         \
        camel-session.c                         \
        camel-settings.c                        \
+       camel-sexp.c                            \
        camel-smime-context.c                   \
        camel-store-settings.c                  \
        camel-store-summary.c                   \
@@ -263,6 +264,7 @@ libcamelinclude_HEADERS =                   \
        camel-service.h                         \
        camel-session.h                         \
        camel-settings.h                        \
+       camel-sexp.h                            \
        camel-smime-context.h                   \
        camel-store-settings.h                  \
        camel-store-summary.h                   \
index ea2da51..3b065e2 100644 (file)
@@ -38,8 +38,6 @@
 #include <sys/wait.h>
 #endif
 
-#include <libedataserver/e-sexp.h>
-
 #include "camel-debug.h"
 #include "camel-file-utils.h"
 #include "camel-filter-driver.h"
@@ -48,6 +46,7 @@
 #include "camel-mime-message.h"
 #include "camel-service.h"
 #include "camel-session.h"
+#include "camel-sexp.h"
 #include "camel-store.h"
 #include "camel-stream-fs.h"
 #include "camel-stream-mem.h"
@@ -121,7 +120,7 @@ struct _CamelFilterDriverPrivate {
        GError *error;
 
        /* evaluator */
-       ESExp *eval;
+       CamelSExp *eval;
 };
 
 static void camel_filter_driver_log (CamelFilterDriver *driver, enum filter_log_t status, const gchar *desc, ...);
@@ -129,46 +128,46 @@ static void camel_filter_driver_log (CamelFilterDriver *driver, enum filter_log_
 static CamelFolder *open_folder (CamelFilterDriver *d, const gchar *folder_url);
 static gint close_folders (CamelFilterDriver *d);
 
-static ESExpResult *do_delete (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *);
-static ESExpResult *do_forward_to (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *);
-static ESExpResult *do_copy (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *);
-static ESExpResult *do_move (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *);
-static ESExpResult *do_stop (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *);
-static ESExpResult *do_label (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *);
-static ESExpResult *do_color (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *);
-static ESExpResult *do_score (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *);
-static ESExpResult *do_adjust_score (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *);
-static ESExpResult *set_flag (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *);
-static ESExpResult *unset_flag (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *);
-static ESExpResult *do_shell (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *);
-static ESExpResult *do_beep (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *);
-static ESExpResult *play_sound (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *);
-static ESExpResult *do_only_once (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *);
-static ESExpResult *pipe_message (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFilterDriver *);
+static CamelSExpResult *do_delete (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFilterDriver *);
+static CamelSExpResult *do_forward_to (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFilterDriver *);
+static CamelSExpResult *do_copy (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFilterDriver *);
+static CamelSExpResult *do_move (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFilterDriver *);
+static CamelSExpResult *do_stop (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFilterDriver *);
+static CamelSExpResult *do_label (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFilterDriver *);
+static CamelSExpResult *do_color (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFilterDriver *);
+static CamelSExpResult *do_score (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFilterDriver *);
+static CamelSExpResult *do_adjust_score (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFilterDriver *);
+static CamelSExpResult *set_flag (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFilterDriver *);
+static CamelSExpResult *unset_flag (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFilterDriver *);
+static CamelSExpResult *do_shell (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFilterDriver *);
+static CamelSExpResult *do_beep (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFilterDriver *);
+static CamelSExpResult *play_sound (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFilterDriver *);
+static CamelSExpResult *do_only_once (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFilterDriver *);
+static CamelSExpResult *pipe_message (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFilterDriver *);
 
 /* these are our filter actions - each must have a callback */
 static struct {
        const gchar *name;
-       ESExpFunc *func;
+       CamelSExpFunc func;
        gint type;              /* set to 1 if a function can perform shortcut evaluation, or
                                   doesn't execute everything, 0 otherwise */
 } symbols[] = {
-       { "delete",            (ESExpFunc *) do_delete,    0 },
-       { "forward-to",        (ESExpFunc *) do_forward_to, 0 },
-       { "copy-to",           (ESExpFunc *) do_copy,      0 },
-       { "move-to",           (ESExpFunc *) do_move,      0 },
-       { "stop",              (ESExpFunc *) do_stop,      0 },
-       { "set-label",         (ESExpFunc *) do_label,     0 },
-       { "set-color",        (ESExpFunc *) do_color,    0 },
-       { "set-score",         (ESExpFunc *) do_score,     0 },
-       { "adjust-score",      (ESExpFunc *) do_adjust_score, 0 },
-       { "set-system-flag",   (ESExpFunc *) set_flag,     0 },
-       { "unset-system-flag", (ESExpFunc *) unset_flag,   0 },
-       { "pipe-message",      (ESExpFunc *) pipe_message, 0 },
-       { "shell",             (ESExpFunc *) do_shell,     0 },
-       { "beep",              (ESExpFunc *) do_beep,      0 },
-       { "play-sound",        (ESExpFunc *) play_sound,   0 },
-       { "only-once",         (ESExpFunc *) do_only_once, 0 }
+       { "delete",            (CamelSExpFunc) do_delete,    0 },
+       { "forward-to",        (CamelSExpFunc) do_forward_to, 0 },
+       { "copy-to",           (CamelSExpFunc) do_copy,      0 },
+       { "move-to",           (CamelSExpFunc) do_move,      0 },
+       { "stop",              (CamelSExpFunc) do_stop,      0 },
+       { "set-label",         (CamelSExpFunc) do_label,     0 },
+       { "set-color",         (CamelSExpFunc) do_color,    0 },
+       { "set-score",         (CamelSExpFunc) do_score,     0 },
+       { "adjust-score",      (CamelSExpFunc) do_adjust_score, 0 },
+       { "set-system-flag",   (CamelSExpFunc) set_flag,     0 },
+       { "unset-system-flag", (CamelSExpFunc) unset_flag,   0 },
+       { "pipe-message",      (CamelSExpFunc) pipe_message, 0 },
+       { "shell",             (CamelSExpFunc) do_shell,     0 },
+       { "beep",              (CamelSExpFunc) do_beep,      0 },
+       { "play-sound",        (CamelSExpFunc) play_sound,   0 },
+       { "only-once",         (CamelSExpFunc) do_only_once, 0 }
 };
 
 G_DEFINE_TYPE (CamelFilterDriver, camel_filter_driver, CAMEL_TYPE_OBJECT)
@@ -222,7 +221,7 @@ filter_driver_finalize (GObject *object)
        g_hash_table_foreach (priv->only_once, free_hash_strings, object);
        g_hash_table_destroy (priv->only_once);
 
-       e_sexp_unref (priv->eval);
+       g_object_unref (priv->eval);
 
        while ((node = (struct _filter_rule *) camel_dlist_remhead (&priv->rules))) {
                g_free (node->match);
@@ -258,17 +257,17 @@ camel_filter_driver_init (CamelFilterDriver *filter_driver)
 
        camel_dlist_init (&filter_driver->priv->rules);
 
-       filter_driver->priv->eval = e_sexp_new ();
+       filter_driver->priv->eval = camel_sexp_new ();
 
        /* Load in builtin symbols */
        for (ii = 0; ii < G_N_ELEMENTS (symbols); ii++) {
                if (symbols[ii].type == 1) {
-                       e_sexp_add_ifunction (
+                       camel_sexp_add_ifunction (
                                filter_driver->priv->eval, 0,
-                               symbols[ii].name, (ESExpIFunc *)
+                               symbols[ii].name, (CamelSExpIFunc)
                                symbols[ii].func, filter_driver);
                } else {
-                       e_sexp_add_function (
+                       camel_sexp_add_function (
                                filter_driver->priv->eval, 0,
                                symbols[ii].name, symbols[ii].func,
                                filter_driver);
@@ -445,10 +444,10 @@ camel_filter_driver_set_global (CamelFilterDriver *d,
 }
 #endif
 
-static ESExpResult *
-do_delete (struct _ESExp *f,
+static CamelSExpResult *
+do_delete (struct _CamelSExp *f,
            gint argc,
-           struct _ESExpResult **argv,
+           struct _CamelSExpResult **argv,
            CamelFilterDriver *driver)
 {
        d(fprintf (stderr, "doing delete\n"));
@@ -458,10 +457,10 @@ do_delete (struct _ESExp *f,
        return NULL;
 }
 
-static ESExpResult *
-do_forward_to (struct _ESExp *f,
+static CamelSExpResult *
+do_forward_to (struct _CamelSExp *f,
                gint argc,
-               struct _ESExpResult **argv,
+               struct _CamelSExpResult **argv,
                CamelFilterDriver *driver)
 {
        CamelFilterDriverPrivate *p = driver->priv;
@@ -469,7 +468,7 @@ do_forward_to (struct _ESExp *f,
        d(fprintf (stderr, "marking message for forwarding\n"));
 
        /* requires one parameter, string with a destination address */
-       if (argc < 1 || argv[0]->type != ESEXP_RES_STRING)
+       if (argc < 1 || argv[0]->type != CAMEL_SEXP_RES_STRING)
                return NULL;
 
        /* make sure we have the message... */
@@ -487,10 +486,10 @@ do_forward_to (struct _ESExp *f,
        return NULL;
 }
 
-static ESExpResult *
-do_copy (struct _ESExp *f,
+static CamelSExpResult *
+do_copy (struct _CamelSExp *f,
          gint argc,
-         struct _ESExpResult **argv,
+         struct _CamelSExpResult **argv,
          CamelFilterDriver *driver)
 {
        CamelFilterDriverPrivate *p = driver->priv;
@@ -499,7 +498,7 @@ do_copy (struct _ESExp *f,
        d(fprintf (stderr, "copying message...\n"));
 
        for (i = 0; i < argc; i++) {
-               if (argv[i]->type == ESEXP_RES_STRING) {
+               if (argv[i]->type == CAMEL_SEXP_RES_STRING) {
                        /* open folders we intent to copy to */
                        gchar *folder = argv[i]->value.string;
                        CamelFolder *outbox;
@@ -547,10 +546,10 @@ do_copy (struct _ESExp *f,
        return NULL;
 }
 
-static ESExpResult *
-do_move (struct _ESExp *f,
+static CamelSExpResult *
+do_move (struct _CamelSExp *f,
          gint argc,
-         struct _ESExpResult **argv,
+         struct _CamelSExpResult **argv,
          CamelFilterDriver *driver)
 {
        CamelFilterDriverPrivate *p = driver->priv;
@@ -559,7 +558,7 @@ do_move (struct _ESExp *f,
        d(fprintf (stderr, "moving message...\n"));
 
        for (i = 0; i < argc; i++) {
-               if (argv[i]->type == ESEXP_RES_STRING) {
+               if (argv[i]->type == CAMEL_SEXP_RES_STRING) {
                        /* open folders we intent to move to */
                        gchar *folder = argv[i]->value.string;
                        CamelFolder *outbox;
@@ -629,10 +628,10 @@ do_move (struct _ESExp *f,
        return NULL;
 }
 
-static ESExpResult *
-do_stop (struct _ESExp *f,
+static CamelSExpResult *
+do_stop (struct _CamelSExp *f,
          gint argc,
-         struct _ESExpResult **argv,
+         struct _CamelSExpResult **argv,
          CamelFilterDriver *driver)
 {
        CamelFilterDriverPrivate *p = driver->priv;
@@ -644,16 +643,16 @@ do_stop (struct _ESExp *f,
        return NULL;
 }
 
-static ESExpResult *
-do_label (struct _ESExp *f,
+static CamelSExpResult *
+do_label (struct _CamelSExp *f,
           gint argc,
-          struct _ESExpResult **argv,
+          struct _CamelSExpResult **argv,
           CamelFilterDriver *driver)
 {
        CamelFilterDriverPrivate *p = driver->priv;
 
        d(fprintf (stderr, "setting label tag\n"));
-       if (argc > 0 && argv[0]->type == ESEXP_RES_STRING) {
+       if (argc > 0 && argv[0]->type == CAMEL_SEXP_RES_STRING) {
                /* This is a list of new labels, we should used these in case of passing in old names.
                 * This all is required only because backward compatibility. */
                const gchar *new_labels[] = { "$Labelimportant", "$Labelwork", "$Labelpersonal", "$Labeltodo", "$Labellater", NULL};
@@ -679,16 +678,16 @@ do_label (struct _ESExp *f,
        return NULL;
 }
 
-static ESExpResult *
-do_color (struct _ESExp *f,
+static CamelSExpResult *
+do_color (struct _CamelSExp *f,
           gint argc,
-          struct _ESExpResult **argv,
+          struct _CamelSExpResult **argv,
           CamelFilterDriver *driver)
 {
        CamelFilterDriverPrivate *p = driver->priv;
 
        d(fprintf (stderr, "setting color tag\n"));
-       if (argc > 0 && argv[0]->type == ESEXP_RES_STRING) {
+       if (argc > 0 && argv[0]->type == CAMEL_SEXP_RES_STRING) {
                if (p->source && p->uid && camel_folder_has_summary_capability (p->source))
                        camel_folder_set_message_user_tag (p->source, p->uid, "color", argv[0]->value.string);
                else
@@ -699,16 +698,16 @@ do_color (struct _ESExp *f,
        return NULL;
 }
 
-static ESExpResult *
-do_score (struct _ESExp *f,
+static CamelSExpResult *
+do_score (struct _CamelSExp *f,
           gint argc,
-          struct _ESExpResult **argv,
+          struct _CamelSExpResult **argv,
           CamelFilterDriver *driver)
 {
        CamelFilterDriverPrivate *p = driver->priv;
 
        d(fprintf (stderr, "setting score tag\n"));
-       if (argc > 0 && argv[0]->type == ESEXP_RES_INT) {
+       if (argc > 0 && argv[0]->type == CAMEL_SEXP_RES_INT) {
                gchar *value;
 
                value = g_strdup_printf ("%d", argv[0]->value.number);
@@ -720,16 +719,16 @@ do_score (struct _ESExp *f,
        return NULL;
 }
 
-static ESExpResult *
-do_adjust_score (struct _ESExp *f,
+static CamelSExpResult *
+do_adjust_score (struct _CamelSExp *f,
                  gint argc,
-                 struct _ESExpResult **argv,
+                 struct _CamelSExpResult **argv,
                  CamelFilterDriver *driver)
 {
        CamelFilterDriverPrivate *p = driver->priv;
 
        d(fprintf (stderr, "adjusting score tag\n"));
-       if (argc > 0 && argv[0]->type == ESEXP_RES_INT) {
+       if (argc > 0 && argv[0]->type == CAMEL_SEXP_RES_INT) {
                gchar *value;
                gint old;
 
@@ -744,17 +743,17 @@ do_adjust_score (struct _ESExp *f,
        return NULL;
 }
 
-static ESExpResult *
-set_flag (struct _ESExp *f,
+static CamelSExpResult *
+set_flag (struct _CamelSExp *f,
           gint argc,
-          struct _ESExpResult **argv,
+          struct _CamelSExpResult **argv,
           CamelFilterDriver *driver)
 {
        CamelFilterDriverPrivate *p = driver->priv;
        guint32 flags;
 
        d(fprintf (stderr, "setting flag\n"));
-       if (argc == 1 && argv[0]->type == ESEXP_RES_STRING) {
+       if (argc == 1 && argv[0]->type == CAMEL_SEXP_RES_STRING) {
                flags = camel_system_flag (argv[0]->value.string);
                if (p->source && p->uid && camel_folder_has_summary_capability (p->source))
                        camel_folder_set_message_flags (
@@ -769,17 +768,17 @@ set_flag (struct _ESExp *f,
        return NULL;
 }
 
-static ESExpResult *
-unset_flag (struct _ESExp *f,
+static CamelSExpResult *
+unset_flag (struct _CamelSExp *f,
             gint argc,
-            struct _ESExpResult **argv,
+            struct _CamelSExpResult **argv,
             CamelFilterDriver *driver)
 {
        CamelFilterDriverPrivate *p = driver->priv;
        guint32 flags;
 
        d(fprintf (stderr, "unsetting flag\n"));
-       if (argc == 1 && argv[0]->type == ESEXP_RES_STRING) {
+       if (argc == 1 && argv[0]->type == CAMEL_SEXP_RES_STRING) {
                flags = camel_system_flag (argv[0]->value.string);
                if (p->source && p->uid && camel_folder_has_summary_capability (p->source))
                        camel_folder_set_message_flags (
@@ -824,9 +823,9 @@ child_watch (GPid pid,
 }
 
 static gint
-pipe_to_system (struct _ESExp *f,
+pipe_to_system (struct _CamelSExp *f,
                 gint argc,
-                struct _ESExpResult **argv,
+                struct _CamelSExpResult **argv,
                 CamelFilterDriver *driver)
 {
        CamelFilterDriverPrivate *p = driver->priv;
@@ -958,17 +957,17 @@ pipe_to_system (struct _ESExp *f,
 #endif
 }
 
-static ESExpResult *
-pipe_message (struct _ESExp *f,
+static CamelSExpResult *
+pipe_message (struct _CamelSExp *f,
               gint argc,
-              struct _ESExpResult **argv,
+              struct _CamelSExpResult **argv,
               CamelFilterDriver *driver)
 {
        gint i;
 
        /* make sure all args are strings */
        for (i = 0; i < argc; i++) {
-               if (argv[i]->type != ESEXP_RES_STRING)
+               if (argv[i]->type != CAMEL_SEXP_RES_STRING)
                        return NULL;
        }
 
@@ -978,10 +977,10 @@ pipe_message (struct _ESExp *f,
        return NULL;
 }
 
-static ESExpResult *
-do_shell (struct _ESExp *f,
+static CamelSExpResult *
+do_shell (struct _CamelSExp *f,
           gint argc,
-          struct _ESExpResult **argv,
+          struct _CamelSExpResult **argv,
           CamelFilterDriver *driver)
 {
        CamelFilterDriverPrivate *p = driver->priv;
@@ -997,7 +996,7 @@ do_shell (struct _ESExp *f,
 
        /* make sure all args are strings */
        for (i = 0; i < argc; i++) {
-               if (argv[i]->type != ESEXP_RES_STRING)
+               if (argv[i]->type != CAMEL_SEXP_RES_STRING)
                        goto done;
 
                g_ptr_array_add (args, argv[i]->value.string);
@@ -1022,10 +1021,10 @@ do_shell (struct _ESExp *f,
        return NULL;
 }
 
-static ESExpResult *
-do_beep (struct _ESExp *f,
+static CamelSExpResult *
+do_beep (struct _CamelSExp *f,
          gint argc,
-         struct _ESExpResult **argv,
+         struct _CamelSExpResult **argv,
          CamelFilterDriver *driver)
 {
        CamelFilterDriverPrivate *p = driver->priv;
@@ -1040,17 +1039,17 @@ do_beep (struct _ESExp *f,
        return NULL;
 }
 
-static ESExpResult *
-play_sound (struct _ESExp *f,
+static CamelSExpResult *
+play_sound (struct _CamelSExp *f,
             gint argc,
-            struct _ESExpResult **argv,
+            struct _CamelSExpResult **argv,
             CamelFilterDriver *driver)
 {
        CamelFilterDriverPrivate *p = driver->priv;
 
        d(fprintf (stderr, "play sound\n"));
 
-       if (p->playfunc && argc == 1 && argv[0]->type == ESEXP_RES_STRING) {
+       if (p->playfunc && argc == 1 && argv[0]->type == CAMEL_SEXP_RES_STRING) {
                p->playfunc (driver, argv[0]->value.string, p->playdata);
                camel_filter_driver_log (driver, FILTER_LOG_ACTION, "Play sound");
        }
@@ -1058,10 +1057,10 @@ play_sound (struct _ESExp *f,
        return NULL;
 }
 
-static ESExpResult *
-do_only_once (struct _ESExp *f,
+static CamelSExpResult *
+do_only_once (struct _CamelSExp *f,
               gint argc,
-              struct _ESExpResult **argv,
+              struct _CamelSExpResult **argv,
               CamelFilterDriver *driver)
 {
        CamelFilterDriverPrivate *p = driver->priv;
@@ -1222,33 +1221,33 @@ run_only_once (gpointer key,
                struct _run_only_once *data)
 {
        CamelFilterDriverPrivate *p = data->driver->priv;
-       ESExpResult *r;
+       CamelSExpResult *r;
 
        d(printf ("evaluating: %s\n\n", action));
 
-       e_sexp_input_text (p->eval, action, strlen (action));
-       if (e_sexp_parse (p->eval) == -1) {
+       camel_sexp_input_text (p->eval, action, strlen (action));
+       if (camel_sexp_parse (p->eval) == -1) {
                if (data->error == NULL)
                        g_set_error (
                                &data->error,
                                CAMEL_ERROR, CAMEL_ERROR_GENERIC,
                                _("Error parsing filter: %s: %s"),
-                               e_sexp_error (p->eval), action);
+                               camel_sexp_error (p->eval), action);
                goto done;
        }
 
-       r = e_sexp_eval (p->eval);
+       r = camel_sexp_eval (p->eval);
        if (r == NULL) {
                if (data->error == NULL)
                        g_set_error (
                                &data->error,
                                CAMEL_ERROR, CAMEL_ERROR_GENERIC,
                                _("Error executing filter: %s: %s"),
-                               e_sexp_error (p->eval), action);
+                               camel_sexp_error (p->eval), action);
                goto done;
        }
 
-       e_sexp_result_free (p->eval, r);
+       camel_sexp_result_free (p->eval, r);
 
  done:
 
@@ -1599,7 +1598,7 @@ camel_filter_driver_filter_message (CamelFilterDriver *driver,
        struct _filter_rule *node;
        gboolean freeinfo = FALSE;
        gboolean filtered = FALSE;
-       ESExpResult *r;
+       CamelSExpResult *r;
        gint result;
 
        /* FIXME: make me into a g_return_if_fail/g_assert or whatever... */
@@ -1674,15 +1673,15 @@ camel_filter_driver_filter_message (CamelFilterDriver *driver,
                                       camel_message_info_subject(info)?camel_message_info_subject(info):"?no subject?", node->name);
 
                        /* perform necessary filtering actions */
-                       e_sexp_input_text (p->eval, node->action, strlen (node->action));
-                       if (e_sexp_parse (p->eval) == -1) {
+                       camel_sexp_input_text (p->eval, node->action, strlen (node->action));
+                       if (camel_sexp_parse (p->eval) == -1) {
                                g_set_error (
                                        error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
                                        _("Error parsing filter: %s: %s"),
-                                       e_sexp_error (p->eval), node->action);
+                                       camel_sexp_error (p->eval), node->action);
                                goto error;
                        }
-                       r = e_sexp_eval (p->eval);
+                       r = camel_sexp_eval (p->eval);
                        if (p->error != NULL)
                                goto error;
 
@@ -1690,10 +1689,10 @@ camel_filter_driver_filter_message (CamelFilterDriver *driver,
                                g_set_error (
                                        error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
                                        _("Error executing filter: %s: %s"),
-                                       e_sexp_error (p->eval), node->action);
+                                       camel_sexp_error (p->eval), node->action);
                                goto error;
                        }
-                       e_sexp_result_free (p->eval, r);
+                       camel_sexp_result_free (p->eval, r);
                default:
                        break;
                }
index 856a67d..2cd3525 100644 (file)
@@ -43,8 +43,6 @@
 #include <sys/wait.h>
 #endif
 
-#include <libedataserver/e-sexp.h>
-
 #include "camel-debug.h"
 #include "camel-filter-search.h"
 #include "camel-iconv.h"
@@ -70,64 +68,64 @@ typedef struct {
        GError **error;
 } FilterMessageSearch;
 
-/* ESExp callbacks */
-static ESExpResult *header_contains (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
-static ESExpResult *header_matches (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
-static ESExpResult *header_starts_with (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
-static ESExpResult *header_ends_with (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
-static ESExpResult *header_exists (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
-static ESExpResult *header_soundex (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
-static ESExpResult *header_regex (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
-static ESExpResult *header_full_regex (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
-static ESExpResult *match_all (struct _ESExp *f, gint argc, struct _ESExpTerm **argv, FilterMessageSearch *fms);
-static ESExpResult *body_contains (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
-static ESExpResult *body_regex (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
-static ESExpResult *user_flag (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
-static ESExpResult *user_tag (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
-static ESExpResult *system_flag (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
-static ESExpResult *get_sent_date (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
-static ESExpResult *get_received_date (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
-static ESExpResult *get_current_date (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
-static ESExpResult *get_relative_months (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
-static ESExpResult *header_source (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
-static ESExpResult *get_size (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
-static ESExpResult *pipe_message (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
-static ESExpResult *junk_test (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
+/* CamelSExp callbacks */
+static CamelSExpResult *header_contains (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms);
+static CamelSExpResult *header_matches (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms);
+static CamelSExpResult *header_starts_with (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms);
+static CamelSExpResult *header_ends_with (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms);
+static CamelSExpResult *header_exists (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms);
+static CamelSExpResult *header_soundex (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms);
+static CamelSExpResult *header_regex (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms);
+static CamelSExpResult *header_full_regex (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms);
+static CamelSExpResult *match_all (struct _CamelSExp *f, gint argc, struct _CamelSExpTerm **argv, FilterMessageSearch *fms);
+static CamelSExpResult *body_contains (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms);
+static CamelSExpResult *body_regex (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms);
+static CamelSExpResult *user_flag (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms);
+static CamelSExpResult *user_tag (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms);
+static CamelSExpResult *system_flag (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms);
+static CamelSExpResult *get_sent_date (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms);
+static CamelSExpResult *get_received_date (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms);
+static CamelSExpResult *get_current_date (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms);
+static CamelSExpResult *get_relative_months (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms);
+static CamelSExpResult *header_source (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms);
+static CamelSExpResult *get_size (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms);
+static CamelSExpResult *pipe_message (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms);
+static CamelSExpResult *junk_test (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, FilterMessageSearch *fms);
 
 /* builtin functions */
 static struct {
        const gchar *name;
-       ESExpFunc *func;
+       CamelSExpFunc func;
        gint type;              /* set to 1 if a function can perform shortcut evaluation, or
                                   doesn't execute everything, 0 otherwise */
 } symbols[] = {
-       { "match-all",          (ESExpFunc *) match_all,          1 },
-       { "body-contains",      (ESExpFunc *) body_contains,      0 },
-       { "body-regex",         (ESExpFunc *) body_regex,         0 },
-       { "header-contains",    (ESExpFunc *) header_contains,    0 },
-       { "header-matches",     (ESExpFunc *) header_matches,     0 },
-       { "header-starts-with", (ESExpFunc *) header_starts_with, 0 },
-       { "header-ends-with",   (ESExpFunc *) header_ends_with,   0 },
-       { "header-exists",      (ESExpFunc *) header_exists,      0 },
-       { "header-soundex",     (ESExpFunc *) header_soundex,     0 },
-       { "header-regex",       (ESExpFunc *) header_regex,       0 },
-       { "header-full-regex",  (ESExpFunc *) header_full_regex,  0 },
-       { "user-tag",           (ESExpFunc *) user_tag,           0 },
-       { "user-flag",          (ESExpFunc *) user_flag,          0 },
-       { "system-flag",        (ESExpFunc *) system_flag,        0 },
-       { "get-sent-date",      (ESExpFunc *) get_sent_date,      0 },
-       { "get-received-date",  (ESExpFunc *) get_received_date,  0 },
-       { "get-current-date",   (ESExpFunc *) get_current_date,   0 },
-       { "get-relative-months",(ESExpFunc *) get_relative_months,0 },
-       { "header-source",      (ESExpFunc *) header_source,      0 },
-       { "get-size",           (ESExpFunc *) get_size,           0 },
-       { "pipe-message",       (ESExpFunc *) pipe_message,       0 },
-       { "junk-test",          (ESExpFunc *) junk_test,          0 },
+       { "match-all",          (CamelSExpFunc) match_all,          1 },
+       { "body-contains",      (CamelSExpFunc) body_contains,      0 },
+       { "body-regex",         (CamelSExpFunc) body_regex,         0 },
+       { "header-contains",    (CamelSExpFunc) header_contains,    0 },
+       { "header-matches",     (CamelSExpFunc) header_matches,     0 },
+       { "header-starts-with", (CamelSExpFunc) header_starts_with, 0 },
+       { "header-ends-with",   (CamelSExpFunc) header_ends_with,   0 },
+       { "header-exists",      (CamelSExpFunc) header_exists,      0 },
+       { "header-soundex",     (CamelSExpFunc) header_soundex,     0 },
+       { "header-regex",       (CamelSExpFunc) header_regex,       0 },
+       { "header-full-regex",  (CamelSExpFunc) header_full_regex,  0 },
+       { "user-tag",           (CamelSExpFunc) user_tag,           0 },
+       { "user-flag",          (CamelSExpFunc) user_flag,          0 },
+       { "system-flag",        (CamelSExpFunc) system_flag,        0 },
+       { "get-sent-date",      (CamelSExpFunc) get_sent_date,      0 },
+       { "get-received-date",  (CamelSExpFunc) get_received_date,  0 },
+       { "get-current-date",   (CamelSExpFunc) get_current_date,   0 },
+       { "get-relative-months",(CamelSExpFunc) get_relative_months,0 },
+       { "header-source",      (CamelSExpFunc) header_source,      0 },
+       { "get-size",           (CamelSExpFunc) get_size,           0 },
+       { "pipe-message",       (CamelSExpFunc) pipe_message,       0 },
+       { "junk-test",          (CamelSExpFunc) junk_test,          0 },
 };
 
 static CamelMimeMessage *
 camel_filter_search_get_message (FilterMessageSearch *fms,
-                                 struct _ESExp *sexp)
+                                 struct _CamelSExp *sexp)
 {
        if (fms->message)
                return fms->message;
@@ -135,35 +133,35 @@ camel_filter_search_get_message (FilterMessageSearch *fms,
        fms->message = fms->get_message (fms->get_message_data, fms->error);
 
        if (fms->message == NULL)
-               e_sexp_fatal_error (sexp, _("Failed to retrieve message"));
+               camel_sexp_fatal_error (sexp, _("Failed to retrieve message"));
 
        return fms->message;
 }
 
-static ESExpResult *
-check_header (struct _ESExp *f,
+static CamelSExpResult *
+check_header (struct _CamelSExp *f,
               gint argc,
-              struct _ESExpResult **argv,
+              struct _CamelSExpResult **argv,
               FilterMessageSearch *fms,
               camel_search_match_t how)
 {
        gboolean matched = FALSE;
-       ESExpResult *r;
+       CamelSExpResult *r;
        gint i;
 
-       if (argc > 1 && argv[0]->type == ESEXP_RES_STRING) {
+       if (argc > 1 && argv[0]->type == CAMEL_SEXP_RES_STRING) {
                gchar *name = argv[0]->value.string;
 
                /* shortcut: a match for "" against any header always matches */
                for (i = 1; i < argc && !matched; i++)
-                       matched = argv[i]->type == ESEXP_RES_STRING && argv[i]->value.string[0] == 0;
+                       matched = argv[i]->type == CAMEL_SEXP_RES_STRING && argv[i]->value.string[0] == 0;
 
                if (g_ascii_strcasecmp(name, "x-camel-mlist") == 0) {
                        const gchar *list = camel_message_info_mlist (fms->info);
 
                        if (list) {
                                for (i = 1; i < argc && !matched; i++) {
-                                       if (argv[i]->type == ESEXP_RES_STRING)
+                                       if (argv[i]->type == CAMEL_SEXP_RES_STRING)
                                                matched = camel_search_header_match (list, argv[i]->value.string, how, CAMEL_SEARCH_TYPE_MLIST, NULL);
                                }
                        }
@@ -192,7 +190,7 @@ check_header (struct _ESExp *f,
                        for (header = mime_part->headers; header && !matched; header = header->next) {
                                if (!g_ascii_strcasecmp (header->name, name)) {
                                        for (i = 1; i < argc && !matched; i++) {
-                                               if (argv[i]->type == ESEXP_RES_STRING)
+                                               if (argv[i]->type == CAMEL_SEXP_RES_STRING)
                                                        matched = camel_search_header_match (header->value, argv[i]->value.string, how, type, charset);
                                        }
                                }
@@ -200,95 +198,95 @@ check_header (struct _ESExp *f,
                }
        }
 
-       r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
        r->value.boolean = matched;
 
        return r;
 }
 
-static ESExpResult *
-header_contains (struct _ESExp *f,
+static CamelSExpResult *
+header_contains (struct _CamelSExp *f,
                  gint argc,
-                 struct _ESExpResult **argv,
+                 struct _CamelSExpResult **argv,
                  FilterMessageSearch *fms)
 {
        return check_header (f, argc, argv, fms, CAMEL_SEARCH_MATCH_CONTAINS);
 }
 
-static ESExpResult *
-header_matches (struct _ESExp *f,
+static CamelSExpResult *
+header_matches (struct _CamelSExp *f,
                 gint argc,
-                struct _ESExpResult **argv,
+                struct _CamelSExpResult **argv,
                 FilterMessageSearch *fms)
 {
        return check_header (f, argc, argv, fms, CAMEL_SEARCH_MATCH_EXACT);
 }
 
-static ESExpResult *
-header_starts_with (struct _ESExp *f,
+static CamelSExpResult *
+header_starts_with (struct _CamelSExp *f,
                     gint argc,
-                    struct _ESExpResult **argv,
+                    struct _CamelSExpResult **argv,
                     FilterMessageSearch *fms)
 {
        return check_header (f, argc, argv, fms, CAMEL_SEARCH_MATCH_STARTS);
 }
 
-static ESExpResult *
-header_ends_with (struct _ESExp *f,
+static CamelSExpResult *
+header_ends_with (struct _CamelSExp *f,
                   gint argc,
-                  struct _ESExpResult **argv,
+                  struct _CamelSExpResult **argv,
                   FilterMessageSearch *fms)
 {
        return check_header (f, argc, argv, fms, CAMEL_SEARCH_MATCH_ENDS);
 }
 
-static ESExpResult *
-header_soundex (struct _ESExp *f,
+static CamelSExpResult *
+header_soundex (struct _CamelSExp *f,
                 gint argc,
-                struct _ESExpResult **argv,
+                struct _CamelSExpResult **argv,
                 FilterMessageSearch *fms)
 {
        return check_header (f, argc, argv, fms, CAMEL_SEARCH_MATCH_SOUNDEX);
 }
 
-static ESExpResult *
-header_exists (struct _ESExp *f,
+static CamelSExpResult *
+header_exists (struct _CamelSExp *f,
                gint argc,
-               struct _ESExpResult **argv,
+               struct _CamelSExpResult **argv,
                FilterMessageSearch *fms)
 {
        CamelMimeMessage *message;
        gboolean matched = FALSE;
-       ESExpResult *r;
+       CamelSExpResult *r;
        gint i;
 
        message = camel_filter_search_get_message (fms, f);
 
        for (i = 0; i < argc && !matched; i++) {
-               if (argv[i]->type == ESEXP_RES_STRING)
+               if (argv[i]->type == CAMEL_SEXP_RES_STRING)
                        matched = camel_medium_get_header (CAMEL_MEDIUM (message), argv[i]->value.string) != NULL;
        }
 
-       r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
        r->value.boolean = matched;
 
        return r;
 }
 
-static ESExpResult *
-header_regex (struct _ESExp *f,
+static CamelSExpResult *
+header_regex (struct _CamelSExp *f,
               gint argc,
-              struct _ESExpResult **argv,
+              struct _CamelSExpResult **argv,
               FilterMessageSearch *fms)
 {
-       ESExpResult *r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+       CamelSExpResult *r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
        CamelMimeMessage *message;
        regex_t pattern;
        const gchar *contents;
 
        message = camel_filter_search_get_message (fms, f);
 
-       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 (message), argv[0]->value.string))
            && camel_search_build_match_regex (&pattern, CAMEL_SEARCH_MATCH_REGEX | CAMEL_SEARCH_MATCH_ICASE, argc - 1, argv + 1, fms->error) == 0) {
                r->value.boolean = regexec (&pattern, contents, 0, NULL, 0) == 0;
@@ -327,13 +325,13 @@ get_full_header (CamelMimeMessage *message)
        return ret;
 }
 
-static ESExpResult *
-header_full_regex (struct _ESExp *f,
+static CamelSExpResult *
+header_full_regex (struct _CamelSExp *f,
                    gint argc,
-                   struct _ESExpResult **argv,
+                   struct _CamelSExpResult **argv,
                    FilterMessageSearch *fms)
 {
-       ESExpResult *r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+       CamelSExpResult *r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
        CamelMimeMessage *message;
        regex_t pattern;
        gchar *contents;
@@ -351,31 +349,31 @@ header_full_regex (struct _ESExp *f,
        return r;
 }
 
-static ESExpResult *
-match_all (struct _ESExp *f,
+static CamelSExpResult *
+match_all (struct _CamelSExp *f,
            gint argc,
-           struct _ESExpTerm **argv,
+           struct _CamelSExpTerm **argv,
            FilterMessageSearch *fms)
 {
        /* match-all: when dealing with single messages is a no-op */
-       ESExpResult *r;
+       CamelSExpResult *r;
 
        if (argc > 0)
-               return e_sexp_term_eval (f, argv[0]);
+               return camel_sexp_term_eval (f, argv[0]);
 
-       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 *
-body_contains (struct _ESExp *f,
+static CamelSExpResult *
+body_contains (struct _CamelSExp *f,
                gint argc,
-               struct _ESExpResult **argv,
+               struct _CamelSExpResult **argv,
                FilterMessageSearch *fms)
 {
-       ESExpResult *r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+       CamelSExpResult *r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
        CamelMimeMessage *message;
        regex_t pattern;
 
@@ -389,13 +387,13 @@ body_contains (struct _ESExp *f,
        return r;
 }
 
-static ESExpResult *
-body_regex (struct _ESExp *f,
+static CamelSExpResult *
+body_regex (struct _CamelSExp *f,
             gint argc,
-            struct _ESExpResult **argv,
+            struct _CamelSExpResult **argv,
             FilterMessageSearch *fms)
 {
-       ESExpResult *r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+       CamelSExpResult *r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
        CamelMimeMessage *message;
        regex_t pattern;
 
@@ -410,129 +408,129 @@ body_regex (struct _ESExp *f,
        return r;
 }
 
-static ESExpResult *
-user_flag (struct _ESExp *f,
+static CamelSExpResult *
+user_flag (struct _CamelSExp *f,
            gint argc,
-           struct _ESExpResult **argv,
+           struct _CamelSExpResult **argv,
            FilterMessageSearch *fms)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        gboolean truth = FALSE;
        gint i;
 
        /* 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 (fms->info, 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;
 
        return r;
 }
 
-static ESExpResult *
-system_flag (struct _ESExp *f,
+static CamelSExpResult *
+system_flag (struct _CamelSExp *f,
              gint argc,
-             struct _ESExpResult **argv,
+             struct _CamelSExpResult **argv,
              FilterMessageSearch *fms)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
 
-       if (argc != 1 || argv[0]->type != ESEXP_RES_STRING)
-               e_sexp_fatal_error(f, _("Invalid arguments to (system-flag)"));
+       if (argc != 1 || argv[0]->type != CAMEL_SEXP_RES_STRING)
+               camel_sexp_fatal_error(f, _("Invalid arguments to (system-flag)"));
 
-       r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
        r->value.boolean = camel_system_flag_get (camel_message_info_flags (fms->info), argv[0]->value.string);
 
        return r;
 }
 
-static ESExpResult *
-user_tag (struct _ESExp *f,
+static CamelSExpResult *
+user_tag (struct _CamelSExp *f,
           gint argc,
-          struct _ESExpResult **argv,
+          struct _CamelSExpResult **argv,
           FilterMessageSearch *fms)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        const gchar *tag;
 
-       if (argc != 1 || argv[0]->type != ESEXP_RES_STRING)
-               e_sexp_fatal_error(f, _("Invalid arguments to (user-tag)"));
+       if (argc != 1 || argv[0]->type != CAMEL_SEXP_RES_STRING)
+               camel_sexp_fatal_error(f, _("Invalid arguments to (user-tag)"));
 
        tag = camel_message_info_user_tag (fms->info, 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 (tag ? tag : "");
 
        return r;
 }
 
-static ESExpResult *
-get_sent_date (struct _ESExp *f,
+static CamelSExpResult *
+get_sent_date (struct _CamelSExp *f,
                gint argc,
-               struct _ESExpResult **argv,
+               struct _CamelSExpResult **argv,
                FilterMessageSearch *fms)
 {
        CamelMimeMessage *message;
-       ESExpResult *r;
+       CamelSExpResult *r;
 
        message = camel_filter_search_get_message (fms, f);
-       r = e_sexp_result_new (f, ESEXP_RES_INT);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_INT);
        r->value.number = camel_mime_message_get_date (message, NULL);
 
        return r;
 }
 
-static ESExpResult *
-get_received_date (struct _ESExp *f,
+static CamelSExpResult *
+get_received_date (struct _CamelSExp *f,
                    gint argc,
-                   struct _ESExpResult **argv,
+                   struct _CamelSExpResult **argv,
                    FilterMessageSearch *fms)
 {
        CamelMimeMessage *message;
-       ESExpResult *r;
+       CamelSExpResult *r;
 
        message = camel_filter_search_get_message (fms, f);
-       r = e_sexp_result_new (f, ESEXP_RES_INT);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_INT);
        r->value.number = camel_mime_message_get_date_received (message, NULL);
 
        return r;
 }
 
-static ESExpResult *
-get_current_date (struct _ESExp *f,
+static CamelSExpResult *
+get_current_date (struct _CamelSExp *f,
                   gint argc,
-                  struct _ESExpResult **argv,
+                  struct _CamelSExpResult **argv,
                   FilterMessageSearch *fms)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
 
-       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 *
-get_relative_months (struct _ESExp *f,
+static CamelSExpResult *
+get_relative_months (struct _CamelSExp *f,
                      gint argc,
-                     struct _ESExpResult **argv,
+                     struct _CamelSExpResult **argv,
                      FilterMessageSearch *fms)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
 
-       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);
        }
 
@@ -570,14 +568,14 @@ get_service_for_source (CamelSession *session,
        return service;
 }
 
-static ESExpResult *
-header_source (struct _ESExp *f,
+static CamelSExpResult *
+header_source (struct _CamelSExp *f,
                gint argc,
-               struct _ESExpResult **argv,
+               struct _CamelSExpResult **argv,
                FilterMessageSearch *fms)
 {
        CamelMimeMessage *message;
-       ESExpResult *r;
+       CamelSExpResult *r;
        const gchar *src;
        CamelService *msg_source = NULL;
        gboolean truth = FALSE;
@@ -596,28 +594,28 @@ header_source (struct _ESExp *f,
                gint ii;
 
                for (ii = 0; ii < argc && !truth; ii++) {
-                       if (argv[ii]->type == ESEXP_RES_STRING) {
+                       if (argv[ii]->type == CAMEL_SEXP_RES_STRING) {
                                truth = msg_source == get_service_for_source (fms->session, argv[ii]->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;
 
        return r;
 }
 
 /* remember, the size comparisons are done at Kbytes */
-static ESExpResult *
-get_size (struct _ESExp *f,
+static CamelSExpResult *
+get_size (struct _CamelSExp *f,
           gint argc,
-          struct _ESExpResult **argv,
+          struct _CamelSExpResult **argv,
           FilterMessageSearch *fms)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
 
-       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 (fms->info) / 1024;
 
        return r;
@@ -652,9 +650,9 @@ child_watch (GPid pid,
 }
 
 static gint
-run_command (struct _ESExp *f,
+run_command (struct _CamelSExp *f,
              gint argc,
-             struct _ESExpResult **argv,
+             struct _CamelSExpResult **argv,
              FilterMessageSearch *fms)
 {
        CamelMimeMessage *message;
@@ -732,18 +730,18 @@ run_command (struct _ESExp *f,
 #endif
 }
 
-static ESExpResult *
-pipe_message (struct _ESExp *f,
+static CamelSExpResult *
+pipe_message (struct _CamelSExp *f,
               gint argc,
-              struct _ESExpResult **argv,
+              struct _CamelSExpResult **argv,
               FilterMessageSearch *fms)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        gint retval, i;
 
        /* make sure all args are strings */
        for (i = 0; i < argc; i++) {
-               if (argv[i]->type != ESEXP_RES_STRING) {
+               if (argv[i]->type != CAMEL_SEXP_RES_STRING) {
                        retval = -1;
                        goto done;
                }
@@ -752,19 +750,19 @@ pipe_message (struct _ESExp *f,
        retval = run_command (f, argc, argv, fms);
 
  done:
-       r = e_sexp_result_new (f, ESEXP_RES_INT);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_INT);
        r->value.number = retval;
 
        return r;
 }
 
-static ESExpResult *
-junk_test (struct _ESExp *f,
+static CamelSExpResult *
+junk_test (struct _CamelSExp *f,
            gint argc,
-           struct _ESExpResult **argv,
+           struct _CamelSExpResult **argv,
            FilterMessageSearch *fms)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        gboolean retval = FALSE;
        CamelMessageInfo *info = fms->info;
        CamelJunkFilter *junk_filter;
@@ -814,7 +812,7 @@ junk_test (struct _ESExp *f,
                        printf ("Message has a NotJunk flag set already, skipping junk test...\n");
        }
 
-       r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
        r->value.number = retval;
 
        return r;
@@ -843,8 +841,8 @@ camel_filter_search_match (CamelSession *session,
                            GError **error)
 {
        FilterMessageSearch fms;
-       ESExp *sexp;
-       ESExpResult *result;
+       CamelSExp *sexp;
+       CamelSExpResult *result;
        gboolean retval;
        gint i;
 
@@ -856,42 +854,42 @@ camel_filter_search_match (CamelSession *session,
        fms.source = source;
        fms.error = error;
 
-       sexp = e_sexp_new ();
+       sexp = camel_sexp_new ();
 
        for (i = 0; i < G_N_ELEMENTS (symbols); i++) {
                if (symbols[i].type == 1)
-                       e_sexp_add_ifunction (sexp, 0, symbols[i].name, (ESExpIFunc *) symbols[i].func, &fms);
+                       camel_sexp_add_ifunction (sexp, 0, symbols[i].name, (CamelSExpIFunc) symbols[i].func, &fms);
                else
-                       e_sexp_add_function (sexp, 0, symbols[i].name, symbols[i].func, &fms);
+                       camel_sexp_add_function (sexp, 0, symbols[i].name, symbols[i].func, &fms);
        }
 
-       e_sexp_input_text (sexp, expression, strlen (expression));
-       if (e_sexp_parse (sexp) == -1) {
+       camel_sexp_input_text (sexp, expression, strlen (expression));
+       if (camel_sexp_parse (sexp) == -1) {
                /* A filter search is a search through your filters,
                 * ie. your filters is the corpus being searched thru. */
                g_set_error (
                        error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
                        _("Error executing filter search: %s: %s"),
-                       e_sexp_error (sexp), expression);
+                       camel_sexp_error (sexp), expression);
                goto error;
        }
 
-       result = e_sexp_eval (sexp);
+       result = camel_sexp_eval (sexp);
        if (result == NULL) {
                g_set_error (
                        error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
                        _("Error executing filter search: %s: %s"),
-                       e_sexp_error (sexp), expression);
+                       camel_sexp_error (sexp), expression);
                goto error;
        }
 
-       if (result->type == ESEXP_RES_BOOL)
+       if (result->type == CAMEL_SEXP_RES_BOOL)
                retval = result->value.boolean ? CAMEL_SEARCH_MATCHED : CAMEL_SEARCH_NOMATCH;
        else
                retval = CAMEL_SEARCH_NOMATCH;
 
-       e_sexp_result_free (sexp, result);
-       e_sexp_unref (sexp);
+       camel_sexp_result_free (sexp, result);
+       g_object_unref (sexp);
 
        if (fms.message)
                g_object_unref (fms.message);
@@ -902,7 +900,7 @@ camel_filter_search_match (CamelSession *session,
        if (fms.message)
                g_object_unref (fms.message);
 
-       e_sexp_unref (sexp);
+       g_object_unref (sexp);
 
        return CAMEL_SEARCH_ERROR;
 }
index a4f88e6..416634c 100644 (file)
@@ -64,32 +64,32 @@ struct _CamelFolderSearchPrivate {
        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 +101,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;
        }
 
@@ -161,7 +161,7 @@ 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->sexp = camel_sexp_new ();
 }
 
 static struct {
@@ -222,9 +222,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);
                        }
                }
        }
@@ -330,7 +330,7 @@ camel_folder_search_execute_expression (CamelFolderSearch *search,
                                         const gchar *expr,
                                         GError **error)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        GPtrArray *matches;
        gint i;
        GHashTable *results;
@@ -341,31 +341,31 @@ camel_folder_search_execute_expression (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);
                        return NULL;
                }
 
                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);
                return NULL;
        }
 
        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"));
                if (search->summary) {
                        /* reorder result in summary order */
@@ -391,7 +391,7 @@ camel_folder_search_execute_expression (CamelFolderSearch *search,
                g_warning("Search returned an invalid result type");
        }
 
-       e_sexp_result_free (search->sexp, r);
+       camel_sexp_result_free (search->sexp, r);
 
        if (p->threads)
                camel_folder_thread_messages_unref (p->threads);
@@ -427,7 +427,7 @@ camel_folder_search_count (CamelFolderSearch *search,
                            const gchar *expr,
                            GError **error)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        GPtrArray *summary_set;
        gint i;
        CamelDB *cdb;
@@ -451,29 +451,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 +491,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;
@@ -587,7 +587,7 @@ camel_folder_search_search (CamelFolderSearch *search,
                             GPtrArray *uids,
                             GError **error)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        GPtrArray *matches = NULL, *summary_set;
        gint i;
        CamelDB *cdb;
@@ -622,31 +622,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 +664,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;
@@ -735,19 +735,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 +755,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 +809,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 +842,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) {
@@ -888,18 +888,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 +941,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 +957,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 +987,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 +1010,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 +1053,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);
@@ -1075,21 +1075,21 @@ get_current_message (CamelFolderSearch *search)
                search->folder, search->current->uid, NULL, 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 +1136,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 +1175,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 +1189,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 +1272,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 +1284,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 +1313,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 +1327,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 +1342,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 ();
        }
 
@@ -1576,16 +1576,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 +1595,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) {
@@ -1610,10 +1610,10 @@ search_body_contains (struct _ESExp *f,
                                }
                        }
                }
-               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,7 +1629,7 @@ 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);
@@ -1653,19 +1653,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 +1677,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) {
@@ -1707,13 +1707,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 +1723,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 +1755,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 +1909,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 +1943,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 +1972,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) {
index cdd65e5..a1b2448 100644 (file)
@@ -26,9 +26,9 @@
 #ifndef CAMEL_FOLDER_SEARCH_H
 #define CAMEL_FOLDER_SEARCH_H
 
-#include <libedataserver/e-sexp.h>
 #include <camel/camel-folder.h>
 #include <camel/camel-index.h>
+#include <camel/camel-sexp.h>
 
 /* Standard GObject macros */
 #define CAMEL_TYPE_FOLDER_SEARCH \
@@ -59,7 +59,7 @@ struct _CamelFolderSearch {
        CamelObject parent;
        CamelFolderSearchPrivate *priv;
 
-       ESExp *sexp;            /* s-exp evaluator */
+       CamelSExp *sexp;                /* s-exp evaluator */
        gchar *last_search;     /* last searched expression */
 
        /* these are only valid during the search, and are reset afterwards */
@@ -75,79 +75,79 @@ struct _CamelFolderSearchClass {
        CamelObjectClass parent_class;
 
        /* general bool/comparison options, usually these wont need to be set, unless it is compiling into another language */
-       ESExpResult * (*and)(struct _ESExp *f, gint argc, struct _ESExpTerm **argv, CamelFolderSearch *s);
-       ESExpResult * (*or)(struct _ESExp *f, gint argc, struct _ESExpTerm **argv, CamelFolderSearch *s);
-       ESExpResult * (*not)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
-       ESExpResult * (*lt)(struct _ESExp *f, gint argc, struct _ESExpTerm **argv, CamelFolderSearch *s);
-       ESExpResult * (*gt)(struct _ESExp *f, gint argc, struct _ESExpTerm **argv, CamelFolderSearch *s);
-       ESExpResult * (*eq)(struct _ESExp *f, gint argc, struct _ESExpTerm **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*and)(CamelSExp *f, gint argc, CamelSExpTerm **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*or)(CamelSExp *f, gint argc, CamelSExpTerm **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*not)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*lt)(CamelSExp *f, gint argc, CamelSExpTerm **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*gt)(CamelSExp *f, gint argc, CamelSExpTerm **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*eq)(CamelSExp *f, gint argc, CamelSExpTerm **argv, CamelFolderSearch *s);
 
        /* search options */
        /* (match-all [boolean expression]) Apply match to all messages */
-       ESExpResult * (*match_all)(struct _ESExp *f, gint argc, struct _ESExpTerm **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*match_all)(CamelSExp *f, gint argc, CamelSExpTerm **argv, CamelFolderSearch *s);
 
        /* (match-threads "type" [array expression]) add all related threads */
-       ESExpResult * (*match_threads)(struct _ESExp *f, gint argc, struct _ESExpTerm **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*match_threads)(CamelSExp *f, gint argc, CamelSExpTerm **argv, CamelFolderSearch *s);
 
        /* (body-contains "string1" "string2" ...) Returns a list of matches, or true if in single-message mode */
-       ESExpResult * (*body_contains)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*body_contains)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
 
        /* (body-regex "regex") Returns a list of matches, or true if in single-message mode */
-       ESExpResult * (*body_regex)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*body_regex)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
 
        /* (header-contains "headername" "string1" ...) List of matches, or true if in single-message mode */
-       ESExpResult * (*header_contains)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*header_contains)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
 
        /* (header-matches "headername" "string") */
-       ESExpResult * (*header_matches)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*header_matches)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
 
        /* (header-starts-with "headername" "string") */
-       ESExpResult * (*header_starts_with)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*header_starts_with)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
 
        /* (header-ends-with "headername" "string") */
-       ESExpResult * (*header_ends_with)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*header_ends_with)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
 
        /* (header-exists "headername") */
-       ESExpResult * (*header_exists)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*header_exists)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
 
        /* (header-soundex "headername" "string") */
-       ESExpResult * (*header_soundex)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*header_soundex)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
 
        /* (header-regex "headername" "regex_string") */
-       ESExpResult * (*header_regex)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*header_regex)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
 
        /* (header-full-regex "regex") */
-       ESExpResult * (*header_full_regex)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*header_full_regex)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
 
        /* (user-flag "flagname" "flagname" ...) If one of user-flag set */
-       ESExpResult * (*user_flag)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*user_flag)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
 
        /* (user-tag "flagname") Returns the value of a user tag.  Can only be used in match-all */
-       ESExpResult * (*user_tag)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*user_tag)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
 
        /* (system-flag "flagname") Returns the value of a system flag.  Can only be used in match-all */
-       ESExpResult * (*system_flag)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*system_flag)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
 
        /* (get-sent-date) Retrieve the date that the message was sent on as a time_t */
-       ESExpResult * (*get_sent_date)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*get_sent_date)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
 
        /* (get-received-date) Retrieve the date that the message was received on as a time_t */
-       ESExpResult * (*get_received_date)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*get_received_date)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
 
        /* (get-current-date) Retrieve 'now' as a time_t */
-       ESExpResult * (*get_current_date)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*get_current_date)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
 
        /* (get-relative-months) Retrieve relative seconds from 'now' and specified number of months as a time_t */
-       ESExpResult * (*get_relative_months)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*get_relative_months)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
 
        /* (get-size) Retrieve message size as an gint (in kilobytes) */
-       ESExpResult * (*get_size)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*get_size)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
 
        /* (uid "uid" ...) True if the uid is in the list */
-       ESExpResult * (*uid)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*uid)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
 
        /* (message-location "folder_string") True if the message is in the folder's full name "folder_string" */
-       ESExpResult * (*message_location)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+       CamelSExpResult * (*message_location)(CamelSExp *f, gint argc, CamelSExpResult **argv, CamelFolderSearch *s);
 
 };
 
index 9b19f86..680343b 100644 (file)
@@ -54,7 +54,7 @@ gint
 camel_search_build_match_regex (regex_t *pattern,
                                 camel_search_flags_t type,
                                 gint argc,
-                                struct _ESExpResult **argv,
+                                struct _CamelSExpResult **argv,
                                 GError **error)
 {
        GString *match = g_string_new("");
@@ -66,7 +66,7 @@ camel_search_build_match_regex (regex_t *pattern,
        if (argc > 1)
                g_string_append_c (match, '(');
        for (i = 0; i < argc; i++) {
-               if (argv[i]->type == ESEXP_RES_STRING) {
+               if (argv[i]->type == CAMEL_SEXP_RES_STRING) {
                        if (count > 0)
                                g_string_append_c (match, '|');
 
index 58a963c..a6e4b81 100644 (file)
@@ -28,8 +28,6 @@
 
 #include <camel/camel.h>
 
-#include "libedataserver/e-sexp.h"
-
 G_BEGIN_DECLS
 
 typedef enum {
@@ -57,7 +55,7 @@ typedef enum {
 } camel_search_t;
 
 /* builds a regex that represents a string search */
-gint camel_search_build_match_regex (regex_t *pattern, camel_search_flags_t type, gint argc, struct _ESExpResult **argv, GError **error);
+gint camel_search_build_match_regex (regex_t *pattern, camel_search_flags_t type, gint argc, struct _CamelSExpResult **argv, GError **error);
 gboolean camel_search_message_body_contains (CamelDataWrapper *object, regex_t *pattern);
 
 gboolean camel_search_header_match (const gchar *value, const gchar *match, camel_search_match_t how, camel_search_t type, const gchar *default_charset);
index f5fb023..aac19a2 100644 (file)
@@ -77,13 +77,13 @@ get_db_safe_string (const gchar *str)
 
 /* Configuration of your sexp expression */
 
-static ESExpResult *
-func_and (ESExp *f,
+static CamelSExpResult *
+func_and (CamelSExp *f,
           gint argc,
-          struct _ESExpTerm **argv,
+          struct _CamelSExpTerm **argv,
           gpointer data)
 {
-       ESExpResult *r, *r1;
+       CamelSExpResult *r, *r1;
        GString *string;
        gint i;
 
@@ -91,18 +91,18 @@ func_and (ESExp *f,
 
        string = g_string_new("( ");
        for (i = 0; i < argc; i++) {
-               r1 = e_sexp_term_eval (f, argv[i]);
+               r1 = camel_sexp_term_eval (f, argv[i]);
 
-               if (r1->type != ESEXP_RES_STRING) {
-                       e_sexp_result_free (f, r1);
+               if (r1->type != CAMEL_SEXP_RES_STRING) {
+                       camel_sexp_result_free (f, r1);
                        continue;
                }
                if (r1->value.string && *r1->value.string)
                        g_string_append_printf(string, "%s%s", r1->value.string, ((argc>1) && (i != argc-1)) ?  " AND ":"");
-               e_sexp_result_free (f, r1);
+               camel_sexp_result_free (f, r1);
        }
        g_string_append(string, " )");
-       r = e_sexp_result_new (f, ESEXP_RES_STRING);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_STRING);
 
        if (strlen (string->str) == 4)
                r->value.string = g_strdup("");
@@ -113,13 +113,13 @@ func_and (ESExp *f,
        return r;
 }
 
-static ESExpResult *
-func_or (ESExp *f,
+static CamelSExpResult *
+func_or (CamelSExp *f,
          gint argc,
-         struct _ESExpTerm **argv,
+         struct _CamelSExpTerm **argv,
          gpointer data)
 {
-       ESExpResult *r, *r1;
+       CamelSExpResult *r, *r1;
        GString *string;
        gint i;
 
@@ -127,36 +127,36 @@ func_or (ESExp *f,
 
        string = g_string_new("( ");
        for (i = 0; i < argc; i++) {
-               r1 = e_sexp_term_eval (f, argv[i]);
+               r1 = camel_sexp_term_eval (f, argv[i]);
 
-               if (r1->type != ESEXP_RES_STRING) {
-                       e_sexp_result_free (f, r1);
+               if (r1->type != CAMEL_SEXP_RES_STRING) {
+                       camel_sexp_result_free (f, r1);
                        continue;
                }
                g_string_append_printf(string, "%s%s", r1->value.string, ((argc>1) && (i != argc-1)) ?  " OR ":"");
-               e_sexp_result_free (f, r1);
+               camel_sexp_result_free (f, r1);
        }
        g_string_append(string, " )");
 
-       r = e_sexp_result_new (f, ESEXP_RES_STRING);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_STRING);
        r->value.string = string->str;
        g_string_free (string, FALSE);
        return r;
 }
 
-static ESExpResult *
-func_not (ESExp *f,
+static CamelSExpResult *
+func_not (CamelSExp *f,
           gint argc,
-          struct _ESExpTerm **argv,
+          struct _CamelSExpTerm **argv,
           gpointer data)
 {
-       ESExpResult *r = NULL, *r1;
+       CamelSExpResult *r = NULL, *r1;
 
        d(printf("executing not: %d", argc));
-       r1 = e_sexp_term_eval (f, argv[0]);
+       r1 = camel_sexp_term_eval (f, argv[0]);
 
-       if (r1->type == ESEXP_RES_STRING) {
-               r = e_sexp_result_new (f, ESEXP_RES_STRING);
+       if (r1->type == CAMEL_SEXP_RES_STRING) {
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_STRING);
                /* HACK: Fix and handle completed-on better. */
                if (g_strcmp0 (r1->value.string, "( (usertags LIKE '%completed-on 0%' AND usertags LIKE '%completed-on%') )") == 0)
                        r->value.string = g_strdup ("( (not (usertags LIKE '%completed-on 0%')) AND usertags LIKE '%completed-on%' )");
@@ -164,32 +164,32 @@ func_not (ESExp *f,
                        r->value.string = g_strdup_printf ("(NOT (%s))",
                                                           r1->value.string);
        }
-       e_sexp_result_free (f, r1);
+       camel_sexp_result_free (f, r1);
 
        return r;
 }
 
 /* this should support all arguments ...? */
-static ESExpResult *
-eval_eq (struct _ESExp *f,
+static CamelSExpResult *
+eval_eq (struct _CamelSExp *f,
          gint argc,
-         struct _ESExpTerm **argv,
+         struct _CamelSExpTerm **argv,
          gpointer data)
 {
-       struct _ESExpResult *r, *r1, *r2;
+       struct _CamelSExpResult *r, *r1, *r2;
 
-       r = e_sexp_result_new (f, ESEXP_RES_STRING);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_STRING);
 
        if (argc == 2) {
                GString *str = g_string_new("( ");
-               r1 = e_sexp_term_eval (f, argv[0]);
-               r2 = e_sexp_term_eval (f, argv[1]);
+               r1 = camel_sexp_term_eval (f, argv[0]);
+               r2 = camel_sexp_term_eval (f, argv[1]);
 
-               if (r1->type == ESEXP_RES_INT)
+               if (r1->type == CAMEL_SEXP_RES_INT)
                        g_string_append_printf(str, "%d", r1->value.number);
-               else if (r1->type == ESEXP_RES_TIME)
+               else if (r1->type == CAMEL_SEXP_RES_TIME)
                        g_string_append_printf(str, "%ld", r1->value.time);
-               else if (r1->type == ESEXP_RES_STRING)
+               else if (r1->type == CAMEL_SEXP_RES_STRING)
                        g_string_append_printf(str, "%s", r1->value.string);
 
                if (!strstr(str->str, "completed-on") && !strstr(str->str, "follow-up")) {
@@ -201,13 +201,13 @@ eval_eq (struct _ESExp *f,
                                g_string_append_printf(str, " LIKE ");
                        else
                                g_string_append_printf(str, " = ");
-                       if (r2->type == ESEXP_RES_INT)
+                       if (r2->type == CAMEL_SEXP_RES_INT)
                                g_string_append_printf(str, "%d", r2->value.number);
-                       if (r2->type == ESEXP_RES_BOOL)
+                       if (r2->type == CAMEL_SEXP_RES_BOOL)
                                g_string_append_printf(str, "%d", r2->value.boolean);
-                       else if (r2->type == ESEXP_RES_TIME)
+                       else if (r2->type == CAMEL_SEXP_RES_TIME)
                                g_string_append_printf(str, "%ld", r2->value.time);
-                       else if (r2->type == ESEXP_RES_STRING) {
+                       else if (r2->type == CAMEL_SEXP_RES_STRING) {
                                gchar *tmp = g_strdup_printf("%c%s%c", ut ? '%':' ', r2->value.string, ut?'%':' ');
                                gchar *safe = get_db_safe_string (tmp);
                                g_string_append_printf(str, "%s", safe);
@@ -215,8 +215,8 @@ eval_eq (struct _ESExp *f,
                                g_free (tmp);
                        }
                }
-               e_sexp_result_free (f, r1);
-               e_sexp_result_free (f, r2);
+               camel_sexp_result_free (f, r1);
+               camel_sexp_result_free (f, r2);
                g_string_append (str, " )");
                r->value.string = str->str;
                g_string_free (str, FALSE);
@@ -226,39 +226,39 @@ eval_eq (struct _ESExp *f,
        return r;
 }
 
-static ESExpResult *
-eval_lt (struct _ESExp *f,
+static CamelSExpResult *
+eval_lt (struct _CamelSExp *f,
          gint argc,
-         struct _ESExpTerm **argv,
+         struct _CamelSExpTerm **argv,
          gpointer data)
 {
-       struct _ESExpResult *r, *r1, *r2;
+       struct _CamelSExpResult *r, *r1, *r2;
 
-       r = e_sexp_result_new (f, ESEXP_RES_STRING);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_STRING);
 
        if (argc == 2) {
                GString *str = g_string_new("( ");
-               r1 = e_sexp_term_eval (f, argv[0]);
-               r2 = e_sexp_term_eval (f, argv[1]);
+               r1 = camel_sexp_term_eval (f, argv[0]);
+               r2 = camel_sexp_term_eval (f, argv[1]);
 
-               if (r1->type == ESEXP_RES_INT)
+               if (r1->type == CAMEL_SEXP_RES_INT)
                        g_string_append_printf(str, "%d", r1->value.number);
-               else if (r1->type == ESEXP_RES_TIME)
+               else if (r1->type == CAMEL_SEXP_RES_TIME)
                        g_string_append_printf(str, "%ld", r1->value.time);
-               else if (r1->type == ESEXP_RES_STRING)
+               else if (r1->type == CAMEL_SEXP_RES_STRING)
                        g_string_append_printf(str, "%s", r1->value.string);
 
                g_string_append_printf(str, " < ");
-               if (r2->type == ESEXP_RES_INT)
+               if (r2->type == CAMEL_SEXP_RES_INT)
                        g_string_append_printf(str, "%d", r2->value.number);
-               if (r2->type == ESEXP_RES_BOOL)
+               if (r2->type == CAMEL_SEXP_RES_BOOL)
                        g_string_append_printf(str, "%d", r2->value.boolean);
-               else if (r2->type == ESEXP_RES_TIME)
+               else if (r2->type == CAMEL_SEXP_RES_TIME)
                        g_string_append_printf(str, "%ld", r2->value.time);
-               else if (r2->type == ESEXP_RES_STRING)
+               else if (r2->type == CAMEL_SEXP_RES_STRING)
                        g_string_append_printf(str, "%s", r2->value.string);
-               e_sexp_result_free (f, r1);
-               e_sexp_result_free (f, r2);
+               camel_sexp_result_free (f, r1);
+               camel_sexp_result_free (f, r2);
                g_string_append (str, " )");
 
                r->value.string = str->str;
@@ -268,39 +268,39 @@ eval_lt (struct _ESExp *f,
 }
 
 /* this should support all arguments ...? */
-static ESExpResult *
-eval_gt (struct _ESExp *f,
+static CamelSExpResult *
+eval_gt (struct _CamelSExp *f,
          gint argc,
-         struct _ESExpTerm **argv,
+         struct _CamelSExpTerm **argv,
          gpointer data)
 {
-       struct _ESExpResult *r, *r1, *r2;
+       struct _CamelSExpResult *r, *r1, *r2;
 
-       r = e_sexp_result_new (f, ESEXP_RES_STRING);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_STRING);
 
        if (argc == 2) {
                GString *str = g_string_new("( ");
-               r1 = e_sexp_term_eval (f, argv[0]);
-               r2 = e_sexp_term_eval (f, argv[1]);
+               r1 = camel_sexp_term_eval (f, argv[0]);
+               r2 = camel_sexp_term_eval (f, argv[1]);
 
-               if (r1->type == ESEXP_RES_INT)
+               if (r1->type == CAMEL_SEXP_RES_INT)
                        g_string_append_printf(str, "%d", r1->value.number);
-               else if (r1->type == ESEXP_RES_TIME)
+               else if (r1->type == CAMEL_SEXP_RES_TIME)
                        g_string_append_printf(str, "%ld", r1->value.time);
-               else if (r1->type == ESEXP_RES_STRING)
+               else if (r1->type == CAMEL_SEXP_RES_STRING)
                        g_string_append_printf(str, "%s", r1->value.string);
 
                g_string_append_printf(str, " > ");
-               if (r2->type == ESEXP_RES_INT)
+               if (r2->type == CAMEL_SEXP_RES_INT)
                        g_string_append_printf(str, "%d", r2->value.number);
-               if (r2->type == ESEXP_RES_BOOL)
+               if (r2->type == CAMEL_SEXP_RES_BOOL)
                        g_string_append_printf(str, "%d", r2->value.boolean);
-               else if (r2->type == ESEXP_RES_TIME)
+               else if (r2->type == CAMEL_SEXP_RES_TIME)
                        g_string_append_printf(str, "%ld", r2->value.time);
-               else if (r2->type == ESEXP_RES_STRING)
+               else if (r2->type == CAMEL_SEXP_RES_STRING)
                        g_string_append_printf(str, "%s", r2->value.string);
-               e_sexp_result_free (f, r1);
-               e_sexp_result_free (f, r2);
+               camel_sexp_result_free (f, r1);
+               camel_sexp_result_free (f, r2);
                g_string_append (str, " )");
 
                r->value.string = str->str;
@@ -309,22 +309,22 @@ eval_gt (struct _ESExp *f,
        return r;
 }
 
-static ESExpResult *
-match_all (struct _ESExp *f,
+static CamelSExpResult *
+match_all (struct _CamelSExp *f,
            gint argc,
-           struct _ESExpTerm **argv,
+           struct _CamelSExpTerm **argv,
            gpointer data)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
 
        d(printf("executing match-all: %d", argc));
        if (argc == 0) {
-               r = e_sexp_result_new (f, ESEXP_RES_STRING);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_STRING);
                r->value.string = g_strdup ("1");
-       } else if (argv[0]->type != ESEXP_TERM_BOOL)
-               r = e_sexp_term_eval (f, argv[0]);
+       } else if (argv[0]->type != CAMEL_SEXP_TERM_BOOL)
+               r = camel_sexp_term_eval (f, argv[0]);
        else {
-               r = e_sexp_result_new (f, ESEXP_RES_STRING);
+               r = camel_sexp_result_new (f, CAMEL_SEXP_RES_STRING);
                r->value.string = g_strdup(argv[0]->value.boolean ? "1" : "0");
        }
 
@@ -332,46 +332,46 @@ match_all (struct _ESExp *f,
 
 }
 
-static ESExpResult *
-match_threads (struct _ESExp *f,
+static CamelSExpResult *
+match_threads (struct _CamelSExp *f,
                gint argc,
-               struct _ESExpTerm **argv,
+               struct _CamelSExpTerm **argv,
                gpointer data)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        gint i;
        GString *str = g_string_new ("( ");
 
        d(printf("executing match-threads: %d", argc));
 
        for (i = 1; i < argc; i++) {
-               r = e_sexp_term_eval (f, argv[i]);
+               r = camel_sexp_term_eval (f, argv[i]);
                g_string_append_printf(str, "%s%s", r->value.string, ((argc>1) && (i != argc-1)) ?  " AND ":"");
-               e_sexp_result_free (f, r);
+               camel_sexp_result_free (f, r);
        }
 
        g_string_append (str, " )");
-       r = e_sexp_result_new (f, ESEXP_RES_STRING);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_STRING);
        r->value.string = str->str;
        g_string_free (str, FALSE);
 
        return r;
 }
 
-static ESExpResult *
-check_header (struct _ESExp *f,
+static CamelSExpResult *
+check_header (struct _CamelSExp *f,
               gint argc,
-              struct _ESExpResult **argv,
+              struct _CamelSExpResult **argv,
               gpointer data,
               camel_search_match_t how)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        gchar *str = NULL;
 
        d(printf("executing check-header %d\n", how));
 
        /* are we inside a match-all? */
-       if (argc > 1 && argv[0]->type == ESEXP_RES_STRING) {
+       if (argc > 1 && argv[0]->type == CAMEL_SEXP_RES_STRING) {
                gchar *headername;
                gint i;
 
@@ -380,7 +380,7 @@ check_header (struct _ESExp *f,
 
                /* performs an OR of all words */
                for (i = 1; i < argc; i++) {
-                       if (argv[i]->type == ESEXP_RES_STRING) {
+                       if (argv[i]->type == CAMEL_SEXP_RES_STRING) {
                                gchar *value = NULL, *tstr = NULL;
                                if (argv[i]->value.string[0] == 0)
                                        continue;
@@ -409,16 +409,16 @@ check_header (struct _ESExp *f,
        }
        /* TODO: else, find all matches */
 
-       r = e_sexp_result_new (f, ESEXP_RES_STRING);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_STRING);
        r->value.string = str;
 
        return r;
 }
 
-static ESExpResult *
-header_contains (struct _ESExp *f,
+static CamelSExpResult *
+header_contains (struct _CamelSExp *f,
                  gint argc,
-                 struct _ESExpResult **argv,
+                 struct _CamelSExpResult **argv,
                  gpointer data)
 {
        d(printf("executing header-contains: %d", argc));
@@ -426,10 +426,10 @@ header_contains (struct _ESExp *f,
        return check_header (f, argc, argv, data, CAMEL_SEARCH_MATCH_CONTAINS);
 }
 
-static ESExpResult *
-header_matches (struct _ESExp *f,
+static CamelSExpResult *
+header_matches (struct _CamelSExp *f,
                 gint argc,
-                struct _ESExpResult **argv,
+                struct _CamelSExpResult **argv,
                 gpointer data)
 {
        d(printf("executing header-matches: %d", argc));
@@ -437,10 +437,10 @@ header_matches (struct _ESExp *f,
        return check_header (f, argc, argv, data, CAMEL_SEARCH_MATCH_EXACT);
 }
 
-static ESExpResult *
-header_starts_with (struct _ESExp *f,
+static CamelSExpResult *
+header_starts_with (struct _CamelSExp *f,
                     gint argc,
-                    struct _ESExpResult **argv,
+                    struct _CamelSExpResult **argv,
                     gpointer data)
 {
        d(printf("executing header-starts-with: %d", argc));
@@ -448,10 +448,10 @@ header_starts_with (struct _ESExp *f,
        return check_header (f, argc, argv, data, CAMEL_SEARCH_MATCH_STARTS);
 }
 
-static ESExpResult *
-header_ends_with (struct _ESExp *f,
+static CamelSExpResult *
+header_ends_with (struct _CamelSExp *f,
                   gint argc,
-                  struct _ESExpResult **argv,
+                  struct _CamelSExpResult **argv,
                   gpointer data)
 {
        d(printf("executing header-ends-with: %d", argc));
@@ -459,35 +459,35 @@ header_ends_with (struct _ESExp *f,
        return check_header (f, argc, argv, data, CAMEL_SEARCH_MATCH_ENDS);
 }
 
-static ESExpResult *
-header_exists (struct _ESExp *f,
+static CamelSExpResult *
+header_exists (struct _CamelSExp *f,
                gint argc,
-               struct _ESExpResult **argv,
+               struct _CamelSExpResult **argv,
                gpointer data)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        gchar *headername;
 
        d(printf("executing header-exists: %d", argc));
 
        headername = camel_db_get_column_name (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_printf ("(%s NOTNULL)", headername);
        g_free (headername);
        return r;
 }
 
-static ESExpResult *
-user_tag (struct _ESExp *f,
+static CamelSExpResult *
+user_tag (struct _CamelSExp *f,
           gint argc,
-          struct _ESExpResult **argv,
+          struct _CamelSExpResult **argv,
           gpointer data)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
 
        d(printf("executing user-tag: %d", argc));
 
-       r = e_sexp_result_new (f, ESEXP_RES_STRING);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_STRING);
        /* Hacks no otherway to fix these really :( */
        if (g_strcmp0 (argv[0]->value.string, "completed-on") == 0)
                r->value.string = g_strdup_printf("(usertags LIKE '%ccompleted-on 0%c' AND usertags LIKE '%ccompleted-on%c')", '%', '%', '%', '%');
@@ -499,18 +499,18 @@ user_tag (struct _ESExp *f,
        return r;
 }
 
-static ESExpResult *
-user_flag (struct _ESExp *f,
+static CamelSExpResult *
+user_flag (struct _CamelSExp *f,
            gint argc,
-           struct _ESExpResult **argv,
+           struct _CamelSExpResult **argv,
            gpointer data)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        gchar *tstr, *qstr;
 
        d(printf("executing user-flag: %d", argc));
 
-       r = e_sexp_result_new (f, ESEXP_RES_STRING);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_STRING);
 
        if (argc != 1) {
                r->value.string = g_strdup ("(0)");
@@ -525,18 +525,18 @@ user_flag (struct _ESExp *f,
        return r;
 }
 
-static ESExpResult *
-system_flag (struct _ESExp *f,
+static CamelSExpResult *
+system_flag (struct _CamelSExp *f,
              gint argc,
-             struct _ESExpResult **argv,
+             struct _CamelSExpResult **argv,
              gpointer data)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        gchar *tstr;
 
        d(printf("executing system-flag: %d", argc));
 
-       r = e_sexp_result_new (f, ESEXP_RES_STRING);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_STRING);
 
        if (argc != 1) {
                r->value.string = g_strdup ("(0)");
@@ -549,107 +549,107 @@ system_flag (struct _ESExp *f,
        return r;
 }
 
-static ESExpResult *
-get_sent_date (struct _ESExp *f,
+static CamelSExpResult *
+get_sent_date (struct _CamelSExp *f,
                gint argc,
-               struct _ESExpResult **argv,
+               struct _CamelSExpResult **argv,
                gpointer data)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
 
        d(printf("executing get-sent-date\n"));
 
-       r = e_sexp_result_new (f, ESEXP_RES_STRING);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_STRING);
        r->value.string = g_strdup("dsent");
 
        return r;
 }
 
-static ESExpResult *
-get_received_date (struct _ESExp *f,
+static CamelSExpResult *
+get_received_date (struct _CamelSExp *f,
                    gint argc,
-                   struct _ESExpResult **argv,
+                   struct _CamelSExpResult **argv,
                    gpointer data)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
 
        d(printf("executing get-received-date\n"));
 
-       r = e_sexp_result_new (f, ESEXP_RES_STRING);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_STRING);
        r->value.string = g_strdup("dreceived");
 
        return r;
 }
 
-static ESExpResult *
-get_current_date (struct _ESExp *f,
+static CamelSExpResult *
+get_current_date (struct _CamelSExp *f,
                   gint argc,
-                  struct _ESExpResult **argv,
+                  struct _CamelSExpResult **argv,
                   gpointer data)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
 
        d(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 *
-get_relative_months (struct _ESExp *f,
+static CamelSExpResult *
+get_relative_months (struct _CamelSExp *f,
                      gint argc,
-                     struct _ESExpResult **argv,
+                     struct _CamelSExpResult **argv,
                      gpointer data)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
 
        d(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 *
-get_size (struct _ESExp *f,
+static CamelSExpResult *
+get_size (struct _CamelSExp *f,
           gint argc,
-          struct _ESExpResult **argv,
+          struct _CamelSExpResult **argv,
           gpointer data)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
 
        d(printf("executing get-size\n"));
 
-       r = e_sexp_result_new (f, ESEXP_RES_STRING);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_STRING);
        r->value.string = g_strdup("size/1024");
 
        return r;
 }
 
-static ESExpResult *
-sql_exp (struct _ESExp *f,
+static CamelSExpResult *
+sql_exp (struct _CamelSExp *f,
          gint argc,
-         struct _ESExpResult **argv,
+         struct _CamelSExpResult **argv,
          gpointer data)
 {
-       ESExpResult *r;
+       CamelSExpResult *r;
        gint i;
        GString *str = g_string_new (NULL);
 
        d(printf("executing sql-exp\n"));
 
-       r = e_sexp_result_new (f, ESEXP_RES_STRING);
+       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_STRING);
        for (i = 0; i < argc; i++) {
-               if (argv[i]->type == ESEXP_RES_STRING && argv[i]->value.string)
+               if (argv[i]->type == CAMEL_SEXP_RES_STRING && argv[i]->value.string)
                        g_string_append (str, argv[i]->value.string);
        }
        r->value.string = str->str;
@@ -661,18 +661,18 @@ sql_exp (struct _ESExp *f,
 /* 'builtin' functions */
 static struct {
        const gchar *name;
-       ESExpFunc *func;
+       CamelSExpFunc func;
        guint immediate :1;
 } symbols[] = {
-       { "and", (ESExpFunc *) func_and, 1 },
-       { "or", (ESExpFunc *) func_or, 1},
-       { "not", (ESExpFunc *) func_not, 1},
-       { "=", (ESExpFunc *)eval_eq, 1},
-       { ">", (ESExpFunc *)eval_gt, 1},
-       { "<", (ESExpFunc *)eval_lt, 1},
-
-       { "match-all", (ESExpFunc *)match_all, 1 },
-       { "match-threads", (ESExpFunc *)match_threads, 1 },
+       { "and", (CamelSExpFunc) func_and, 1 },
+       { "or", (CamelSExpFunc) func_or, 1},
+       { "not", (CamelSExpFunc) func_not, 1},
+       { "=", (CamelSExpFunc)eval_eq, 1},
+       { ">", (CamelSExpFunc)eval_gt, 1},
+       { "<", (CamelSExpFunc)eval_lt, 1},
+
+       { "match-all", (CamelSExpFunc)match_all, 1 },
+       { "match-threads", (CamelSExpFunc)match_threads, 1 },
 /*     { "body-contains", body_contains}, */ /* We don't store body on the db. */
        { "header-contains", header_contains, 0},
        { "header-matches", header_matches, 0},
@@ -700,38 +700,38 @@ static struct {
 gchar *
 camel_sexp_to_sql_sexp (const gchar *sql)
 {
-       ESExp *sexp;
-       ESExpResult *r;
+       CamelSExp *sexp;
+       CamelSExpResult *r;
        gint i;
        gchar *res;
 
-       sexp = e_sexp_new ();
+       sexp = camel_sexp_new ();
 
        for (i = 0; i < G_N_ELEMENTS (symbols); i++) {
                if (symbols[i].immediate)
-                       e_sexp_add_ifunction (sexp, 0, symbols[i].name,
-                                            (ESExpIFunc *) symbols[i].func, NULL);
+                       camel_sexp_add_ifunction (sexp, 0, symbols[i].name,
+                                            (CamelSExpIFunc) symbols[i].func, NULL);
                else
-                       e_sexp_add_function (sexp, 0, symbols[i].name,
+                       camel_sexp_add_function (sexp, 0, symbols[i].name,
                                            symbols[i].func, NULL);
        }
 
-       e_sexp_input_text (sexp, sql, strlen (sql));
-       e_sexp_parse (sexp);
+       camel_sexp_input_text (sexp, sql, strlen (sql));
+       camel_sexp_parse (sexp);
 
-       r = e_sexp_eval (sexp);
+       r = camel_sexp_eval (sexp);
        if (!r) {
-               e_sexp_unref (sexp);
+               g_object_unref (sexp);
                return NULL;
        }
 
-       if (r->type == ESEXP_RES_STRING) {
+       if (r->type == CAMEL_SEXP_RES_STRING) {
                res = g_strdup (r->value.string);
        } else
                g_assert (0);
 
-       e_sexp_result_free (sexp, r);
-       e_sexp_unref (sexp);
+       camel_sexp_result_free (sexp, r);
+       g_object_unref (sexp);
 
        return res;
 }
diff --git a/camel/camel-sexp.c b/camel/camel-sexp.c
new file mode 100644 (file)
index 0000000..31c8e2d
--- /dev/null
@@ -0,0 +1,1861 @@
+/*
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ * A simple, extensible s-exp evaluation engine.
+ *
+ * Author :
+ *  Michael Zucchi <notzed@ximian.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+/*
+ *   The following built-in s-exp's are supported:
+ *
+ *   list = (and list*)
+ *      perform an intersection of a number of lists, and return that.
+ *
+ *   bool = (and bool*)
+ *      perform a boolean AND of boolean values.
+ *
+ *   list = (or list*)
+ *      perform a union of a number of lists, returning the new list.
+ *
+ *   bool = (or bool*)
+ *      perform a boolean OR of boolean values.
+ *
+ *   gint = (+ int*)
+ *      Add integers.
+ *
+ *   string = (+ string*)
+ *      Concat strings.
+ *
+ *   time_t = (+ time_t*)
+ *      Add time_t values.
+ *
+ *   gint = (- gint int*)
+ *      Subtract integers from the first.
+ *
+ *   time_t = (- time_t*)
+ *      Subtract time_t values from the first.
+ *
+ *   gint = (cast-int string|int|bool)
+ *         Cast to an integer value.
+ *
+ *   string = (cast-string string|int|bool)
+ *         Cast to an string value.
+ *
+ *   Comparison operators:
+ *
+ *   bool = (< gint gint)
+ *   bool = (> gint gint)
+ *   bool = (= gint gint)
+ *
+ *   bool = (< string string)
+ *   bool = (> string string)
+ *   bool = (= string string)
+ *
+ *   bool = (< time_t time_t)
+ *   bool = (> time_t time_t)
+ *   bool = (= time_t time_t)
+ *      Perform a comparision of 2 integers, 2 string values, or 2 time values.
+ *
+ *   Function flow:
+ *
+ *   type = (if bool function)
+ *   type = (if bool function function)
+ *      Choose a flow path based on a boolean value
+ *
+ *   type = (begin  func func func)
+ *         Execute a sequence.  The last function return is the return type.
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <string.h>
+
+#include "camel-sexp.h"
+
+#define p(x)                   /* parse debug */
+#define r(x)                   /* run debug */
+#define d(x)                   /* general debug */
+
+G_DEFINE_TYPE (CamelSExp, camel_sexp, G_TYPE_OBJECT)
+
+static CamelSExpTerm * parse_list (CamelSExp *sexp, gint gotbrace);
+static CamelSExpTerm * parse_value (CamelSExp *sexp);
+
+#ifdef TESTER
+static void parse_dump_term (CamelSExpTerm *term, gint depth);
+#endif
+
+typedef gboolean       (CamelSGeneratorFunc)   (gint argc,
+                                                CamelSExpResult **argv,
+                                                CamelSExpResult *result);
+typedef gboolean       (CamelSOperatorFunc)    (gint argc,
+                                                CamelSExpResult **argv,
+                                                CamelSExpResult *result);
+
+/* FIXME: constant _TIME_MAX used in different files, move it somewhere */
+#define _TIME_MAX      ((time_t) INT_MAX)      /* Max valid time_t     */
+
+static const GScannerConfig scanner_config =
+{
+       ( (gchar *) " \t\r\n")          /* cset_skip_characters */,
+       ( (gchar *) G_CSET_a_2_z
+         "_+-<=>?"
+         G_CSET_A_2_Z)                 /* cset_identifier_first */,
+       ( (gchar *) G_CSET_a_2_z
+         "_0123456789-<>?"
+         G_CSET_A_2_Z
+         G_CSET_LATINS
+         G_CSET_LATINC )               /* cset_identifier_nth */,
+       ( (gchar *) ";\n" )             /* cpair_comment_single */,
+
+       FALSE                           /* case_sensitive */,
+
+       TRUE                            /* skip_comment_multi */,
+       TRUE                            /* skip_comment_single */,
+       TRUE                            /* scan_comment_multi */,
+       TRUE                            /* scan_identifier */,
+       TRUE                            /* scan_identifier_1char */,
+       FALSE                           /* scan_identifier_NULL */,
+       TRUE                            /* scan_symbols */,
+       FALSE                           /* scan_binary */,
+       TRUE                            /* scan_octal */,
+       TRUE                            /* scan_float */,
+       TRUE                            /* scan_hex */,
+       FALSE                           /* scan_hex_dollar */,
+       TRUE                            /* scan_string_sq */,
+       TRUE                            /* scan_string_dq */,
+       TRUE                            /* numbers_2_int */,
+       FALSE                           /* int_2_float */,
+       FALSE                           /* identifier_2_string */,
+       TRUE                            /* char_2_token */,
+       FALSE                           /* symbol_2_token */,
+       FALSE                           /* scope_0_fallback */,
+};
+
+/**
+ * camel_sexp_fatal_error:
+ *
+ * Since: 3.4
+ **/
+void
+camel_sexp_fatal_error (CamelSExp *sexp,
+                        const gchar *why,
+                        ...)
+{
+       va_list args;
+
+       /* jumps back to the caller of sexp->failenv,
+        * only to be called from inside a callback */
+
+       if (sexp->error)
+               g_free (sexp->error);
+
+       va_start (args, why);
+       sexp->error = g_strdup_vprintf (why, args);
+       va_end (args);
+
+       longjmp (sexp->failenv, 1);
+}
+
+/**
+ * camel_sexp_error:
+ *
+ * Since: 3.4
+ **/
+const gchar *
+camel_sexp_error (CamelSExp *sexp)
+{
+       return sexp->error;
+}
+
+/**
+ * camel_sexp_result_new:
+ *
+ * Since: 3.4
+ **/
+CamelSExpResult *
+camel_sexp_result_new (CamelSExp *sexp,
+                       gint type)
+{
+       CamelSExpResult *result;
+
+       result = camel_memchunk_alloc0 (sexp->result_chunks);
+       result->type = type;
+       result->occuring_start = 0;
+       result->occuring_end = _TIME_MAX;
+       result->time_generator = FALSE;
+
+       return result;
+}
+
+/**
+ * camel_sexp_result_free:
+ *
+ * Since: 3.4
+ **/
+void
+camel_sexp_result_free (CamelSExp *sexp,
+                        CamelSExpResult *term)
+{
+       if (term == NULL)
+               return;
+
+       switch (term->type) {
+       case CAMEL_SEXP_RES_ARRAY_PTR:
+               g_ptr_array_free (term->value.ptrarray, TRUE);
+               break;
+       case CAMEL_SEXP_RES_BOOL:
+       case CAMEL_SEXP_RES_INT:
+       case CAMEL_SEXP_RES_TIME:
+               break;
+       case CAMEL_SEXP_RES_STRING:
+               g_free (term->value.string);
+               break;
+       case CAMEL_SEXP_RES_UNDEFINED:
+               break;
+       default:
+               g_assert_not_reached ();
+       }
+       camel_memchunk_free (sexp->result_chunks, term);
+}
+
+/**
+ * camel_sexp_resultv_free:
+ *
+ * Since: 3.4
+ **/
+void
+camel_sexp_resultv_free (CamelSExp *sexp,
+                         gint argc,
+                         CamelSExpResult **argv)
+{
+       gint i;
+
+       /* used in normal functions if they have to abort,
+        * and free their arguments */
+
+       for (i = 0; i < argc; i++) {
+               camel_sexp_result_free (sexp, argv[i]);
+       }
+}
+
+/* implementations for the builtin functions */
+
+/* we can only itereate a hashtable from a called function */
+struct IterData {
+       gint count;
+       GPtrArray *uids;
+};
+
+/* ok, store any values that are in all sets */
+static void
+htand (gchar *key,
+       gint value,
+       struct IterData *iter_data)
+{
+       if (value == iter_data->count) {
+               g_ptr_array_add (iter_data->uids, key);
+       }
+}
+
+/* or, store all unique values */
+static void
+htor (gchar *key,
+      gint value,
+      struct IterData *iter_data)
+{
+       g_ptr_array_add (iter_data->uids, key);
+}
+
+static CamelSExpResult *
+term_eval_and (CamelSExp *sexp,
+               gint argc,
+               CamelSExpTerm **argv,
+               gpointer data)
+{
+       CamelSExpResult *result, *r1;
+       GHashTable *ht = g_hash_table_new (g_str_hash, g_str_equal);
+       struct IterData lambdafoo;
+       gint type=-1;
+       gint bool = TRUE;
+       gint i;
+       const gchar *oper;
+
+       r(printf("( and\n"));
+
+       result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_UNDEFINED);
+
+       oper = "AND";
+       sexp->operators = g_slist_prepend (sexp->operators, (gpointer) oper);
+
+       for (i = 0; bool && i < argc; i++) {
+               r1 = camel_sexp_term_eval (sexp, argv[i]);
+               if (type == -1)
+                       type = r1->type;
+               if (type != r1->type) {
+                       camel_sexp_result_free (sexp, result);
+                       camel_sexp_result_free (sexp, r1);
+                       g_hash_table_destroy (ht);
+                       camel_sexp_fatal_error(sexp, "Invalid types in AND");
+               } else if (r1->type == CAMEL_SEXP_RES_ARRAY_PTR) {
+                       gchar **a1;
+                       gint l1, j;
+
+                       a1 = (gchar **) r1->value.ptrarray->pdata;
+                       l1 = r1->value.ptrarray->len;
+                       for (j = 0; j < l1; j++) {
+                               gpointer ptr;
+                               gint n;
+                               ptr = g_hash_table_lookup (ht, a1[j]);
+                               n = GPOINTER_TO_INT (ptr);
+                               g_hash_table_insert (ht, a1[j], GINT_TO_POINTER (n + 1));
+                       }
+               } else if (r1->type == CAMEL_SEXP_RES_BOOL) {
+                       bool = bool && r1->value.boolean;
+               }
+               camel_sexp_result_free (sexp, r1);
+       }
+
+       if (type == CAMEL_SEXP_RES_ARRAY_PTR) {
+               lambdafoo.count = argc;
+               lambdafoo.uids = g_ptr_array_new ();
+               g_hash_table_foreach (ht, (GHFunc) htand, &lambdafoo);
+               result->type = CAMEL_SEXP_RES_ARRAY_PTR;
+               result->value.ptrarray = lambdafoo.uids;
+       } else if (type == CAMEL_SEXP_RES_BOOL) {
+               result->type = CAMEL_SEXP_RES_BOOL;
+               result->value.boolean = bool;
+       }
+
+       g_hash_table_destroy (ht);
+       sexp->operators = g_slist_remove (sexp->operators, oper);
+
+       return result;
+}
+
+static CamelSExpResult *
+term_eval_or (CamelSExp *sexp,
+              gint argc,
+              CamelSExpTerm **argv,
+              gpointer data)
+{
+       CamelSExpResult *result, *r1;
+       GHashTable *ht = g_hash_table_new (g_str_hash, g_str_equal);
+       struct IterData lambdafoo;
+       gint type = -1;
+       gint bool = FALSE;
+       gint i;
+       const gchar *oper;
+
+       r(printf("(or \n"));
+
+       oper = "OR";
+       sexp->operators = g_slist_prepend (sexp->operators, (gpointer) oper);
+
+       result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_UNDEFINED);
+
+       for (i = 0; !bool && i < argc; i++) {
+               r1 = camel_sexp_term_eval (sexp, argv[i]);
+               if (type == -1)
+                       type = r1->type;
+               if (r1->type != type) {
+                       camel_sexp_result_free (sexp, result);
+                       camel_sexp_result_free (sexp, r1);
+                       g_hash_table_destroy (ht);
+                       camel_sexp_fatal_error(sexp, "Invalid types in OR");
+               } else if (r1->type == CAMEL_SEXP_RES_ARRAY_PTR) {
+                       gchar **a1;
+                       gint l1, j;
+
+                       a1 = (gchar **) r1->value.ptrarray->pdata;
+                       l1 = r1->value.ptrarray->len;
+                       for (j = 0; j < l1; j++) {
+                               g_hash_table_insert (ht, a1[j], (gpointer) 1);
+                       }
+               } else if (r1->type == CAMEL_SEXP_RES_BOOL) {
+                       bool |= r1->value.boolean;
+               }
+               camel_sexp_result_free (sexp, r1);
+       }
+
+       if (type == CAMEL_SEXP_RES_ARRAY_PTR) {
+               lambdafoo.count = argc;
+               lambdafoo.uids = g_ptr_array_new ();
+               g_hash_table_foreach (ht, (GHFunc) htor, &lambdafoo);
+               result->type = CAMEL_SEXP_RES_ARRAY_PTR;
+               result->value.ptrarray = lambdafoo.uids;
+       } else if (type == CAMEL_SEXP_RES_BOOL) {
+               result->type = CAMEL_SEXP_RES_BOOL;
+               result->value.boolean = bool;
+       }
+       g_hash_table_destroy (ht);
+
+       sexp->operators = g_slist_remove (sexp->operators, oper);
+       return result;
+}
+
+static CamelSExpResult *
+term_eval_not (CamelSExp *sexp,
+               gint argc,
+               CamelSExpResult **argv,
+               gpointer data)
+{
+       gint res = TRUE;
+       CamelSExpResult *result;
+
+       if (argc > 0) {
+               if (argv[0]->type == CAMEL_SEXP_RES_BOOL
+                   && argv[0]->value.boolean)
+                       res = FALSE;
+       }
+       result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_BOOL);
+       result->value.boolean = res;
+
+       return result;
+}
+
+/* this should support all arguments ...? */
+static CamelSExpResult *
+term_eval_lt (CamelSExp *sexp,
+              gint argc,
+              CamelSExpTerm **argv,
+              gpointer data)
+{
+       CamelSExpResult *result, *r1, *r2;
+
+       result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_UNDEFINED);
+
+       if (argc == 2) {
+               r1 = camel_sexp_term_eval (sexp, argv[0]);
+               r2 = camel_sexp_term_eval (sexp, argv[1]);
+               if (r1->type != r2->type) {
+                       camel_sexp_result_free (sexp, r1);
+                       camel_sexp_result_free (sexp, r2);
+                       camel_sexp_result_free (sexp, result);
+                       camel_sexp_fatal_error(sexp, "Incompatible types in compare <");
+               } else if (r1->type == CAMEL_SEXP_RES_INT) {
+                       result->type = CAMEL_SEXP_RES_BOOL;
+                       result->value.boolean = r1->value.number < r2->value.number;
+               } else if (r1->type == CAMEL_SEXP_RES_TIME) {
+                       result->type = CAMEL_SEXP_RES_BOOL;
+                       result->value.boolean = r1->value.time < r2->value.time;
+               } else if (r1->type == CAMEL_SEXP_RES_STRING) {
+                       result->type = CAMEL_SEXP_RES_BOOL;
+                       result->value.boolean = strcmp (r1->value.string, r2->value.string) < 0;
+               }
+               camel_sexp_result_free (sexp, r1);
+               camel_sexp_result_free (sexp, r2);
+       }
+       return result;
+}
+
+/* this should support all arguments ...? */
+static CamelSExpResult *
+term_eval_gt (CamelSExp *sexp,
+              gint argc,
+              CamelSExpTerm **argv,
+              gpointer data)
+{
+       CamelSExpResult *result, *r1, *r2;
+
+       result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_UNDEFINED);
+
+       if (argc == 2) {
+               r1 = camel_sexp_term_eval (sexp, argv[0]);
+               r2 = camel_sexp_term_eval (sexp, argv[1]);
+               if (r1->type != r2->type) {
+                       camel_sexp_result_free (sexp, r1);
+                       camel_sexp_result_free (sexp, r2);
+                       camel_sexp_result_free (sexp, result);
+                       camel_sexp_fatal_error(sexp, "Incompatible types in compare >");
+               } else if (r1->type == CAMEL_SEXP_RES_INT) {
+                       result->type = CAMEL_SEXP_RES_BOOL;
+                       result->value.boolean = r1->value.number > r2->value.number;
+               } else if (r1->type == CAMEL_SEXP_RES_TIME) {
+                       result->type = CAMEL_SEXP_RES_BOOL;
+                       result->value.boolean = r1->value.time > r2->value.time;
+               } else if (r1->type == CAMEL_SEXP_RES_STRING) {
+                       result->type = CAMEL_SEXP_RES_BOOL;
+                       result->value.boolean = strcmp (r1->value.string, r2->value.string) > 0;
+               }
+               camel_sexp_result_free (sexp, r1);
+               camel_sexp_result_free (sexp, r2);
+       }
+       return result;
+}
+
+/* this should support all arguments ...? */
+static CamelSExpResult *
+term_eval_eq (CamelSExp *sexp,
+              gint argc,
+              CamelSExpTerm **argv,
+              gpointer data)
+{
+       CamelSExpResult *result, *r1, *r2;
+
+       result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_BOOL);
+
+       if (argc == 2) {
+               r1 = camel_sexp_term_eval (sexp, argv[0]);
+               r2 = camel_sexp_term_eval (sexp, argv[1]);
+               if (r1->type != r2->type) {
+                       result->value.boolean = FALSE;
+               } else if (r1->type == CAMEL_SEXP_RES_INT) {
+                       result->value.boolean = r1->value.number == r2->value.number;
+               } else if (r1->type == CAMEL_SEXP_RES_BOOL) {
+                       result->value.boolean = r1->value.boolean == r2->value.boolean;
+               } else if (r1->type == CAMEL_SEXP_RES_TIME) {
+                       result->value.boolean = r1->value.time == r2->value.time;
+               } else if (r1->type == CAMEL_SEXP_RES_STRING) {
+                       result->value.boolean = strcmp (r1->value.string, r2->value.string) == 0;
+               }
+               camel_sexp_result_free (sexp, r1);
+               camel_sexp_result_free (sexp, r2);
+       }
+       return result;
+}
+
+static CamelSExpResult *
+term_eval_plus (CamelSExp *sexp,
+                gint argc,
+                CamelSExpResult **argv,
+                gpointer data)
+{
+       CamelSExpResult *result = NULL;
+       gint type;
+       gint i;
+
+       if (argc > 0) {
+               type = argv[0]->type;
+               switch (type) {
+               case CAMEL_SEXP_RES_INT: {
+                       gint total = argv[0]->value.number;
+                       for (i = 1; i < argc && argv[i]->type == CAMEL_SEXP_RES_INT; i++) {
+                               total += argv[i]->value.number;
+                       }
+                       if (i < argc) {
+                               camel_sexp_resultv_free (sexp, argc, argv);
+                               camel_sexp_fatal_error(sexp, "Invalid types in (+ ints)");
+                       }
+                       result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_INT);
+                       result->value.number = total;
+                       break; }
+               case CAMEL_SEXP_RES_STRING: {
+                       GString *string = g_string_new (argv[0]->value.string);
+                       for (i = 1; i < argc && argv[i]->type == CAMEL_SEXP_RES_STRING; i++) {
+                               g_string_append (string, argv[i]->value.string);
+                       }
+                       if (i < argc) {
+                               camel_sexp_resultv_free (sexp, argc, argv);
+                               camel_sexp_fatal_error(sexp, "Invalid types in (+ strings)");
+                       }
+                       result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_STRING);
+                       result->value.string = string->str;
+                       g_string_free (string, FALSE);
+                       break; }
+               case CAMEL_SEXP_RES_TIME: {
+                       time_t total;
+
+                       total = argv[0]->value.time;
+
+                       for (i = 1; i < argc && argv[i]->type == CAMEL_SEXP_RES_TIME; i++)
+                               total += argv[i]->value.time;
+
+                       if (i < argc) {
+                               camel_sexp_resultv_free (sexp, argc, argv);
+                               camel_sexp_fatal_error (sexp, "Invalid types in (+ time_t)");
+                       }
+
+                       result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_TIME);
+                       result->value.time = total;
+                       break; }
+               }
+       }
+
+       if (result == NULL) {
+               result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_INT);
+               result->value.number = 0;
+       }
+
+       return result;
+}
+
+static CamelSExpResult *
+term_eval_sub (CamelSExp *sexp,
+               gint argc,
+               CamelSExpResult **argv,
+               gpointer data)
+{
+       CamelSExpResult *result = NULL;
+       gint type;
+       gint i;
+
+       if (argc > 0) {
+               type = argv[0]->type;
+               switch (type) {
+               case CAMEL_SEXP_RES_INT: {
+                       gint total = argv[0]->value.number;
+                       for (i = 1; i < argc && argv[i]->type == CAMEL_SEXP_RES_INT; i++) {
+                               total -= argv[i]->value.number;
+                       }
+                       if (i < argc) {
+                               camel_sexp_resultv_free (sexp, argc, argv);
+                               camel_sexp_fatal_error(sexp, "Invalid types in -");
+                       }
+                       result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_INT);
+                       result->value.number = total;
+                       break; }
+               case CAMEL_SEXP_RES_TIME: {
+                       time_t total;
+
+                       total = argv[0]->value.time;
+
+                       for (i = 1; i < argc && argv[i]->type == CAMEL_SEXP_RES_TIME; i++)
+                               total -= argv[i]->value.time;
+
+                       if (i < argc) {
+                               camel_sexp_resultv_free (sexp, argc, argv);
+                               camel_sexp_fatal_error (sexp, "Invalid types in (- time_t)");
+                       }
+
+                       result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_TIME);
+                       result->value.time = total;
+                       break; }
+               }
+       }
+
+       if (result == NULL) {
+               result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_INT);
+               result->value.number = 0;
+       }
+       return result;
+}
+
+/* cast to gint */
+static CamelSExpResult *
+term_eval_castint (CamelSExp *sexp,
+                   gint argc,
+                   CamelSExpResult **argv,
+                   gpointer data)
+{
+       CamelSExpResult *result;
+
+       if (argc != 1)
+               camel_sexp_fatal_error(sexp, "Incorrect argument count to (gint )");
+
+       result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_INT);
+       switch (argv[0]->type) {
+       case CAMEL_SEXP_RES_INT:
+               result->value.number = argv[0]->value.number;
+               break;
+       case CAMEL_SEXP_RES_BOOL:
+               result->value.number = argv[0]->value.boolean != 0;
+               break;
+       case CAMEL_SEXP_RES_STRING:
+               result->value.number = strtoul (argv[0]->value.string, NULL, 10);
+               break;
+       default:
+               camel_sexp_result_free (sexp, result);
+               camel_sexp_fatal_error(sexp, "Invalid type in (cast-int )");
+       }
+
+       return result;
+}
+
+/* cast to string */
+static CamelSExpResult *
+term_eval_caststring (CamelSExp *sexp,
+                      gint argc,
+                      CamelSExpResult **argv,
+                      gpointer data)
+{
+       CamelSExpResult *result;
+
+       if (argc != 1)
+               camel_sexp_fatal_error(sexp, "Incorrect argument count to (cast-string )");
+
+       result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_STRING);
+       switch (argv[0]->type) {
+       case CAMEL_SEXP_RES_INT:
+               result->value.string = g_strdup_printf("%d", argv[0]->value.number);
+               break;
+       case CAMEL_SEXP_RES_BOOL:
+               result->value.string = g_strdup_printf("%d", argv[0]->value.boolean != 0);
+               break;
+       case CAMEL_SEXP_RES_STRING:
+               result->value.string = g_strdup (argv[0]->value.string);
+               break;
+       default:
+               camel_sexp_result_free (sexp, result);
+               camel_sexp_fatal_error(sexp, "Invalid type in (gint )");
+       }
+
+       return result;
+}
+
+/* implements 'if' function */
+static CamelSExpResult *
+term_eval_if (CamelSExp *sexp,
+              gint argc,
+              CamelSExpTerm **argv,
+              gpointer data)
+{
+       CamelSExpResult *result;
+       gint doit;
+
+       if (argc >=2 && argc <= 3) {
+               result = camel_sexp_term_eval (sexp, argv[0]);
+               doit = (result->type == CAMEL_SEXP_RES_BOOL && result->value.boolean);
+               camel_sexp_result_free (sexp, result);
+               if (doit) {
+                       return camel_sexp_term_eval (sexp, argv[1]);
+               } else if (argc > 2) {
+                       return camel_sexp_term_eval (sexp, argv[2]);
+               }
+       }
+       return camel_sexp_result_new (sexp, CAMEL_SEXP_RES_UNDEFINED);
+}
+
+/* implements 'begin' statement */
+static CamelSExpResult *
+term_eval_begin (CamelSExp *sexp,
+                 gint argc,
+                 CamelSExpTerm **argv,
+                 gpointer data)
+{
+       CamelSExpResult *result = NULL;
+       gint i;
+
+       for (i = 0; i < argc; i++) {
+               if (result != NULL)
+                       camel_sexp_result_free (sexp, result);
+               result = camel_sexp_term_eval (sexp, argv[i]);
+       }
+       if (result != NULL)
+               return result;
+       else
+               return camel_sexp_result_new (sexp, CAMEL_SEXP_RES_UNDEFINED);
+}
+
+/**
+ * camel_sexp_term_eval:
+ *
+ * Since: 3.4
+ **/
+CamelSExpResult *
+camel_sexp_term_eval (CamelSExp *sexp,
+                      CamelSExpTerm *term)
+{
+       CamelSExpResult *result = NULL;
+       gint i;
+       CamelSExpResult **argv;
+
+       /* this must only be called from inside term evaluation callbacks! */
+
+       g_return_val_if_fail (term != NULL, NULL);
+
+       r(printf("eval term :\n"));
+       r (parse_dump_term (term, 0));
+
+       switch (term->type) {
+       case CAMEL_SEXP_TERM_STRING:
+               r(printf(" (string \"%s\")\n", term->value.string));
+               result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_STRING);
+               /* erk, this shoul;dn't need to strdup this ... */
+               result->value.string = g_strdup (term->value.string);
+               break;
+       case CAMEL_SEXP_TERM_INT:
+               r(printf(" (gint %d)\n", term->value.number));
+               result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_INT);
+               result->value.number = term->value.number;
+               break;
+       case CAMEL_SEXP_TERM_BOOL:
+               r(printf(" (gint %d)\n", term->value.number));
+               result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_BOOL);
+               result->value.boolean = term->value.boolean;
+               break;
+       case CAMEL_SEXP_TERM_TIME:
+               r(printf(" (time_t %ld)\n", term->value.time));
+               result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_TIME);
+               result->value.time = term->value.time;
+               break;
+       case CAMEL_SEXP_TERM_IFUNC:
+               if (term->value.func.sym && term->value.func.sym->f.ifunc)
+                       result = term->value.func.sym->f.ifunc (sexp, term->value.func.termcount, term->value.func.terms, term->value.func.sym->data);
+               break;
+       case CAMEL_SEXP_TERM_FUNC:
+               /* first evaluate all arguments to result types */
+               argv = alloca (sizeof (argv[0]) * term->value.func.termcount);
+               for (i = 0; i < term->value.func.termcount; i++) {
+                       argv[i] = camel_sexp_term_eval (sexp, term->value.func.terms[i]);
+               }
+               /* call the function */
+               if (term->value.func.sym->f.func)
+                       result = term->value.func.sym->f.func (sexp, term->value.func.termcount, argv, term->value.func.sym->data);
+
+               camel_sexp_resultv_free (sexp, term->value.func.termcount, argv);
+               break;
+       default:
+               camel_sexp_fatal_error(sexp, "Unknown type in parse tree: %d", term->type);
+       }
+
+       if (result == NULL)
+               result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_UNDEFINED);
+
+       return result;
+}
+
+#ifdef TESTER
+static void
+eval_dump_result (CamelSExpResult *result,
+                  gint depth)
+{
+       gint i;
+
+       if (result == NULL) {
+               printf("null result???\n");
+               return;
+       }
+
+       for (i = 0; i < depth; i++)
+               printf("   ");
+
+       switch (result->type) {
+       case CAMEL_SEXP_RES_ARRAY_PTR:
+               printf("array pointers\n");
+               break;
+       case CAMEL_SEXP_RES_INT:
+               printf("int: %d\n", result->value.number);
+               break;
+       case CAMEL_SEXP_RES_STRING:
+               printf("string: '%s'\n", result->value.string);
+               break;
+       case CAMEL_SEXP_RES_BOOL:
+               printf("bool: %c\n", result->value.boolean?'t':'f');
+               break;
+       case CAMEL_SEXP_RES_TIME:
+               printf("time_t: %ld\n", (glong) result->value.time);
+               break;
+       case CAMEL_SEXP_RES_UNDEFINED:
+               printf(" <undefined>\n");
+               break;
+       }
+       printf("\n");
+}
+#endif
+
+#ifdef TESTER
+static void
+parse_dump_term (CamelSExpTerm *term,
+                 gint depth)
+{
+       gint i;
+
+       if (t == NULL) {
+               printf("null term??\n");
+               return;
+       }
+
+       for (i = 0; i < depth; i++)
+               printf("   ");
+
+       switch (term->type) {
+       case CAMEL_SEXP_TERM_STRING:
+               printf(" \"%s\"", term->value.string);
+               break;
+       case CAMEL_SEXP_TERM_INT:
+               printf(" %d", term->value.number);
+               break;
+       case CAMEL_SEXP_TERM_BOOL:
+               printf(" #%c", term->value.boolean?'t':'f');
+               break;
+       case CAMEL_SEXP_TERM_TIME:
+               printf(" %ld", (glong) term->value.time);
+               break;
+       case CAMEL_SEXP_TERM_IFUNC:
+       case CAMEL_SEXP_TERM_FUNC:
+               printf(" (function %s\n", term->value.func.sym->name);
+               /*printf(" [%d] ", term->value.func.termcount);*/
+               for (i = 0; i < term->value.func.termcount; i++) {
+                       parse_dump_term (term->value.func.terms[i], depth + 1);
+               }
+               for (i = 0; i < depth; i++)
+                       printf("   ");
+               printf(" )");
+               break;
+       case CAMEL_SEXP_TERM_VAR:
+               printf(" (variable %s )\n", term->value.var->name);
+               break;
+       default:
+               printf("unknown type: %d\n", term->type);
+       }
+
+       printf("\n");
+}
+#endif
+
+const gchar *time_functions[] = {
+       "time-now",
+       "make-time",
+       "time-add-day",
+       "time-day-begin",
+       "time-day-end"
+};
+
+static gboolean
+occur_in_time_range_generator (gint argc,
+                               CamelSExpResult **argv,
+                               CamelSExpResult *result)
+{
+       g_return_val_if_fail (result != NULL, FALSE);
+       g_return_val_if_fail (argc == 2 || argc == 3, FALSE);
+
+       if ((argv[0]->type != CAMEL_SEXP_RES_TIME) || (argv[1]->type != CAMEL_SEXP_RES_TIME))
+               return FALSE;
+
+       result->occuring_start = argv[0]->value.time;
+       result->occuring_end = argv[1]->value.time;
+
+       return TRUE;
+}
+
+static gboolean
+binary_generator (gint argc,
+                  CamelSExpResult **argv,
+                  CamelSExpResult *result)
+{
+       g_return_val_if_fail (result != NULL, FALSE);
+       g_return_val_if_fail (argc == 2, FALSE);
+
+       if ((argv[0]->type != CAMEL_SEXP_RES_TIME) || (argv[1]->type != CAMEL_SEXP_RES_TIME))
+               return FALSE;
+
+       result->occuring_start = argv[0]->value.time;
+       result->occuring_end = argv[1]->value.time;
+
+       return TRUE;
+}
+
+static gboolean
+unary_generator (gint argc,
+                 CamelSExpResult **argv,
+                 CamelSExpResult *result)
+{
+       /* unary generator with end time */
+       g_return_val_if_fail (result != NULL, FALSE);
+       g_return_val_if_fail (argc == 1, FALSE);
+
+       if (argv[0]->type != CAMEL_SEXP_RES_TIME)
+               return FALSE;
+
+       result->occuring_start = 0;
+       result->occuring_end = argv[0]->value.time;
+
+       return TRUE;
+}
+
+static const struct {
+       const gchar *name;
+       CamelSGeneratorFunc *func;
+} generators[] = {
+       {"occur-in-time-range?", occur_in_time_range_generator},
+       {"due-in-time-range?", binary_generator},
+       {"has-alarms-in-range?", binary_generator},
+       {"completed-before?", unary_generator},
+};
+
+const gint generators_count = sizeof (generators) / sizeof (generators[0]);
+
+static gboolean
+or_operator (gint argc,
+             CamelSExpResult **argv,
+             CamelSExpResult *result)
+{
+       gint ii;
+
+       /*
+        * A          B           A or B
+        * ----       ----        ------
+        * norm (0)   norm (0)    norm (0)
+        * gen (1)    norm (0)    norm (0)
+        * norm (0)   gen (1)     norm (0)
+        * gen (1)    gen (1)     gen*(1)
+        */
+
+       g_return_val_if_fail (result != NULL, FALSE);
+       g_return_val_if_fail (argc > 0, FALSE);
+
+       result->time_generator = TRUE;
+       for (ii = 0; ii < argc && result->time_generator; ii++) {
+               result->time_generator = argv[ii]->time_generator;
+       }
+
+       if (result->time_generator) {
+               result->occuring_start = argv[0]->occuring_start;
+               result->occuring_end = argv[0]->occuring_end;
+
+               for (ii = 1; ii < argc; ii++) {
+                       result->occuring_start = MIN (result->occuring_start, argv[ii]->occuring_start);
+                       result->occuring_end = MAX (result->occuring_end, argv[ii]->occuring_end);
+               }
+       }
+
+       return TRUE;
+}
+
+static gboolean
+and_operator (gint argc,
+              CamelSExpResult **argv,
+              CamelSExpResult *result)
+{
+       gint ii;
+
+       /*
+        * A           B          A and B
+        * ----        ----       ------- -
+        * norm (0)     norm (0)    norm (0)
+        * gen (1)      norm (0)    gen (1)
+        * norm (0)     gen (1)     gen (1)
+        * gen (1)      gen (1)     gen (1)
+        * */
+
+       g_return_val_if_fail (result != NULL, FALSE);
+       g_return_val_if_fail (argc > 0, FALSE);
+
+       result->time_generator = FALSE;
+       for (ii = 0; ii < argc && !result->time_generator; ii++) {
+               result->time_generator = argv[ii]->time_generator;
+       }
+
+       if (result->time_generator) {
+               result->occuring_start = argv[0]->occuring_start;
+               result->occuring_end = argv[0]->occuring_end;
+
+               for (ii = 1; ii < argc; ii++) {
+                       result->occuring_start = MAX (result->occuring_start, argv[ii]->occuring_start);
+                       result->occuring_end = MIN (result->occuring_end, argv[ii]->occuring_end);
+               }
+       }
+
+       return TRUE;
+}
+
+static const struct {
+       const gchar *name;
+       CamelSOperatorFunc *func;
+} operators[] = {
+       {"or", or_operator},
+       {"and", and_operator}
+};
+
+const gint operators_count = sizeof (operators) / sizeof (operators[0]);
+
+static CamelSOperatorFunc *
+get_operator_function (const gchar *fname)
+{
+       gint i;
+
+       g_return_val_if_fail (fname != NULL, NULL);
+
+       for (i = 0; i < sizeof (operators) / sizeof (operators[0]); i++)
+               if (strcmp (operators[i].name, fname) == 0)
+                       return operators[i].func;
+
+       return NULL;
+}
+
+static inline gboolean
+is_time_function (const gchar *fname)
+{
+       gint i;
+
+       g_return_val_if_fail (fname != NULL, FALSE);
+
+       for (i = 0; i < sizeof (time_functions) / sizeof (time_functions[0]); i++)
+               if (strcmp (time_functions[i], fname) == 0)
+                       return TRUE;
+
+       return FALSE;
+}
+
+static CamelSGeneratorFunc *
+get_generator_function (const gchar *fname)
+{
+       gint i;
+
+       g_return_val_if_fail (fname != NULL, NULL);
+
+       for (i = 0; i < sizeof (generators) / sizeof (generators[0]); i++)
+               if (strcmp (generators[i].name, fname) == 0)
+                       return generators[i].func;
+
+       return NULL;
+}
+
+/* this must only be called from inside term evaluation callbacks! */
+static CamelSExpResult *
+camel_sexp_term_evaluate_occur_times (CamelSExp *sexp,
+                                      CamelSExpTerm *term,
+                                      time_t *start,
+                                      time_t *end)
+{
+       CamelSExpResult *result = NULL;
+       gint i, argc;
+       CamelSExpResult **argv;
+       gboolean ok = TRUE;
+
+       g_return_val_if_fail (term != NULL, NULL);
+       g_return_val_if_fail (start != NULL, NULL);
+       g_return_val_if_fail (end != NULL, NULL);
+
+       /*
+       printf("eval term :\n");
+       parse_dump_term (t, 0);
+       */
+
+       switch (term->type) {
+       case CAMEL_SEXP_TERM_STRING:
+               r(printf(" (string \"%s\")\n", term->value.string));
+               result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_STRING);
+               result->value.string = g_strdup (term->value.string);
+               break;
+       case CAMEL_SEXP_TERM_IFUNC:
+       case CAMEL_SEXP_TERM_FUNC:
+       {
+               CamelSGeneratorFunc *generator = NULL;
+               CamelSOperatorFunc *operator = NULL;
+
+               r(printf(" (function \"%s\"\n", term->value.func.sym->name));
+
+               result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_UNDEFINED);
+               argc = term->value.func.termcount;
+               argv = alloca (sizeof (argv[0]) * argc);
+
+               for (i = 0; i < term->value.func.termcount; i++) {
+                       argv[i] = camel_sexp_term_evaluate_occur_times (sexp, term->value.func.terms[i],
+                                                                   start, end);
+               }
+
+               if (is_time_function (term->value.func.sym->name)) {
+                       /* evaluate time */
+                       if (term->value.func.sym->f.func)
+                               result = term->value.func.sym->f.func (sexp, term->value.func.termcount,
+                                             argv, term->value.func.sym->data);
+               } else if ((generator = get_generator_function (term->value.func.sym->name)) != NULL) {
+                       /* evaluate generator function */
+                       result->time_generator = TRUE;
+                       ok = generator (argc, argv, result);
+               } else if ((operator = get_operator_function (term->value.func.sym->name)) != NULL)
+                       /* evaluate operator function */
+                       ok = operator (argc, argv, result);
+               else {
+                       /* normal function: we need to scan all objects */
+                       result->time_generator = FALSE;
+               }
+
+               camel_sexp_resultv_free (sexp, term->value.func.termcount, argv);
+               break;
+       }
+       case CAMEL_SEXP_TERM_INT:
+       case CAMEL_SEXP_TERM_BOOL:
+       case CAMEL_SEXP_TERM_TIME:
+               break;
+       default:
+               ok = FALSE;
+               break;
+       }
+
+       if (!ok)
+               camel_sexp_fatal_error(sexp, "Error in parse tree");
+
+       if (result == NULL)
+               result = camel_sexp_result_new (sexp, CAMEL_SEXP_RES_UNDEFINED);
+
+       return result;
+}
+
+/*
+  PARSER
+*/
+
+static CamelSExpTerm *
+parse_term_new (CamelSExp *sexp,
+                gint type)
+{
+       CamelSExpTerm *term;
+
+       term = camel_memchunk_alloc0 (sexp->term_chunks);
+       term->type = type;
+
+       return term;
+}
+
+static void
+parse_term_free (CamelSExp *sexp,
+                 CamelSExpTerm *term)
+{
+       gint i;
+
+       if (term == NULL) {
+               return;
+       }
+
+       switch (term->type) {
+       case CAMEL_SEXP_TERM_INT:
+       case CAMEL_SEXP_TERM_BOOL:
+       case CAMEL_SEXP_TERM_TIME:
+       case CAMEL_SEXP_TERM_VAR:
+               break;
+
+       case CAMEL_SEXP_TERM_STRING:
+               g_free (term->value.string);
+               break;
+
+       case CAMEL_SEXP_TERM_FUNC:
+       case CAMEL_SEXP_TERM_IFUNC:
+               for (i = 0; i < term->value.func.termcount; i++) {
+                       parse_term_free (sexp, term->value.func.terms[i]);
+               }
+               g_free (term->value.func.terms);
+               break;
+
+       default:
+               printf("parse_term_free: unknown type: %d\n", term->type);
+       }
+       camel_memchunk_free (sexp->term_chunks, term);
+}
+
+static CamelSExpTerm **
+parse_values (CamelSExp *sexp,
+              gint *len)
+{
+       gint token;
+       CamelSExpTerm **terms;
+       gint i, size = 0;
+       GScanner *gs = sexp->scanner;
+       GSList *list = NULL, *l;
+
+       p(printf("parsing values\n"));
+
+       while ( (token = g_scanner_peek_next_token (gs)) != G_TOKEN_EOF
+               && token != ')') {
+               list = g_slist_prepend (list, parse_value (sexp));
+               size++;
+       }
+
+       /* go over the list, and put them backwards into the term array */
+       terms = g_malloc (size * sizeof (*terms));
+       l = list;
+       for (i = size - 1; i >= 0; i--) {
+               g_assert (l);
+               g_assert (l->data);
+               terms[i] = l->data;
+               l = g_slist_next (l);
+       }
+       g_slist_free (list);
+
+       p(printf("found %d subterms\n", size));
+       *len = size;
+
+       p(printf("done parsing values\n"));
+       return terms;
+}
+
+/**
+ * camel_sexp_parse_value:
+ *
+ * Since: 3.4
+ **/
+CamelSExpTerm *
+camel_sexp_parse_value (CamelSExp *sexp)
+{
+       return parse_value (sexp);
+}
+
+static CamelSExpTerm *
+parse_value (CamelSExp *sexp)
+{
+       gint token, negative = FALSE;
+       CamelSExpTerm *term = NULL;
+       GScanner *gs = sexp->scanner;
+       CamelSExpSymbol *sym;
+
+       p(printf("parsing value\n"));
+
+       token = g_scanner_get_next_token (gs);
+       switch (token) {
+       case G_TOKEN_EOF:
+               break;
+       case G_TOKEN_LEFT_PAREN:
+               p(printf("got brace, its a list!\n"));
+               return parse_list (sexp, TRUE);
+       case G_TOKEN_STRING:
+               p(printf("got string '%s'\n", g_scanner_cur_value(gs).v_string));
+               term = parse_term_new (sexp, CAMEL_SEXP_TERM_STRING);
+               term->value.string = g_strdup (g_scanner_cur_value (gs).v_string);
+               break;
+       case '-':
+               p(printf ("got negative int?\n"));
+               token = g_scanner_get_next_token (gs);
+               if (token != G_TOKEN_INT) {
+                       camel_sexp_fatal_error (sexp, "Invalid format for a integer value");
+                       return NULL;
+               }
+
+               negative = TRUE;
+               /* fall through... */
+       case G_TOKEN_INT:
+               term = parse_term_new (sexp, CAMEL_SEXP_TERM_INT);
+               term->value.number = g_scanner_cur_value (gs).v_int;
+               if (negative)
+                       term->value.number = -term->value.number;
+               p(printf("got gint %d\n", term->value.number));
+               break;
+       case '#': {
+               gchar *str;
+
+               p(printf("got bool?\n"));
+               token = g_scanner_get_next_token (gs);
+               if (token != G_TOKEN_IDENTIFIER) {
+                       camel_sexp_fatal_error (sexp, "Invalid format for a boolean value");
+                       return NULL;
+               }
+
+               str = g_scanner_cur_value (gs).v_identifier;
+
+               g_assert (str != NULL);
+               if (!(strlen (str) == 1 && (str[0] == 't' || str[0] == 'f'))) {
+                       camel_sexp_fatal_error (sexp, "Invalid format for a boolean value");
+                       return NULL;
+               }
+
+               term = parse_term_new (sexp, CAMEL_SEXP_TERM_BOOL);
+               term->value.boolean = (str[0] == 't');
+               break; }
+       case G_TOKEN_SYMBOL:
+               sym = g_scanner_cur_value (gs).v_symbol;
+               p(printf("got symbol '%s'\n", sym->name));
+               switch (sym->type) {
+               case CAMEL_SEXP_TERM_FUNC:
+               case CAMEL_SEXP_TERM_IFUNC:
+                       /* this is basically invalid, since we can't use function
+                        * pointers, but let the runtime catch it ... */
+                       term = parse_term_new (sexp, sym->type);
+                       term->value.func.sym = sym;
+                       term->value.func.terms = parse_values (sexp, &term->value.func.termcount);
+                       break;
+               case CAMEL_SEXP_TERM_VAR:
+                       term = parse_term_new (sexp, sym->type);
+                       term->value.var = sym;
+                       break;
+               default:
+                       camel_sexp_fatal_error(sexp, "Invalid symbol type: %s: %d", sym->name, sym->type);
+               }
+               break;
+       case G_TOKEN_IDENTIFIER:
+               p(printf("got unknown identifider '%s'\n", g_scanner_cur_value(gs).v_identifier));
+               camel_sexp_fatal_error(sexp, "Unknown identifier: %s", g_scanner_cur_value(gs).v_identifier);
+               break;
+       default:
+               camel_sexp_fatal_error(sexp, "Unexpected token encountered: %d", token);
+       }
+       p(printf("done parsing value\n"));
+
+       return term;
+}
+
+/* FIXME: this needs some robustification */
+static CamelSExpTerm *
+parse_list (CamelSExp *sexp,
+            gint gotbrace)
+{
+       gint token;
+       CamelSExpTerm *term = NULL;
+       GScanner *gs = sexp->scanner;
+
+       p(printf("parsing list\n"));
+       if (gotbrace)
+               token = '(';
+       else
+               token = g_scanner_get_next_token (gs);
+       if (token =='(') {
+               token = g_scanner_get_next_token (gs);
+               switch (token) {
+               case G_TOKEN_SYMBOL: {
+                       CamelSExpSymbol *sym;
+
+                       sym = g_scanner_cur_value (gs).v_symbol;
+                       p(printf("got funciton: %s\n", sym->name));
+                       term = parse_term_new (sexp, sym->type);
+                       p(printf("created new list %p\n", t));
+                       /* if we have a variable, find out its base type */
+                       while (sym->type == CAMEL_SEXP_TERM_VAR) {
+                               sym = ((CamelSExpTerm *)(sym->data))->value.var;
+                       }
+                       if (sym->type == CAMEL_SEXP_TERM_FUNC
+                           || sym->type == CAMEL_SEXP_TERM_IFUNC) {
+                               term->value.func.sym = sym;
+                               term->value.func.terms = parse_values (sexp, &term->value.func.termcount);
+                       } else {
+                               parse_term_free (sexp, term);
+                               camel_sexp_fatal_error(sexp, "Trying to call variable as function: %s", sym->name);
+                       }
+                       break; }
+               case G_TOKEN_IDENTIFIER:
+                       camel_sexp_fatal_error(sexp, "Unknown identifier: %s", g_scanner_cur_value(gs).v_identifier);
+                       break;
+               case G_TOKEN_LEFT_PAREN:
+                       return parse_list (sexp, TRUE);
+               default:
+                       camel_sexp_fatal_error(sexp, "Unexpected token encountered: %d", token);
+               }
+               token = g_scanner_get_next_token (gs);
+               if (token != ')') {
+                       camel_sexp_fatal_error(sexp, "Missing ')'");
+               }
+       } else {
+               camel_sexp_fatal_error(sexp, "Missing '('");
+       }
+
+       p(printf("returning list %p\n", term));
+
+       return term;
+}
+
+static void
+free_symbol (gpointer key,
+             gpointer value,
+             gpointer data)
+{
+       CamelSExpSymbol *sym = value;
+
+       g_free (sym->name);
+       g_free (sym);
+}
+
+static void
+camel_sexp_finalize (GObject *object)
+{
+       CamelSExp *sexp = (CamelSExp *) object;
+
+       if (sexp->tree) {
+               parse_term_free (sexp, sexp->tree);
+               sexp->tree = NULL;
+       }
+
+       camel_memchunk_destroy (sexp->term_chunks);
+       camel_memchunk_destroy (sexp->result_chunks);
+
+       g_scanner_scope_foreach_symbol (sexp->scanner, 0, free_symbol, NULL);
+       g_scanner_destroy (sexp->scanner);
+
+       /* Chain up to parent's finalize() method. */
+       G_OBJECT_CLASS (camel_sexp_parent_class)->finalize (object);
+}
+
+
+static void
+camel_sexp_class_init (CamelSExpClass *class)
+{
+       GObjectClass *object_class;
+
+       object_class = G_OBJECT_CLASS (class);
+       object_class->finalize = camel_sexp_finalize;
+}
+
+/* 'builtin' functions */
+static const struct {
+       const gchar *name;
+       CamelSExpFunc func;
+       gint type;      /* set to 1 if a function can perform shortcut
+                        * evaluation, or doesn't execute everything,
+                        * 0 otherwise */
+} symbols[] = {
+       { "and",         (CamelSExpFunc) term_eval_and, 1 },
+       { "or",          (CamelSExpFunc) term_eval_or, 1 },
+       { "not",         (CamelSExpFunc) term_eval_not, 0 },
+       { "<",           (CamelSExpFunc) term_eval_lt, 1 },
+       { ">",           (CamelSExpFunc) term_eval_gt, 1 },
+       { "=",           (CamelSExpFunc) term_eval_eq, 1 },
+       { "+",           (CamelSExpFunc) term_eval_plus, 0 },
+       { "-",           (CamelSExpFunc) term_eval_sub, 0 },
+       { "cast-int",    (CamelSExpFunc) term_eval_castint, 0 },
+       { "cast-string", (CamelSExpFunc) term_eval_caststring, 0 },
+       { "if",          (CamelSExpFunc) term_eval_if, 1 },
+       { "begin",       (CamelSExpFunc) term_eval_begin, 1 },
+};
+
+static void
+camel_sexp_init (CamelSExp *sexp)
+{
+       gint i;
+
+       sexp->scanner = g_scanner_new (&scanner_config);
+       sexp->term_chunks = camel_memchunk_new (16, sizeof (CamelSExpTerm));
+       sexp->result_chunks = camel_memchunk_new (16, sizeof (CamelSExpResult));
+
+       /* load in builtin symbols? */
+       for (i = 0; i < G_N_ELEMENTS (symbols); i++) {
+               if (symbols[i].type == 1) {
+                       camel_sexp_add_ifunction (
+                               sexp, 0, symbols[i].name,
+                               (CamelSExpIFunc) symbols[i].func,
+                               (gpointer) &symbols[i]);
+               } else {
+                       camel_sexp_add_function (
+                               sexp, 0, symbols[i].name,
+                               symbols[i].func,
+                               (gpointer) &symbols[i]);
+               }
+       }
+}
+
+/**
+ * camel_sexp_new:
+ *
+ * Since: 3.4
+ **/
+CamelSExp *
+camel_sexp_new (void)
+{
+       return g_object_new (CAMEL_TYPE_SEXP, NULL);
+}
+
+/**
+ * camel_sexp_add_function:
+ *
+ * Since: 3.4
+ **/
+void
+camel_sexp_add_function (CamelSExp *sexp,
+                         guint scope,
+                         const gchar *name,
+                         CamelSExpFunc func,
+                         gpointer data)
+{
+       CamelSExpSymbol *sym;
+
+       g_return_if_fail (CAMEL_IS_SEXP (sexp));
+       g_return_if_fail (name != NULL);
+
+       camel_sexp_remove_symbol (sexp, scope, name);
+
+       sym = g_malloc0 (sizeof (*sym));
+       sym->name = g_strdup (name);
+       sym->f.func = func;
+       sym->type = CAMEL_SEXP_TERM_FUNC;
+       sym->data = data;
+
+       g_scanner_scope_add_symbol (sexp->scanner, scope, sym->name, sym);
+}
+
+/**
+ * camel_sexp_add_ifunction:
+ *
+ * Since: 3.4
+ **/
+void
+camel_sexp_add_ifunction (CamelSExp *sexp,
+                          guint scope,
+                          const gchar *name,
+                          CamelSExpIFunc ifunc,
+                          gpointer data)
+{
+       CamelSExpSymbol *sym;
+
+       g_return_if_fail (CAMEL_IS_SEXP (sexp));
+       g_return_if_fail (name != NULL);
+
+       camel_sexp_remove_symbol (sexp, scope, name);
+
+       sym = g_malloc0 (sizeof (*sym));
+       sym->name = g_strdup (name);
+       sym->f.ifunc = ifunc;
+       sym->type = CAMEL_SEXP_TERM_IFUNC;
+       sym->data = data;
+
+       g_scanner_scope_add_symbol (sexp->scanner, scope, sym->name, sym);
+}
+
+/**
+ * camel_sexp_add_variable:
+ *
+ * Since: 3.4
+ **/
+void
+camel_sexp_add_variable (CamelSExp *sexp,
+                         guint scope,
+                         gchar *name,
+                         CamelSExpTerm *value)
+{
+       CamelSExpSymbol *sym;
+
+       g_return_if_fail (CAMEL_IS_SEXP (sexp));
+       g_return_if_fail (name != NULL);
+
+       sym = g_malloc0 (sizeof (*sym));
+       sym->name = g_strdup (name);
+       sym->type = CAMEL_SEXP_TERM_VAR;
+       sym->data = value;
+
+       g_scanner_scope_add_symbol (sexp->scanner, scope, sym->name, sym);
+}
+
+/**
+ * camel_sexp_remove_symbol:
+ *
+ * Since: 3.4
+ **/
+void
+camel_sexp_remove_symbol (CamelSExp *sexp,
+                          guint scope,
+                          const gchar *name)
+{
+       gint oldscope;
+       CamelSExpSymbol *sym;
+
+       g_return_if_fail (CAMEL_IS_SEXP (sexp));
+       g_return_if_fail (name != NULL);
+
+       oldscope = g_scanner_set_scope (sexp->scanner, scope);
+       sym = g_scanner_lookup_symbol (sexp->scanner, name);
+       g_scanner_scope_remove_symbol (sexp->scanner, scope, name);
+       g_scanner_set_scope (sexp->scanner, oldscope);
+       if (sym != NULL) {
+               g_free (sym->name);
+               g_free (sym);
+       }
+}
+
+/**
+ * camel_sexp_set_scope:
+ *
+ * Since: 3.4
+ **/
+gint
+camel_sexp_set_scope (CamelSExp *sexp,
+                      guint scope)
+{
+       g_return_val_if_fail (CAMEL_IS_SEXP (sexp), 0);
+
+       return g_scanner_set_scope (sexp->scanner, scope);
+}
+
+/**
+ * camel_sexp_input_text:
+ *
+ * Since: 3.4
+ **/
+void
+camel_sexp_input_text (CamelSExp *sexp,
+                       const gchar *text,
+                       gint len)
+{
+       g_return_if_fail (CAMEL_IS_SEXP (sexp));
+       g_return_if_fail (text != NULL);
+
+       g_scanner_input_text (sexp->scanner, text, len);
+}
+
+/**
+ * camel_sexp_input_file:
+ *
+ * Since: 3.4
+ **/
+void
+camel_sexp_input_file (CamelSExp *sexp,
+                       gint fd)
+{
+       g_return_if_fail (CAMEL_IS_SEXP (sexp));
+
+       g_scanner_input_file (sexp->scanner, fd);
+}
+
+/**
+ * camel_sexp_parse:
+ *
+ * Since: 3.4
+ **/
+gint
+camel_sexp_parse (CamelSExp *sexp)
+{
+       g_return_val_if_fail (CAMEL_IS_SEXP (sexp), -1);
+
+       if (setjmp (sexp->failenv)) {
+               g_warning("Error in parsing: %s", sexp->error);
+               return -1;
+       }
+
+       if (sexp->tree)
+               parse_term_free (sexp, sexp->tree);
+
+       sexp->tree = parse_value (sexp);
+
+       return 0;
+}
+
+/**
+ * camel_sexp_eval:
+ *
+ * Since: 3.4
+ **/
+CamelSExpResult *
+camel_sexp_eval (CamelSExp *sexp)
+{
+       g_return_val_if_fail (CAMEL_IS_SEXP (sexp), NULL);
+       g_return_val_if_fail (sexp->tree != NULL, NULL);
+
+       if (setjmp (sexp->failenv)) {
+               g_warning("Error in execution: %s", sexp->error);
+               return NULL;
+       }
+
+       return camel_sexp_term_eval (sexp, sexp->tree);
+}
+
+/**
+ * e_cal_backend_sexp_evaluate_occur_times:
+ * @f: An #CamelSExp object.
+ * @start: Start of the time window will be stored here.
+ * @end: End of the time window will be stored here.
+ *
+ * Determines biggest time window given by expressions "occur-in-range" in sexp.
+ *
+ * Since: 3.4
+ */
+gboolean
+camel_sexp_evaluate_occur_times (CamelSExp *sexp,
+                                 time_t *start,
+                                 time_t *end)
+{
+       CamelSExpResult *result;
+       gboolean generator;
+       g_return_val_if_fail (CAMEL_IS_SEXP (sexp), FALSE);
+       g_return_val_if_fail (sexp->tree != NULL, FALSE);
+       g_return_val_if_fail (start != NULL, FALSE);
+       g_return_val_if_fail (end != NULL, FALSE);
+
+       *start = *end = -1;
+
+       if (setjmp (sexp->failenv)) {
+               g_warning("Error in execution: %s", sexp->error);
+               return FALSE;
+       }
+
+       result = camel_sexp_term_evaluate_occur_times (
+               sexp, sexp->tree, start, end);
+       generator = result->time_generator;
+
+       if (generator) {
+               *start = result->occuring_start;
+               *end = result->occuring_end;
+       }
+
+       camel_sexp_result_free (sexp, result);
+
+       return generator;
+}
+
+/**
+ * camel_sexp_encode_bool:
+ * @string:
+ * @v_bool:
+ *
+ * Encode a bool into an s-expression @string.  Bools are
+ * encoded using #t #f syntax.
+ *
+ * Since: 3.4
+ **/
+void
+camel_sexp_encode_bool (GString *string,
+                        gboolean v_bool)
+{
+       if (v_bool)
+               g_string_append (string, " #t");
+       else
+               g_string_append (string, " #f");
+}
+
+/**
+ * camel_sexp_encode_string:
+ * @string: Destination string.
+ * @v_string: String expression.
+ *
+ * Add a c string @v_string to the s-expression stored in
+ * the gstring @s.  Quotes are added, and special characters
+ * are escaped appropriately.
+ *
+ * Since: 3.4
+ **/
+void
+camel_sexp_encode_string (GString *string,
+                          const gchar *v_string)
+{
+       gchar c;
+       const gchar *p;
+
+       if (v_string == NULL)
+               p = "";
+       else
+               p = v_string;
+       g_string_append (string, " \"");
+       while ((c = *p++)) {
+               if (c == '\\' || c == '\"' || c == '\'')
+                       g_string_append_c (string, '\\');
+               g_string_append_c (string, c);
+       }
+       g_string_append (string, "\"");
+}
+
+#ifdef TESTER
+gint
+main (gint argc,
+      gchar **argv)
+{
+       CamelSExp *sexp;
+       gchar *t = "(+ \"foo\" \"\\\"\" \"bar\" \"\\\\ blah \\x \")";
+       CamelSExpResult *result;
+
+       g_type_init ();
+
+       sexp = camel_sexp_new ();
+
+       camel_sexp_add_variable (sexp, 0, "test", NULL);
+
+       if (argc < 2 || !argv[1])
+               return;
+
+       camel_sexp_input_text (sexp, t, t);
+       camel_sexp_parse (sexp);
+
+       if (sexp->tree)
+               parse_dump_term (sexp->tree, 0);
+
+       result = camel_sexp_eval (sexp);
+       if (result) {
+               eval_dump_result (result, 0);
+       } else {
+               printf("no result?|\n");
+       }
+
+       return 0;
+}
+#endif
diff --git a/camel/camel-sexp.h b/camel/camel-sexp.h
new file mode 100644 (file)
index 0000000..50e5ab8
--- /dev/null
@@ -0,0 +1,243 @@
+/*
+ * generic s-exp evaluator class
+*/
+
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_SEXP_H
+#define CAMEL_SEXP_H
+
+#include <setjmp.h>
+#include <time.h>
+#include <glib.h>
+
+#include <glib-object.h>
+
+#include <camel/camel-memchunk.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_SEXP \
+       (camel_sexp_get_type ())
+#define CAMEL_SEXP(obj) \
+       (G_TYPE_CHECK_INSTANCE_CAST \
+       ((obj), CAMEL_TYPE_SEXP, CamelSExp))
+#define CAMEL_SEXP_CLASS(cls) \
+       (G_TYPE_CHECK_CLASS_CAST \
+       ((cls), CAMEL_TYPE_SEXP, CamelSExpClass))
+#define CAMEL_IS_SEXP(obj) \
+       (G_TYPE_CHECK_INSTANCE_TYPE \
+       ((obj), CAMEL_TYPE_SEXP))
+#define CAMEL_IS_SEXP_CLASS(cls) \
+       (G_TYPE_CHECK_CLASS_TYPE \
+       ((cls), CAMEL_TYPE_SEXP))
+#define CAMEL_SEXP_GET_CLASS(obj) \
+       (G_TYPE_INSTANCE_GET_CLASS \
+       ((obj), CAMEL_TYPE_SEXP, CamelSExpClass))
+
+G_BEGIN_DECLS
+
+typedef struct _CamelSExp CamelSExp;
+typedef struct _CamelSExpClass CamelSExpClass;
+
+typedef struct _CamelSExpSymbol CamelSExpSymbol;
+typedef struct _CamelSExpResult CamelSExpResult;
+typedef struct _CamelSExpTerm CamelSExpTerm;
+
+/**
+ * CamelSExpResultType:
+ *
+ * Since: 3.4
+ **/
+typedef enum {
+       CAMEL_SEXP_RES_ARRAY_PTR,       /* type is a ptrarray, what it points to is implementation dependant */
+       CAMEL_SEXP_RES_INT,             /* type is a number */
+       CAMEL_SEXP_RES_STRING,          /* type is a pointer to a single string */
+       CAMEL_SEXP_RES_BOOL,            /* boolean type */
+       CAMEL_SEXP_RES_TIME,            /* time_t type */
+       CAMEL_SEXP_RES_UNDEFINED        /* unknown type */
+} CamelSExpResultType;
+
+/**
+ * CamelSExpResult:
+ *
+ * Since: 3.4
+ **/
+struct _CamelSExpResult {
+       CamelSExpResultType type;
+       union {
+               GPtrArray *ptrarray;
+               gint number;
+               gchar *string;
+               gint boolean;
+               time_t time;
+       } value;
+       gboolean time_generator;
+       time_t occuring_start;
+       time_t occuring_end;
+};
+
+/**
+ * CamelSExpFunc:
+ *
+ * Since: 3.4
+ **/
+typedef CamelSExpResult *
+                       (*CamelSExpFunc)        (CamelSExp *sexp,
+                                                gint argc,
+                                                CamelSExpResult **argv,
+                                                gpointer data);
+
+/**
+ * CamelSExpIFunc:
+ *
+ * Since: 3.4
+ **/
+typedef CamelSExpResult *
+                       (*CamelSExpIFunc)       (CamelSExp *sexp, gint argc,
+                                                CamelSExpTerm **argv,
+                                                gpointer data);
+
+/**
+ * CamelSExpTermType:
+ *
+ * Since: 3.4
+ **/
+typedef enum {
+       CAMEL_SEXP_TERM_INT,    /* integer literal */
+       CAMEL_SEXP_TERM_BOOL,   /* boolean literal */
+       CAMEL_SEXP_TERM_STRING, /* string literal */
+       CAMEL_SEXP_TERM_TIME,   /* time_t literal (number of seconds past the epoch) */
+       CAMEL_SEXP_TERM_FUNC,   /* normal function, arguments are evaluated before calling */
+       CAMEL_SEXP_TERM_IFUNC,  /* immediate function, raw terms are arguments */
+       CAMEL_SEXP_TERM_VAR     /* variable reference */
+} CamelSExpTermType;
+
+/**
+ * CamelSExpSymbol:
+ *
+ * Since: 3.4
+ **/
+struct _CamelSExpSymbol {
+       gint type;              /* TERM_FUNC or TERM_VAR */
+       gchar *name;
+       gpointer data;
+       union {
+               CamelSExpFunc func;
+               CamelSExpIFunc ifunc;
+       } f;
+};
+
+/**
+ * CamelSExpTerm:
+ *
+ * Since: 3.4
+ **/
+struct _CamelSExpTerm {
+       CamelSExpTermType type;
+       union {
+               gchar *string;
+               gint number;
+               gint boolean;
+               time_t time;
+               struct {
+                       CamelSExpSymbol *sym;
+                       CamelSExpTerm **terms;
+                       gint termcount;
+               } func;
+               CamelSExpSymbol *var;
+       } value;
+};
+
+/**
+ * CamelSExp:
+ *
+ * Since: 3.4
+ **/
+struct _CamelSExp {
+       GObject parent;
+       GScanner *scanner;      /* for parsing text version */
+       CamelSExpTerm *tree;    /* root of expression tree */
+
+       /* private stuff */
+       jmp_buf failenv;
+       gchar *error;
+       GSList *operators;
+
+       /* TODO: may also need a pool allocator for term strings,
+        *       so we dont lose them in error conditions? */
+       CamelMemChunk *term_chunks;
+       CamelMemChunk *result_chunks;
+};
+
+struct _CamelSExpClass {
+       GObjectClass parent_class;
+};
+
+GType          camel_sexp_get_type             (void) G_GNUC_CONST;
+CamelSExp *    camel_sexp_new                  (void);
+void           camel_sexp_add_function         (CamelSExp *sexp,
+                                                guint scope,
+                                                const gchar *name,
+                                                CamelSExpFunc func,
+                                                gpointer data);
+void           camel_sexp_add_ifunction        (CamelSExp *sexp,
+                                                guint scope,
+                                                const gchar *name,
+                                                CamelSExpIFunc func,
+                                                gpointer data);
+void           camel_sexp_add_variable         (CamelSExp *sexp,
+                                                guint scope,
+                                                gchar *name,
+                                                CamelSExpTerm *value);
+void           camel_sexp_remove_symbol        (CamelSExp *sexp,
+                                                guint scope,
+                                                const gchar *name);
+gint           camel_sexp_set_scope            (CamelSExp *sexp,
+                                                guint scope);
+void           camel_sexp_input_text           (CamelSExp *sexp,
+                                                const gchar *text,
+                                                gint len);
+void           camel_sexp_input_file           (CamelSExp *sexp,
+                                                gint fd);
+gint           camel_sexp_parse                (CamelSExp *sexp);
+CamelSExpResult *
+               camel_sexp_eval                 (CamelSExp *sexp);
+CamelSExpResult *
+               camel_sexp_term_eval            (CamelSExp *sexp,
+                                                CamelSExpTerm *term);
+CamelSExpResult *
+               camel_sexp_result_new           (CamelSExp *sexp,
+                                                gint type);
+void           camel_sexp_result_free          (CamelSExp *sexp,
+                                                CamelSExpResult *term);
+
+/* used in normal functions if they have to abort, to free their arguments */
+void           camel_sexp_resultv_free         (CamelSExp *sexp,
+                                                gint argc,
+                                                CamelSExpResult **argv);
+
+/* utility functions for creating s-exp strings. */
+void           camel_sexp_encode_bool          (GString *string,
+                                                gboolean v_bool);
+void           camel_sexp_encode_string        (GString *string,
+                                                const gchar *v_string);
+
+/* only to be called from inside a callback to signal a fatal execution error */
+void           camel_sexp_fatal_error          (CamelSExp *sexp,
+                                                const gchar *why,
+                                                ...) G_GNUC_NORETURN;
+
+/* return the error string */
+const gchar *  camel_sexp_error                (CamelSExp *sexp);
+
+CamelSExpTerm *        camel_sexp_parse_value          (CamelSExp *sexp);
+
+gboolean       camel_sexp_evaluate_occur_times (CamelSExp *sexp,
+                                                time_t *start,
+                                                time_t *end);
+
+G_END_DECLS
+
+#endif /* CAMEL_SEXP_H */
index c110694..93dc3c9 100644 (file)
 #include <camel/camel-service.h>
 #include <camel/camel-session.h>
 #include <camel/camel-settings.h>
+#include <camel/camel-sexp.h>
 #include <camel/camel-smime-context.h>
 #include <camel/camel-store.h>
 #include <camel/camel-store-settings.h>
index 9cf2754..6103b47 100644 (file)
@@ -89,7 +89,7 @@ struct _match_record {
        GArray *matches;
 };
 
-static ESExpResult *imap_body_contains (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+static CamelSExpResult *imap_body_contains (struct _CamelSExp *f, gint argc, struct _CamelSExpResult **argv, CamelFolderSearch *s);
 
 G_DEFINE_TYPE (CamelImapSearch, camel_imap_search, CAMEL_TYPE_FOLDER_SEARCH)
 
@@ -187,7 +187,7 @@ camel_imap_search_new (const gchar *cachedir)
 static void
 hash_match (gchar hash[17],
             gint argc,
-            struct _ESExpResult **argv)
+            struct _CamelSExpResult **argv)
 {
        GChecksum *checksum;
        guint8 *digest;
@@ -200,7 +200,7 @@ hash_match (gchar hash[17],
 
        checksum = g_checksum_new (G_CHECKSUM_MD5);
        for (i = 0; i < argc; i++) {
-               if (argv[i]->type == ESEXP_RES_STRING)
+               if (argv[i]->type == CAMEL_SEXP_RES_STRING)
                        g_checksum_update (
                                checksum, (guchar *) argv[i]->value.string, -1);
        }
@@ -264,7 +264,7 @@ static struct _match_record *
 load_match (CamelImapSearch *is,
             gchar hash[17],
             gint argc,
-            struct _ESExpResult **argv)
+            struct _CamelSExpResult **argv)
 {
        struct _match_record *mr;
        CamelStream *stream = NULL;
@@ -277,7 +277,7 @@ load_match (CamelImapSearch *is,
        strcpy (mr->hash, hash);
        mr->terms = g_malloc0 (sizeof (mr->terms[0]) * argc);
        for (i = 0; i < argc; i++) {
-               if (argv[i]->type == ESEXP_RES_STRING) {
+               if (argv[i]->type == CAMEL_SEXP_RES_STRING) {
                        mr->termcount++;
                        mr->terms[i] = g_strdup (argv[i]->value.string);
                }
@@ -396,7 +396,7 @@ sync_match (CamelImapSearch *is,
 static struct _match_record *
 get_match (CamelImapSearch *is,
            gint argc,
-           struct _ESExpResult **argv)
+           struct _CamelSExpResult **argv)
 {
        gchar hash[17];
        struct _match_record *mr;
@@ -432,17 +432,17 @@ get_match (CamelImapSearch *is,
        return mr;
 }
 
-static ESExpResult *
-imap_body_contains (struct _ESExp *f,
+static CamelSExpResult *
+imap_body_contains (struct _CamelSExp *f,
                     gint argc,
-                    struct _ESExpResult **argv,
+                    struct _CamelSExpResult **argv,
                     CamelFolderSearch *s)
 {
        CamelStore *parent_store;
        CamelImapStore *store;
        CamelImapSearch *is = (CamelImapSearch *) s;
        gchar *uid;
-       ESExpResult *r;
+       CamelSExpResult *r;
        GHashTable *uid_hash = NULL;
        GPtrArray *array;
        gint i, j;
@@ -463,10 +463,10 @@ imap_body_contains (struct _ESExp *f,
        /* optimise the match "" case - match everything */
        if (argc == 1 && argv[0]->value.string[0] == '\0') {
                if (s->current) {
-                       r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+                       r = camel_sexp_result_new (f, CAMEL_SEXP_RES_BOOL);
                        r->value.boolean = TRUE;
                } 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 < s->summary->len; i++) {
                                g_ptr_array_add (r->value.ptrarray, (gchar *) g_ptr_array_index (s->summary, i));
@@ -475,10 +475,10 @@ imap_body_contains (struct _ESExp *f,
        } else if (argc == 0 || s->summary->len == 0) {
                /* nothing to match case, do nothing (should be handled higher up?) */
                if (s->current) {
-                       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 ();
                }
        } else {
@@ -496,10 +496,10 @@ imap_body_contains (struct _ESExp *f,
                        j = mr->matches->len;
                        for (i = 0; i < j && !truth; i++)
                                truth = *uidp++ == uidn;
-                       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);
                        array = r->value.ptrarray = g_ptr_array_new ();
 
                        /* We use a hash to map the uid numbers to uid strings as required by the search api */
index 2d9fb7e..20b7e03 100644 (file)
       <xi:include href="xml/camel-net-utils.xml"/>
       <xi:include href="xml/camel-search-sql.xml"/>
       <xi:include href="xml/camel-search-sql-sexp.xml"/>
+      <xi:include href="xml/camel-sexp.xml"/>
       <xi:include href="xml/camel-string-utils.xml"/>
       <xi:include href="xml/camel-trie.xml"/>
       <xi:include href="xml/camel-uid-cache.xml"/>
index 802fa3a..cbb0248 100644 (file)
@@ -2090,6 +2090,49 @@ camel_settings_get_type
 </SECTION>
 
 <SECTION>
+<FILE>camel-sexp</FILE>
+<TITLE>CamelSExp</TITLE>
+CamelSExp
+CamelSExpSymbol
+CamelSExpResult
+CamelSExpTerm
+CamelSExpResultType
+CamelSExpFunc
+CamelSExpIFunc
+CamelSExpTermType
+camel_sexp_new
+camel_sexp_add_function
+camel_sexp_add_ifunction
+camel_sexp_add_variable
+camel_sexp_remove_symbol
+camel_sexp_set_scope
+camel_sexp_input_text
+camel_sexp_input_file
+camel_sexp_parse
+camel_sexp_eval
+camel_sexp_term_eval
+camel_sexp_result_new
+camel_sexp_result_free
+camel_sexp_resultv_free
+camel_sexp_encode_bool
+camel_sexp_encode_string
+camel_sexp_fatal_error
+camel_sexp_error
+camel_sexp_parse_value
+camel_sexp_evaluate_occur_times
+<SUBSECTION Standard>
+CAMEL_SEXP
+CAMEL_IS_SEXP
+CAMEL_TYPE_SEXP
+CAMEL_SEXP_CLASS
+CAMEL_IS_SEXP_CLASS
+CAMEL_SEXP_GET_CLASS
+CamelSExpClass
+<SUBSECTION Private>
+camel_sexp_get_type
+</SECTION>
+
+<SECTION>
 <FILE>camel-smime-context</FILE>
 <TITLE>CamelSMIMEContext</TITLE>
 CamelSMIMEContext
index 70e8aa3..7f2932c 100644 (file)
@@ -69,6 +69,7 @@ camel_sasl_popb4smtp_get_type
 camel_service_get_type
 camel_session_get_type
 camel_settings_get_type
+camel_sexp_get_type
 camel_smime_context_get_type
 camel_store_get_type
 camel_store_settings_get_type