Commit a5709755 authored by Milan Crha's avatar Milan Crha Committed by Rodrigo Moya
Browse files

Bug #650671 - Service connect/disconnect not cancelled properly

parent 290111d5
......@@ -22,6 +22,8 @@
#include "e-mail-session-utils.h"
#include "em-utils.h"
#include <glib/gi18n-lib.h>
#include <mail/mail-tools.h>
......@@ -423,7 +425,7 @@ mail_session_send_to_thread (GSimpleAsyncResult *simple,
did_connect = TRUE;
/* XXX This API does not allow for cancellation. */
if (!camel_service_connect_sync (service, &error)) {
if (!em_utils_connect_service_sync (service, cancellable, &error)) {
g_simple_async_result_set_from_error (simple, error);
g_error_free (error);
return;
......@@ -441,7 +443,7 @@ mail_session_send_to_thread (GSimpleAsyncResult *simple,
context->recipients, cancellable, &error);
if (did_connect)
camel_service_disconnect_sync (service, error == NULL, error ? NULL : &error);
em_utils_disconnect_service_sync (service, error == NULL, cancellable, error ? NULL : &error);
if (error != NULL) {
g_simple_async_result_set_from_error (simple, error);
......@@ -871,8 +873,8 @@ e_mail_session_unsubscribe_folder_sync (EMailSession *session,
/* FIXME This should take our GCancellable. */
success =
camel_service_connect_sync (
CAMEL_SERVICE (store), error) &&
em_utils_connect_service_sync (
CAMEL_SERVICE (store), cancellable, error) &&
camel_store_unsubscribe_folder_sync (
store, folder_name, cancellable, error);
......
......@@ -1045,7 +1045,7 @@ e_mail_session_get_inbox_sync (EMailSession *session,
if (!CAMEL_IS_STORE (service))
return NULL;
if (!camel_service_connect_sync (service, error))
if (!em_utils_connect_service_sync (service, cancellable, error))
return NULL;
return camel_store_get_inbox_folder_sync (
......@@ -1144,7 +1144,7 @@ e_mail_session_get_trash_sync (EMailSession *session,
if (!CAMEL_IS_STORE (service))
return NULL;
if (!camel_service_connect_sync (service, error))
if (!em_utils_connect_service_sync (service, cancellable, error))
return NULL;
return camel_store_get_trash_folder_sync (
......
......@@ -20,6 +20,8 @@
#include <config.h>
#endif
#include "em-utils.h"
#include "e-mail-store-utils.h"
#include <glib/gi18n-lib.h>
......@@ -175,7 +177,7 @@ mail_store_go_offline_thread (GSimpleAsyncResult *simple,
disco_store, CAMEL_DISCO_STORE_OFFLINE,
cancellable, &error);
else
camel_service_disconnect_sync (service, TRUE, &error);
em_utils_disconnect_service_sync (service, TRUE, cancellable, &error);
} else if (CAMEL_IS_OFFLINE_STORE (store)) {
CamelOfflineStore *offline_store;
......@@ -186,7 +188,7 @@ mail_store_go_offline_thread (GSimpleAsyncResult *simple,
offline_store, FALSE, cancellable, &error);
} else
camel_service_disconnect_sync (service, TRUE, &error);
em_utils_disconnect_service_sync (service, TRUE, cancellable, &error);
if (error != NULL) {
g_simple_async_result_set_from_error (simple, error);
......
......@@ -345,7 +345,7 @@ emfu_copy_folder_selected (EMailBackend *backend,
session = e_mail_backend_get_session (backend);
service = CAMEL_SERVICE (cfd->source_store);
camel_service_connect_sync (service, &local_error);
em_utils_connect_service_sync (service, NULL, &local_error);
if (local_error != NULL) {
e_mail_backend_submit_alert (
......@@ -373,8 +373,8 @@ emfu_copy_folder_selected (EMailBackend *backend,
tostore = NULL;
if (tostore != NULL)
camel_service_connect_sync (
CAMEL_SERVICE (tostore), &local_error);
em_utils_connect_service_sync (
CAMEL_SERVICE (tostore), NULL, &local_error);
if (local_error != NULL) {
e_mail_backend_submit_alert (
......
......@@ -2289,3 +2289,52 @@ em_utils_is_local_delivery_mbox_file (CamelURL *url)
g_file_test (url->path, G_FILE_TEST_EXISTS) &&
!g_file_test (url->path, G_FILE_TEST_IS_DIR);
}
static void
cancel_service_connect_cb (GCancellable *cancellable, CamelService *service)
{
g_return_if_fail (service != NULL);
g_return_if_fail (CAMEL_IS_SERVICE (service));
camel_service_cancel_connect (service);
}
gboolean
em_utils_connect_service_sync (CamelService *service, GCancellable *cancellable, GError **error)
{
gboolean res;
gulong handler_id = 0;
g_return_val_if_fail (service != NULL, FALSE);
g_return_val_if_fail (CAMEL_IS_SERVICE (service), FALSE);
if (cancellable)
handler_id = g_cancellable_connect (cancellable, G_CALLBACK (cancel_service_connect_cb), service, NULL);
res = camel_service_connect_sync (service, error);
if (handler_id)
g_cancellable_disconnect (cancellable, handler_id);
return res;
}
gboolean
em_utils_disconnect_service_sync (CamelService *service, gboolean clean, GCancellable *cancellable, GError **error)
{
gboolean res;
gulong handler_id = 0;
g_return_val_if_fail (service != NULL, FALSE);
g_return_val_if_fail (CAMEL_IS_SERVICE (service), FALSE);
if (cancellable)
handler_id = g_cancellable_connect (cancellable, G_CALLBACK (cancel_service_connect_cb), service, NULL);
res = camel_service_disconnect_sync (service, clean, error);
if (handler_id)
g_cancellable_disconnect (cancellable, handler_id);
return res;
}
......@@ -96,6 +96,9 @@ void emu_restore_folder_tree_state (EMFolderTree *folder_tree);
gboolean em_utils_is_local_delivery_mbox_file (CamelURL *url);
gboolean em_utils_connect_service_sync (CamelService *service, GCancellable *cancellable, GError **error);
gboolean em_utils_disconnect_service_sync (CamelService *service, gboolean clean, GCancellable *cancellable, GError **error);
G_END_DECLS
#endif /* __EM_UTILS_H__ */
......@@ -339,7 +339,7 @@ fail:
/* also disconnect if not a local delivery mbox;
there is no need to keep the connection alive forever */
if (!is_local_delivery)
camel_service_disconnect_sync (CAMEL_SERVICE (m->store), TRUE, NULL);
em_utils_disconnect_service_sync (CAMEL_SERVICE (m->store), TRUE, cancellable, NULL);
}
static void
......@@ -580,8 +580,8 @@ mail_send_message (struct _send_queue_msg *m,
}
if (camel_address_length (recipients) > 0) {
if (!camel_service_connect_sync (
CAMEL_SERVICE (transport), error))
if (!em_utils_connect_service_sync (
CAMEL_SERVICE (transport), cancellable, error))
goto exit;
if (!camel_transport_send_to_sync (
......@@ -1597,7 +1597,7 @@ disconnect_service_exec (struct _disconnect_msg *m,
GCancellable *cancellable,
GError **error)
{
camel_service_disconnect_sync (CAMEL_SERVICE (m->store), TRUE, error);
em_utils_disconnect_service_sync (CAMEL_SERVICE (m->store), TRUE, cancellable, error);
}
static void
......
......@@ -1124,7 +1124,7 @@ vfolder_load_storage (EMailBackend *backend)
CAMEL_SESSION (session), "vfolder",
storeuri, CAMEL_PROVIDER_STORE, NULL);
if (service != NULL)
camel_service_connect_sync (service, NULL);
em_utils_connect_service_sync (service, NULL, NULL);
else {
g_warning("Cannot open vfolder store - no vfolders available");
return;
......
......@@ -553,7 +553,7 @@ all_accounts:
/* FIXME Complete lack of error checking here. */
service = camel_session_get_service (
CAMEL_SESSION (session), "vfolder");
camel_service_connect_sync (service, NULL);
em_utils_connect_service_sync (service, NULL, NULL);
search_folder = (CamelVeeFolder *) camel_vee_folder_new (
CAMEL_STORE (service), _("All Account Search"),
......@@ -726,7 +726,7 @@ current_account:
/* FIXME Complete lack of error checking here. */
service = camel_session_get_service (
CAMEL_SESSION (session), "vfolder");
camel_service_connect_sync (service, NULL);
em_utils_connect_service_sync (service, NULL, NULL);
search_folder = (CamelVeeFolder *) camel_vee_folder_new (
CAMEL_STORE (service), _("Account Search"),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment