camel_ews_folder_update_thread (gpointer user_data)
{
	struct ScheduleUpdateData *sud = user_data;
	CamelEwsStore *ews_store = sud->ews_store;
	GSList *update_folder_names, *l;

	g_return_val_if_fail (sud != NULL, NULL);

	UPDATE_LOCK (ews_store);
	update_folder_names = ews_store->priv->update_folder_names;
	ews_store->priv->update_folder_names = NULL;
	UPDATE_UNLOCK (ews_store);

	for (l = update_folder_names; l != NULL && !g_cancellable_is_cancelled (sud->cancellable); l = l->next) {
		const gchar *folder_name = l->data;
		CamelFolder *folder;
		GError *error = NULL;

		folder = camel_store_get_folder_sync (CAMEL_STORE (ews_store), folder_name, 0, sud->cancellable, NULL);
		if (folder == NULL)
			continue;

		camel_folder_refresh_info_sync (folder, sud->cancellable, &error);
		g_object_unref (folder);

		if (error != NULL) {
			g_warning ("%s: %s\n", G_STRFUNC, error->message);
			g_clear_error (&error);
			break;
		}
	}

	g_slist_free_full (update_folder_names, g_free);
	update_folder_names = NULL;
	free_schedule_update_data (sud);

	return NULL;
}
camel_ews_folder_update_thread (gpointer user_data)
{
	struct ScheduleUpdateData *sud = user_data;
	CamelEwsStore *ews_store = sud->ews_store;
	GSList *update_folder_names, *l;

	g_return_val_if_fail (sud != NULL, NULL);

	UPDATE_LOCK (ews_store);
	update_folder_names = ews_store->priv->update_folder_names;
	ews_store->priv->update_folder_names = NULL;
	UPDATE_UNLOCK (ews_store);

	for (l = update_folder_names; l != NULL && !g_cancellable_is_cancelled (sud->cancellable); l = l->next) {
		const gchar *folder_name = l->data;
		CamelFolder *folder;
		GError *error = NULL;

		folder = camel_store_get_folder_sync (CAMEL_STORE (ews_store), folder_name, 0, sud->cancellable, NULL);
		if (folder == NULL)
			continue;

		camel_folder_refresh_info_sync (folder, sud->cancellable, &error);
		g_object_unref (folder);

		if (error != NULL) {
			g_warning ("%s: %s\n", G_STRFUNC, error->message);
			g_clear_error (&error);
			break;
		}
	}

	g_slist_free_full (update_folder_names, g_free);
	update_folder_names = NULL;
	free_schedule_update_data (sud);

	return NULL;
}