static CamelFolder * groupwise_get_folder_from_disk (CamelStore *store, const gchar *folder_name, guint32 flags, GCancellable *cancellable, GError **error) { CamelGroupwiseStore *gw_store = CAMEL_GROUPWISE_STORE (store); CamelGroupwiseStorePrivate *priv = gw_store->priv; CamelFolder *folder; gchar *folder_dir, *storage_path; storage_path = g_strdup_printf("%s/folders", priv->storage_path); folder_dir = e_path_to_physical (storage_path, folder_name); g_free (storage_path); if (!folder_dir || g_access (folder_dir, F_OK) != 0) { g_free (folder_dir); g_set_error ( error, CAMEL_STORE_ERROR, CAMEL_STORE_ERROR_NO_FOLDER, _("No such folder %s"), folder_name); return NULL; } folder = camel_gw_folder_new (store, folder_name, folder_dir, cancellable, error); g_free (folder_dir); return folder; }
static void groupwise_forget_folder (CamelGroupwiseStore *gw_store, const gchar *folder_name, GError **error) { CamelGroupwiseStorePrivate *priv = gw_store->priv; gchar *state_file; gchar *folder_dir, *storage_path; CamelFolderInfo *fi; storage_path = g_strdup_printf ("%s/folders", priv->storage_path); folder_dir = e_path_to_physical (storage_path,folder_name); if (g_access (folder_dir, F_OK) != 0) { g_free (folder_dir); return; } state_file = g_strdup_printf ("%s/cmeta", folder_dir); g_unlink (state_file); g_free (state_file); g_rmdir (folder_dir); g_free (folder_dir); camel_store_summary_remove_path ( (CamelStoreSummary *)gw_store->summary, folder_name); camel_store_summary_save ( (CamelStoreSummary *)gw_store->summary); fi = groupwise_build_folder_info (gw_store, NULL, folder_name); camel_store_folder_deleted (CAMEL_STORE (gw_store), fi); camel_folder_info_free (fi); }
/** * e_path_rmdir: * @prefix: a prefix to prepend to the path, or %NULL * @path: the virtual path to convert to a filesystem path. * * This removes the directory pointed to by @prefix and @path * and attempts to remove its parent "subfolders" directory too * if it's empty. * * Return value: -1 (with errno set) if it failed to rmdir the * specified directory. 0 otherwise, whether or not it removed * the parent directory. **/ gint e_path_rmdir (const gchar *prefix, const gchar *vpath) { gchar *physical_path, *p; /* Remove the directory itself */ physical_path = e_path_to_physical (prefix, vpath); if (g_rmdir (physical_path) == -1) { g_free (physical_path); return -1; } /* Attempt to remove its parent "subfolders" directory, * ignoring errors since it might not be empty. */ p = strrchr (physical_path, '/'); if (p[1] == '\0') { g_free (physical_path); return 0; } *p = '\0'; p = strrchr (physical_path, '/'); if (!p || strcmp (p + 1, SUBFOLDER_DIR_NAME) != 0) { g_free (physical_path); return 0; } g_rmdir (physical_path); g_free (physical_path); return 0; }
static void groupwise_forget_folder (CamelGroupwiseStore *gw_store, const char *folder_name, CamelException *ex) { CamelFolderSummary *summary; CamelGroupwiseStorePrivate *priv = gw_store->priv; char *summary_file, *state_file; char *folder_dir, *storage_path; CamelFolderInfo *fi; const char *name; name = folder_name; storage_path = g_strdup_printf ("%s/folders", priv->storage_path); folder_dir = e_path_to_physical (storage_path,folder_name); if (g_access(folder_dir, F_OK) != 0) { g_free(folder_dir); return; } summary_file = g_strdup_printf ("%s/summary", folder_dir); summary = camel_groupwise_summary_new(NULL,summary_file); if(!summary) { g_free(summary_file); g_free(folder_dir); return; } camel_object_unref (summary); g_unlink (summary_file); g_free (summary_file); state_file = g_strdup_printf ("%s/cmeta", folder_dir); g_unlink (state_file); g_free (state_file); g_rmdir (folder_dir); g_free (folder_dir); camel_store_summary_remove_path ( (CamelStoreSummary *)gw_store->summary, folder_name); camel_store_summary_save ( (CamelStoreSummary *)gw_store->summary); fi = groupwise_build_folder_info(gw_store, NULL, folder_name); camel_object_trigger_event (CAMEL_OBJECT (gw_store), "folder_deleted", fi); camel_folder_info_free (fi); }
static CamelFolder * groupwise_get_folder_from_disk (CamelStore *store, const char *folder_name, guint32 flags, CamelException *ex) { CamelGroupwiseStore *gw_store = CAMEL_GROUPWISE_STORE (store); CamelGroupwiseStorePrivate *priv = gw_store->priv; CamelFolder *folder; char *folder_dir, *storage_path; storage_path = g_strdup_printf("%s/folders", priv->storage_path); folder_dir = e_path_to_physical (storage_path, folder_name); g_free(storage_path); if (!folder_dir || g_access (folder_dir, F_OK) != 0) { g_free (folder_dir); camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, _("No such folder %s"), folder_name); return NULL; } folder = camel_gw_folder_new (store, folder_name, folder_dir, ex); g_free (folder_dir); return folder; }
static CamelFolder * groupwise_store_get_folder_sync (CamelStore *store, const gchar *folder_name, CamelStoreGetFolderFlags flags, GCancellable *cancellable, GError **error) { CamelGroupwiseStore *gw_store = CAMEL_GROUPWISE_STORE (store); CamelGroupwiseStorePrivate *priv = gw_store->priv; CamelFolder *folder; CamelGroupwiseSummary *summary; gchar *container_id, *folder_dir, *storage_path; EGwConnectionStatus status; GList *list = NULL; gboolean done = FALSE, all_ok = TRUE; const gchar *position = E_GW_CURSOR_POSITION_END; gint count = 0, cursor, summary_count = 0; CamelStoreInfo *si = NULL; guint total = 0; GError *local_error = NULL; folder = groupwise_get_folder_from_disk ( store, folder_name, flags, cancellable, &local_error); if (folder) { groupwise_store_set_current_folder (gw_store, folder); return folder; /* Ignore "no such folder" errors, fail on any other error. */ } else if (!g_error_matches (local_error, CAMEL_STORE_ERROR, CAMEL_STORE_ERROR_NO_FOLDER)) { g_propagate_error (error, local_error); return NULL; } else g_clear_error (&local_error); camel_service_lock (CAMEL_SERVICE (gw_store), CAMEL_SERVICE_REC_CONNECT_LOCK); groupwise_store_set_current_folder (gw_store, NULL); if (!camel_groupwise_store_connected (gw_store, cancellable, error)) { camel_service_unlock (CAMEL_SERVICE (gw_store), CAMEL_SERVICE_REC_CONNECT_LOCK); return NULL; } if (!E_IS_GW_CONNECTION ( priv->cnc)) { if (!groupwise_connect_sync (CAMEL_SERVICE (store), cancellable, error)) { camel_service_unlock (CAMEL_SERVICE (gw_store), CAMEL_SERVICE_REC_CONNECT_LOCK); return NULL; } } container_id = g_strdup (g_hash_table_lookup (priv->name_hash, folder_name)); storage_path = g_strdup_printf("%s/folders", priv->storage_path); folder_dir = e_path_to_physical (storage_path, folder_name); g_free (storage_path); folder = camel_gw_folder_new (store, folder_name, folder_dir, cancellable, NULL); if (!folder) { camel_service_unlock (CAMEL_SERVICE (gw_store), CAMEL_SERVICE_REC_CONNECT_LOCK); g_set_error ( error, CAMEL_SERVICE_ERROR, CAMEL_SERVICE_ERROR_INVALID, _("Authentication failed")); g_free (folder_dir); g_free (container_id); return NULL; } g_free (folder_dir); si = camel_store_summary_path ((CamelStoreSummary *)gw_store->summary, folder_name); if (si) { total = si->total; camel_store_summary_info_free ((CamelStoreSummary *)(gw_store)->summary, si); } summary = (CamelGroupwiseSummary *) folder->summary; summary_count = camel_folder_summary_count (folder->summary); if (!summary_count || !summary->time_string) { d(g_print ("\n\n** %s **: No summary as yet : using get cursor request\n\n", folder->name);)
static CamelFolder * groupwise_get_folder (CamelStore *store, const char *folder_name, guint32 flags, CamelException *ex) { CamelGroupwiseStore *gw_store = CAMEL_GROUPWISE_STORE (store); CamelGroupwiseStorePrivate *priv = gw_store->priv; CamelFolder *folder; CamelGroupwiseSummary *summary; char *container_id, *folder_dir, *storage_path; EGwConnectionStatus status; GList *list = NULL; gboolean done = FALSE, all_ok = TRUE; const char *position = E_GW_CURSOR_POSITION_END; int count = 0, cursor, summary_count = 0; CamelStoreInfo *si = NULL; guint total = 0; folder = groupwise_get_folder_from_disk (store, folder_name, flags, ex); if (folder) { camel_object_ref (folder); return folder; } camel_exception_clear (ex); CAMEL_SERVICE_REC_LOCK (gw_store, connect_lock); if (!camel_groupwise_store_connected (gw_store, ex)) { CAMEL_SERVICE_REC_UNLOCK (gw_store, connect_lock); return NULL; } if (gw_store->current_folder) { camel_object_unref (gw_store->current_folder); gw_store->current_folder = NULL; } if (!E_IS_GW_CONNECTION( priv->cnc)) { if (!groupwise_connect (CAMEL_SERVICE(store), ex)) { CAMEL_SERVICE_REC_UNLOCK (gw_store, connect_lock); return NULL; } } container_id = g_strdup (g_hash_table_lookup (priv->name_hash, folder_name)); storage_path = g_strdup_printf("%s/folders", priv->storage_path); folder_dir = e_path_to_physical (storage_path, folder_name); g_free(storage_path); folder = camel_gw_folder_new (store, folder_name, folder_dir, ex); if (!folder) { CAMEL_SERVICE_REC_UNLOCK (gw_store, connect_lock); camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_INVALID, _("Authentication failed")); g_free (folder_dir); g_free (container_id); return NULL; } g_free (folder_dir); si = camel_store_summary_path ((CamelStoreSummary *)gw_store->summary, folder_name); if (si) { total = si->total; camel_store_summary_info_free ((CamelStoreSummary *)(gw_store)->summary, si); } summary = (CamelGroupwiseSummary *) folder->summary; summary_count = camel_folder_summary_count (folder->summary); if(!summary_count || !summary->time_string) { d(g_print ("\n\n** %s **: No summary as yet : using get cursor request\n\n", folder->name);)