[evolution-data-server] Add GCancellable parameter to camel_filter_search_match()



commit 6c9482c4b2b3cb3b4763a58a467190d547245826
Author: Milan Crha <mcrha redhat com>
Date:   Wed Jul 15 10:45:28 2015 +0200

    Add GCancellable parameter to camel_filter_search_match()
    
    This way the junk filtering can be cancelled. This also changes
    camel_filter_driver_filter_message(), to check the cancellable
    and stop processing filter rules early on cancellation.

 camel/camel-filter-driver.c |    8 ++++++--
 camel/camel-filter-search.c |   17 ++++++++++++-----
 camel/camel-filter-search.h |   13 +++++++++----
 configure.ac                |    2 +-
 4 files changed, 28 insertions(+), 12 deletions(-)
---
diff --git a/camel/camel-filter-driver.c b/camel/camel-filter-driver.c
index ce98f64..79b1137 100644
--- a/camel/camel-filter-driver.c
+++ b/camel/camel-filter-driver.c
@@ -1602,6 +1602,7 @@ struct _get_message {
 
 static CamelMimeMessage *
 get_message_cb (gpointer data,
+               GCancellable *cancellable,
                 GError **error)
 {
        struct _get_message *msgdata = data;
@@ -1619,7 +1620,7 @@ get_message_cb (gpointer data,
 
                /* FIXME Pass a GCancellable */
                message = camel_folder_get_message_sync (
-                       msgdata->priv->source, uid, NULL, error);
+                       msgdata->priv->source, uid, cancellable, error);
        }
 
        if (message != NULL && camel_mime_message_get_source (message) == NULL)
@@ -1727,6 +1728,9 @@ camel_filter_driver_filter_message (CamelFilterDriver *driver,
                if (driver->priv->terminated)
                        break;
 
+               if (g_cancellable_set_error_if_cancelled (cancellable, &driver->priv->error))
+                       goto error;
+
                d (printf ("applying rule %s\naction %s\n", rule->match, rule->action));
 
                data.priv = p;
@@ -1737,7 +1741,7 @@ camel_filter_driver_filter_message (CamelFilterDriver *driver,
 
                result = camel_filter_search_match (
                        driver->priv->session, get_message_cb, &data, driver->priv->info,
-                       original_store_uid, source, rule->match, &driver->priv->error);
+                       original_store_uid, source, rule->match, cancellable, &driver->priv->error);
 
                switch (result) {
                case CAMEL_SEARCH_ERROR:
diff --git a/camel/camel-filter-search.c b/camel/camel-filter-search.c
index 1f5c79f..9df10c9 100644
--- a/camel/camel-filter-search.c
+++ b/camel/camel-filter-search.c
@@ -63,6 +63,7 @@ typedef struct {
        CamelMessageInfo *info;
        CamelFolder *folder;
        const gchar *source;
+       GCancellable *cancellable;
        GError **error;
 } FilterMessageSearch;
 
@@ -132,7 +133,7 @@ camel_filter_search_get_message (FilterMessageSearch *fms,
        if (fms->message)
                return fms->message;
 
-       fms->message = fms->get_message (fms->get_message_data, fms->error);
+       fms->message = fms->get_message (fms->get_message_data, fms->cancellable, fms->error);
 
        if (fms->message == NULL)
                camel_sexp_fatal_error (sexp, _("Failed to retrieve message"));
@@ -806,8 +807,8 @@ run_command (struct _CamelSExp *f,
 
        stream = camel_stream_fs_new_with_fd (pipe_to_child);
        camel_data_wrapper_write_to_stream_sync (
-               CAMEL_DATA_WRAPPER (message), stream, NULL, NULL);
-       camel_stream_flush (stream, NULL, NULL);
+               CAMEL_DATA_WRAPPER (message), stream, fms->cancellable, NULL);
+       camel_stream_flush (stream, fms->cancellable, NULL);
        g_object_unref (stream);
 
        context = g_main_context_new ();
@@ -973,7 +974,7 @@ junk_test (struct _CamelSExp *f,
                goto done;
 
        status = camel_junk_filter_classify (
-               junk_filter, message, NULL, &error);
+               junk_filter, message, fms->cancellable, &error);
 
        if (error == NULL) {
                const gchar *status_desc;
@@ -1004,7 +1005,10 @@ junk_test (struct _CamelSExp *f,
                                status_desc);
        } else {
                g_warn_if_fail (status == CAMEL_JUNK_STATUS_ERROR);
-               g_warning ("%s: %s", G_STRFUNC, error->message);
+               if (camel_debug ("junk"))
+                       printf ("Junk classify failed with error: %s\n", error->message);
+               if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+                       g_warning ("%s: %s", G_STRFUNC, error->message);
                g_error_free (error);
                message_is_junk = FALSE;
        }
@@ -1092,6 +1096,7 @@ message_location (struct _CamelSExp *f,
  * @source:
  * @folder: in which folder the message is stored
  * @expression:
+ * @cancellable: (allow-none): a #GCancellable, or %NULL
  * @error: return location for a #GError, or %NULL
  *
  * Returns: one of CAMEL_SEARCH_MATCHED, CAMEL_SEARCH_NOMATCH, or
@@ -1105,6 +1110,7 @@ camel_filter_search_match (CamelSession *session,
                            const gchar *source,
                           CamelFolder *folder,
                            const gchar *expression,
+                          GCancellable *cancellable,
                            GError **error)
 {
        FilterMessageSearch fms;
@@ -1121,6 +1127,7 @@ camel_filter_search_match (CamelSession *session,
        fms.info = info;
        fms.source = source;
        fms.folder = folder;
+       fms.cancellable = cancellable;
        fms.error = &local_error;
 
        sexp = camel_sexp_new ();
diff --git a/camel/camel-filter-search.h b/camel/camel-filter-search.h
index 0b68086..d88ec01 100644
--- a/camel/camel-filter-search.h
+++ b/camel/camel-filter-search.h
@@ -38,12 +38,17 @@ enum {
        CAMEL_SEARCH_MATCHED = 1
 };
 
-typedef CamelMimeMessage * (*CamelFilterSearchGetMessageFunc) (gpointer data, GError **error);
+typedef CamelMimeMessage * (*CamelFilterSearchGetMessageFunc) (gpointer data, GCancellable *cancellable, 
GError **error);
 
 gint camel_filter_search_match (struct _CamelSession *session,
-                               CamelFilterSearchGetMessageFunc get_message, gpointer data,
-                               CamelMessageInfo *info, const gchar *source, struct _CamelFolder *folder,
-                               const gchar *expression, GError **error);
+                               CamelFilterSearchGetMessageFunc get_message,
+                               gpointer data,
+                               CamelMessageInfo *info,
+                               const gchar *source,
+                               struct _CamelFolder *folder,
+                               const gchar *expression,
+                               GCancellable *cancellable,
+                               GError **error);
 
 G_END_DECLS
 
diff --git a/configure.ac b/configure.ac
index 5beb03d..625e3c5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -134,7 +134,7 @@ LIBEBOOK_CONTACTS_CURRENT=2
 LIBEBOOK_CONTACTS_REVISION=0
 LIBEBOOK_CONTACTS_AGE=0
 
-LIBCAMEL_CURRENT=53
+LIBCAMEL_CURRENT=54
 LIBCAMEL_REVISION=0
 LIBCAMEL_AGE=0
 


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