/* Helper for e_mail_store_prepare_for_offline() */ static void mail_store_prepare_for_offline_thread (GSimpleAsyncResult *simple, GObject *source_object, GCancellable *cancellable) { CamelService *service; const gchar *display_name; GError *local_error = NULL; service = CAMEL_SERVICE (source_object); display_name = camel_service_get_display_name (service); if (display_name == NULL || *display_name == '\0') display_name = G_OBJECT_TYPE_NAME (service); camel_operation_push_message ( cancellable, _("Preparing account “%s” for offline"), display_name); if (CAMEL_IS_OFFLINE_STORE (service)) camel_offline_store_prepare_for_offline_sync ( CAMEL_OFFLINE_STORE (service), cancellable, &local_error); if (local_error != NULL) g_simple_async_result_take_error (simple, local_error); camel_operation_pop_message (cancellable); }
static void mail_store_prepare_for_offline_thread (GSimpleAsyncResult *simple, CamelStore *store, GCancellable *cancellable) { CamelService *service; gchar *service_name; GError *error = NULL; service = CAMEL_SERVICE (store); service_name = camel_service_get_name (service, TRUE); camel_operation_push_message ( cancellable, _("Preparing account '%s' for offline"), service_name); g_free (service_name); if (CAMEL_IS_DISCO_STORE (store)) camel_disco_store_prepare_for_offline ( CAMEL_DISCO_STORE (store), cancellable, &error); else if (CAMEL_IS_OFFLINE_STORE (store)) camel_offline_store_prepare_for_offline_sync ( CAMEL_OFFLINE_STORE (store), cancellable, &error); if (error != NULL) g_simple_async_result_take_error (simple, error); camel_operation_pop_message (cancellable); }
gboolean e_mail_store_go_online_sync (CamelStore *store, GCancellable *cancellable, GError **error) { CamelService *service; const gchar *display_name; gboolean success = TRUE; g_return_val_if_fail (CAMEL_IS_STORE (store), FALSE); service = CAMEL_SERVICE (store); display_name = camel_service_get_display_name (service); if (display_name == NULL || *display_name == '\0') display_name = G_OBJECT_TYPE_NAME (service); camel_operation_push_message ( cancellable, _("Reconnecting to “%s”"), display_name); if (CAMEL_IS_OFFLINE_STORE (store)) success = camel_offline_store_set_online_sync ( CAMEL_OFFLINE_STORE (store), TRUE, cancellable, error); camel_operation_pop_message (cancellable); return success; }
static void offline_store_construct (CamelService *service, CamelSession *session, CamelProvider *provider, CamelURL *url, CamelException *ex) { CamelOfflineStore *store = CAMEL_OFFLINE_STORE (service); CAMEL_SERVICE_CLASS (parent_class)->construct (service, session, provider, url, ex); if (camel_exception_is_set (ex)) return; store->state = camel_session_is_online (session) ? CAMEL_OFFLINE_STORE_NETWORK_AVAIL : CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL; }
static void mail_store_go_offline_thread (GSimpleAsyncResult *simple, CamelStore *store, GCancellable *cancellable) { CamelService *service; gchar *service_name; GError *error = NULL; service = CAMEL_SERVICE (store); service_name = camel_service_get_name (service, TRUE); camel_operation_push_message ( cancellable, _("Disconnecting from '%s'"), service_name); g_free (service_name); if (CAMEL_IS_DISCO_STORE (store)) { CamelDiscoStore *disco_store; disco_store = CAMEL_DISCO_STORE (store); if (camel_disco_store_can_work_offline (disco_store)) camel_disco_store_set_status ( disco_store, CAMEL_DISCO_STORE_OFFLINE, cancellable, &error); else em_utils_disconnect_service_sync (service, TRUE, cancellable, &error); } else if (CAMEL_IS_OFFLINE_STORE (store)) { CamelOfflineStore *offline_store; offline_store = CAMEL_OFFLINE_STORE (store); camel_offline_store_set_online_sync ( offline_store, FALSE, cancellable, &error); } else em_utils_disconnect_service_sync (service, TRUE, cancellable, &error); if (error != NULL) g_simple_async_result_take_error (simple, error); camel_operation_pop_message (cancellable); }
static gboolean groupwise_connect_sync (CamelService *service, GCancellable *cancellable, GError **error) { CamelGroupwiseStore *store = CAMEL_GROUPWISE_STORE (service); CamelGroupwiseStorePrivate *priv = store->priv; CamelGroupwiseStoreNamespace *ns; CamelSession *session = service->session; d("in groupwise store connect\n"); if (service->status == CAMEL_SERVICE_DISCONNECTED) return FALSE; if (!priv) { store->priv = g_new0 (CamelGroupwiseStorePrivate, 1); priv = store->priv; camel_service_construct (service, service->session, service->provider, service->url, error); } camel_service_lock (service, CAMEL_SERVICE_REC_CONNECT_LOCK); if (priv->cnc) { camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK); return TRUE; } if (!check_for_connection (service, cancellable, error) || !groupwise_auth_loop (service, cancellable, error)) { camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK); camel_service_disconnect_sync (service, TRUE, NULL); return FALSE; } service->status = CAMEL_SERVICE_CONNECTED; camel_offline_store_set_online_sync ( CAMEL_OFFLINE_STORE (store), TRUE, cancellable, NULL); if (!e_gw_connection_get_version (priv->cnc)) { camel_session_alert_user (session, CAMEL_SESSION_ALERT_WARNING, _("Some features may not work correctly with your current server version"), FALSE); } ns = camel_groupwise_store_summary_namespace_new (store->summary, priv->storage_path, '/'); camel_groupwise_store_summary_namespace_set (store->summary, ns); if (camel_store_summary_count ((CamelStoreSummary *)store->summary) == 0) { /*Settting the refresh stamp to the current time*/ store->refresh_stamp = time (NULL); } camel_store_summary_save ((CamelStoreSummary *) store->summary); camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK); if (E_IS_GW_CONNECTION (priv->cnc)) { return TRUE; } return FALSE; }
/* The worker thread function with all the complex * logic in it! Big fat beast! Please watch your * children ... */ static void synch_worker (struct account_synch_msg *m) { ScalixAccountSynch *sxas; ScalixAccountSynchPrivate *priv; CamelException ex; CamelStore *store; CamelFolderInfo *ftree; CamelFolderInfo *sf; CamelSession *cs; const char *uri; gboolean res; char *sversion; char *markup; sxas = SCALIX_ACCOUNT_SYNCH (m->sxas); priv = SCALIX_ACCOUNT_SYNCH_GET_PRIVATE (sxas); uri = e_account_get_string (priv->account, E_ACCOUNT_SOURCE_URL); g_print ("SxAS: starting synch for %s\n", uri); signal_progress (sxas, 1, _("Trying to connect to server")); camel_exception_init (&ex); cs = scalix_camel_session_get_default (); camel_session_set_online (cs, TRUE); store = camel_session_get_store (cs, uri, &ex); if (store == NULL) { signal_error (sxas, _("Authentication failed. Check for correct hostname, username and password.")); return; } /* Must be online! */ camel_offline_store_set_network_state (CAMEL_OFFLINE_STORE (store), CAMEL_OFFLINE_STORE_NETWORK_AVAIL, &ex); camel_service_connect (CAMEL_SERVICE (store), &ex); if (camel_exception_is_set (&ex)) { signal_error (sxas, _("Error while trying to connect to server.")); return; } /* Always check for minimal required server version */ signal_progress (sxas, 10, _("Checking version of Scalix server")); g_print ("SxAS: Checking for minimal server version\n"); sversion = NULL; camel_object_get (store, NULL, CAMEL_SCALIX_STORE_SERVER_VERSION, &sversion, NULL); res = scalix_check_min_server_version (sversion); if (res == FALSE) { signal_error (sxas, _("Wrong version of Scalix server detected")); return; } m->sversion = g_strdup (sversion); g_print ("SxAS: sversion:%s\n", m->sversion); markup = g_markup_printf_escaped (MSG_SVER, sversion); signal_info (sxas, markup); g_free (markup); signal_progress (sxas, 20, _("Getting list of folders")); ftree = camel_store_get_folder_info (store, NULL, CAMEL_STORE_FOLDER_INFO_RECURSIVE | CAMEL_SCALIX_STORE_SHOW_SFOLDER, &ex); if (ftree == NULL) { camel_object_unref (store); signal_error (sxas, _("Could not obtain folder listening")); return; } /* Calendar */ signal_progress (sxas, 30, _("Loading calendar data...")); synch_data (sxas, ftree, CAMEL_SCALIX_FOLDER_CALENDAR, 30); m->esg_cals = create_group (priv->account, "Calendar"); sync_source_group (priv->account, m->esg_cals, CAMEL_SCALIX_FOLDER_CALENDAR, ftree); /* Contacts */ signal_progress (sxas, 60, _("Loading contacts...")); synch_data (sxas, ftree, CAMEL_SCALIX_FOLDER_CONTACT, 60); m->esg_cnts = create_group (priv->account, "Contacts"); sync_source_group (priv->account, m->esg_cnts, CAMEL_SCALIX_FOLDER_CONTACT, ftree); create_ldap_source (priv->account, m->esg_cnts); /* Sent Items and Drafts Folder */ if (priv->synch_dfolder) { char *url_str; CamelURL *url; url = camel_url_new (uri, NULL); signal_progress (sxas, 95, _("Synchronizing additional data")); sf = folder_tree_find_special (ftree, CAMEL_SCALIX_FOLDER_SENT); if (url && sf) { url_str = url_set_path_and_get_string (url, sf->full_name); e_account_set_string (priv->account, E_ACCOUNT_SENT_FOLDER_URI, url_str); g_free (url_str); } sf = folder_tree_find_special (ftree, CAMEL_SCALIX_FOLDER_DRAFTS); if (url && sf) { url_str = url_set_path_and_get_string (url, sf->full_name); e_account_set_string (priv->account, E_ACCOUNT_DRAFTS_FOLDER_URI, url_str); g_free (url_str); } if (url) { gboolean save_pw; camel_url_set_path (url, NULL); if (url->authmech == NULL) { camel_url_set_authmech (url, "PLAIN"); } url_str = camel_url_to_string (url, 0); e_account_set_string (priv->account, E_ACCOUNT_TRANSPORT_URL, url_str); save_pw = e_account_get_bool (priv->account, E_ACCOUNT_SOURCE_SAVE_PASSWD); e_account_set_bool (priv->account, E_ACCOUNT_TRANSPORT_SAVE_PASSWD, save_pw); } if (url) { camel_url_free (url); } } m->success = TRUE; g_print ("SxAS: DONE!\n"); camel_object_unref (store); signal_progress (sxas, 100, _("Done loading")); signal_info (sxas, _("Initial loading complete. Please click Forward.")); g_print ("SxAS: Freeing DONE\n"); return; }