diff --git a/camel/camel-imapx-store.c b/camel/camel-imapx-store.c
index 33ee30e..0161536 100644
--- a/camel/camel-imapx-store.c
+++ b/camel/camel-imapx-store.c
@@ -1132,11 +1132,30 @@ sync_folders (CamelIMAPXStore *istore,
 	GHashTable *folders_from_server;
 	gboolean notify_all;
 	gint i, total;
+	GError *local_error = NULL;
 
 	folders_from_server = fetch_folders_for_namespaces (
-		istore, pattern, sync, cancellable, error);
-	if (folders_from_server == NULL)
+		istore, pattern, sync, cancellable, &local_error);
+	if (folders_from_server == NULL) {
+		if (local_error)
+			g_propagate_error (error, local_error);
 		return FALSE;
+	}
+
+	/* In certain situations can happen that the function returns data,
+	   even either the operation was cancelled or an error was set,
+	   thus check for this and do not update local list of folders
+	   with incomplete data
+	*/
+	if (g_cancellable_is_cancelled (cancellable) || local_error) {
+		g_hash_table_foreach (folders_from_server, imapx_get_folders_free, NULL);
+		g_hash_table_destroy (folders_from_server);
+
+		if (local_error)
+			g_propagate_error (error, local_error);
+
+		return FALSE;
+	}
 
 	settings = camel_service_ref_settings (CAMEL_SERVICE (istore));
 	notify_all = !camel_imapx_settings_get_use_subscriptions (CAMEL_IMAPX_SETTINGS (settings));
