aboutsummaryrefslogtreecommitdiffstats
path: root/mail/mail-importer.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2003-03-20 18:17:25 +0800
committerMichael Zucci <zucchi@src.gnome.org>2003-03-20 18:17:25 +0800
commit1dc4c5de39970316494ab17e2b50ae1a7ca6170e (patch)
treef474ee61d5e15306ca95f386223d91f1cb060761 /mail/mail-importer.c
parent4ac5734af0ee578f5e769bf4bd5a420d379d2155 (diff)
downloadgsoc2013-evolution-1dc4c5de39970316494ab17e2b50ae1a7ca6170e.tar.gz
gsoc2013-evolution-1dc4c5de39970316494ab17e2b50ae1a7ca6170e.tar.zst
gsoc2013-evolution-1dc4c5de39970316494ab17e2b50ae1a7ca6170e.zip
** for mail part of bug #38461.
2003-03-21 Not Zed <NotZed@Ximian.com> ** for mail part of bug #38461. * importers/evolution-outlook-importer.c (load_file_fn): dont pass in create flag to uri_to_folder, the folder must already exist. * importers/evolution-mbox-importer.c (folder_created_cb): Removed, we now force the caller to create the destination folder first. (load_file_fn): Dont try and create a folder if it doesn't exist. Also, use the uri directly as the destination uri, so we can import into any folder. (process_item_fn): If we dont have a folder, thats just an error, return BAD_FILE. * importers/netscape-importer.c (netscape_import_file): As below for elm_import_file. (import_next): similarly as for pine import_next. (importer_cb): just record result. (importer_timeout_fn): removed. * importers/pine-importer.c (import_next): Similar to below for the elm import_next. (pine_import_file): As below for elm_import_file. (importer_timeout_fn): removed. (importer_cb): just record the result, and exit. (import_next): change around to behave more like the elm importer, cleaning up when we're done. * importers/elm-importer.c (elm_import_file): Create the destination folder ourselves, dont pass it onto the mbox importer. Simplify logic, just do the import within a while loop, polling the g main loop as necessary, remove need for idle callbacks and other crap. (import_next): If elm_import_file fails, then just go straight to the next folder, stops it falling in a heap. (import_item_idle): removed. (importer_cb): just record result/exit. * mail-importer.c (mail_importer_create_folder): removed. (mail_importer_make_local_folder): new function to create a local-only folder from a path. It runs synchronously by using a recursive main loop. (folder_created_cb): callback for make_local_folder. svn path=/trunk/; revision=20379
Diffstat (limited to 'mail/mail-importer.c')
-rw-r--r--mail/mail-importer.c111
1 files changed, 70 insertions, 41 deletions
diff --git a/mail/mail-importer.c b/mail/mail-importer.c
index f6b67351d3..f6d73a5d30 100644
--- a/mail/mail-importer.c
+++ b/mail/mail-importer.c
@@ -39,62 +39,91 @@
#include "mail-local.h"
#include "mail.h"
-
static GList *importer_modules = NULL;
-
extern char *evolution_dir;
-
static GNOME_Evolution_Storage local_storage = NULL;
-/* Prototype */
-
void mail_importer_uninit (void);
+struct _create_data {
+ GNOME_Evolution_Storage_Result create_result;
+ int create_done:1;
+};
+
+static void
+folder_created_cb(BonoboListener *listener, const char *event_name, const BonoboArg *event_data,
+ CORBA_Environment *ev, struct _create_data *data)
+{
+ GNOME_Evolution_Storage_FolderResult *result;
+
+ data->create_done = TRUE;
+
+ if (strcmp (event_name, "evolution-shell:folder_created") != 0) {
+ return; /* Unknown event */
+ }
+
+ result = event_data->_value;
+ data->create_result = result->result;
+}
+
/**
- * mail_importer_create_folder:
- * parent_path: The path of the parent folder.
- * name: The name of the folder to be created.
- * description: A description of the folder.
- * listener: A BonoboListener for notification.
- *
- * Attempts to create the folder @parent_path/@name. When the folder has been
- * created, or there is an error, the "evolution-shell:folder-created" event is
- * emitted on @listener. The BonoboArg that is sent to @listener is a
- * GNOME_Evolution_Storage_FolderResult which has two elements: result and path.
- * Result contains the error code, or success, and path contains the complete
- * physical path to the newly created folder.
- */
-void
-mail_importer_create_folder (const char *parent_path,
- const char *name,
- const char *description,
- const BonoboListener *listener)
+ * mail_importer_make_local_folder:
+ * @folderpath:
+ *
+ * Check a local folder exists at path @folderpath, and if not, create it.
+ *
+ * Return value: The physical uri of the folder, or NULL if the folder did
+ * not exist and could not be created.
+ **/
+char *
+mail_importer_make_local_folder(const char *folderpath)
{
- Bonobo_Listener corba_listener;
CORBA_Environment ev;
- char *path, *physical;
- char *real_description;
+ char *uri = NULL, *tmp;
+ GNOME_Evolution_Folder *fi;
+ BonoboListener *listener;
- g_return_if_fail (local_storage != NULL);
- g_return_if_fail (listener != NULL);
- g_return_if_fail (BONOBO_IS_LISTENER (listener));
+ CORBA_exception_init (&ev);
- path = g_build_filename(parent_path, name, NULL);
- physical = g_strdup_printf ("file://%s/local/%s", evolution_dir, parent_path);
+ /* first, check, does this folder exist, if so, use the right path */
+ fi = GNOME_Evolution_Storage_getFolderAtPath(local_storage, folderpath, &ev);
+ if (fi) {
+ printf("folder %s exists @ %s\n", folderpath, fi->physicalUri);
+ uri = g_strdup(fi->physicalUri);
+ CORBA_free(fi);
+ } else {
+ struct _create_data data = { GNOME_Evolution_Storage_GENERIC_ERROR, FALSE };
- corba_listener = bonobo_object_corba_objref (BONOBO_OBJECT (listener));
+ tmp = g_strdup_printf("file://%s/local", evolution_dir);
+ uri = e_path_to_physical(tmp, folderpath);
+ g_free(tmp);
+ tmp = strrchr(uri, '/');
+ tmp[0] = 0;
- /* Darn CORBA wanting non-NULL values for strings */
- real_description = CORBA_string_dup (description ? description : "");
+ printf("Creating folder %s, parent %s\n", folderpath, uri);
+
+ listener = bonobo_listener_new (NULL, NULL);
+ g_signal_connect(listener, "event-notify", G_CALLBACK (folder_created_cb), &data);
+
+ GNOME_Evolution_Storage_asyncCreateFolder(local_storage, folderpath, "mail", "", uri,
+ bonobo_object_corba_objref((BonoboObject *)listener), &ev);
+
+ while (!data.create_done)
+ g_main_context_iteration(NULL, TRUE);
+
+ bonobo_object_unref((BonoboObject *)listener);
+
+ if (data.create_result != GNOME_Evolution_Storage_OK) {
+ g_free(uri);
+ uri = NULL;
+ } else {
+ *tmp = '/';
+ }
+ }
- CORBA_exception_init (&ev);
- GNOME_Evolution_Storage_asyncCreateFolder (local_storage,
- path, "mail",
- real_description, physical,
- corba_listener, &ev);
CORBA_exception_free (&ev);
- g_free (path);
- g_free (physical);
+
+ return uri;
}
/**