aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
Diffstat (limited to 'mail')
-rw-r--r--mail/ChangeLog6
-rw-r--r--mail/component-factory.c48
-rw-r--r--mail/mail-ops.c110
-rw-r--r--mail/mail-ops.h6
4 files changed, 166 insertions, 4 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 085bc9211a..e03e667e17 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,8 +1,14 @@
2001-05-23 Jeffrey Stedfast <fejj@ximian.com>
+ * component-factory.c (xfer_folder): New function that the shell
+ component calls to copy/move a folder.
+ (component_fn): Set the xfer_folder_fn argument.
+
* mail-ops.c (mail_remove_folder): New async function to remove a
folder. God knows if it does what the ShellComponent needs or not
yet.
+ (mail_xfer_folder): Yet another yummy async function to move or
+ copy a folder to a new location.
* component-factory.c (storage_remove_folder): New function for
removing folders.
diff --git a/mail/component-factory.c b/mail/component-factory.c
index 6bfd489bff..312bcf3054 100644
--- a/mail/component-factory.c
+++ b/mail/component-factory.c
@@ -188,9 +188,7 @@ remove_folder (EvolutionShellComponent *shell_component,
CORBA_exception_init (&ev);
- /* FIXME: what if the folder is mh or maildir? */
- /* ?? maybe we should just rm -rf the physical_uri?? */
- uri = g_strdup_printf ("mbox://%s", physical_uri);
+ uri = g_strdup_printf ("file://%s", physical_uri);
mail_remove_folder (uri, do_remove_folder, CORBA_Object_duplicate (listener, &ev));
GNOME_Evolution_ShellComponentListener_notifyResult (listener,
GNOME_Evolution_ShellComponentListener_OK, &ev);
@@ -198,6 +196,48 @@ remove_folder (EvolutionShellComponent *shell_component,
CORBA_exception_free (&ev);
}
+static void
+do_xfer_folder (char *src_uri, char *dest_uri, gboolean remove_source, CamelFolder *dest_folder, void *data)
+{
+ GNOME_Evolution_ShellComponentListener listener = data;
+ GNOME_Evolution_ShellComponentListener_Result result;
+ CORBA_Environment ev;
+
+ if (dest_folder)
+ result = GNOME_Evolution_ShellComponentListener_OK;
+ else
+ result = GNOME_Evolution_ShellComponentListener_INVALID_URI;
+
+ CORBA_exception_init (&ev);
+ GNOME_Evolution_ShellComponentListener_notifyResult (listener, result, &ev);
+ CORBA_Object_release (listener, &ev);
+ CORBA_exception_free (&ev);
+}
+
+static void
+xfer_folder (EvolutionShellComponent *shell_component,
+ const char *source_physical_uri,
+ const char *destination_physical_uri,
+ gboolean remove_source,
+ const GNOME_Evolution_ShellComponentListener listener,
+ void *closure)
+{
+ CORBA_Environment ev;
+ char *dest_uri;
+
+ CORBA_exception_init (&ev);
+
+ dest_uri = g_strdup_printf ("mbox://%s", destination_physical_uri);
+ mail_xfer_folder (source_physical_uri, dest_uri, remove_source, do_xfer_folder,
+ CORBA_Object_duplicate (listener, &ev));
+ g_free (dest_uri);
+
+ GNOME_Evolution_ShellComponentListener_notifyResult (listener,
+ GNOME_Evolution_ShellComponentListener_OK, &ev);
+
+ CORBA_exception_free (&ev);
+}
+
static struct {
char *name, **uri;
CamelFolder **folder;
@@ -334,7 +374,7 @@ component_fn (BonoboGenericFactory *factory, void *closure)
create_view,
create_folder,
remove_folder,
- NULL, /* xfer_folder_fn */
+ xfer_folder,
NULL, /* populate_folder_context_menu_fn */
NULL, /* get_dnd_selection_fn */
NULL);
diff --git a/mail/mail-ops.c b/mail/mail-ops.c
index 23c0b047db..4b99bc76ac 100644
--- a/mail/mail-ops.c
+++ b/mail/mail-ops.c
@@ -1463,6 +1463,116 @@ mail_remove_folder (const char *uri, void (*done) (char *uri, gboolean removed,
e_thread_put (mail_thread_new, (EMsg *)m);
}
+/* ** XFER FOLDER ******************************************************* */
+
+struct _xfer_folder_msg {
+ struct _mail_msg msg;
+
+ char *src_uri;
+ char *dest_uri;
+ gboolean remove;
+ CamelFolder *folder;
+ void (*done) (char *src_uri, char *dest_uri, gboolean remove, CamelFolder *folder, void *data);
+ void *data;
+};
+
+static char *
+xfer_folder_desc (struct _mail_msg *mm, int done)
+{
+ struct _xfer_folder_msg *m = (struct _xfer_folder_msg *)mm;
+
+ if (m->remove)
+ return g_strdup_printf (_("Moving folder %s to %s"), m->src_uri, m->dest_uri);
+ else
+ return g_strdup_printf (_("Copying folder %s to %s"), m->src_uri, m->dest_uri);
+}
+
+static void
+xfer_folder_get (struct _mail_msg *mm)
+{
+ struct _xfer_folder_msg *m = (struct _xfer_folder_msg *)mm;
+ CamelFolder *src, *dest = NULL;
+ GPtrArray *uids;
+
+ camel_operation_register (mm->cancel);
+
+ src = mail_tool_uri_to_folder (m->src_uri, &mm->ex);
+ if (camel_exception_is_set (&mm->ex))
+ goto done;
+
+ dest = mail_tool_get_folder_from_urlname (m->dest_uri, "mbox",
+ CAMEL_STORE_FOLDER_CREATE | CAMEL_STORE_FOLDER_BODY_INDEX,
+ &mm->ex);
+ if (camel_exception_is_set (&mm->ex))
+ goto done;
+
+ uids = camel_folder_get_uids (src);
+ if (m->remove)
+ camel_folder_move_messages_to (src, uids, dest, &mm->ex);
+ else
+ camel_folder_copy_messages_to (src, uids, dest, &mm->ex);
+
+ camel_folder_free_uids (src, uids);
+
+ if (camel_exception_is_set (&mm->ex))
+ goto done;
+
+ if (m->remove)
+ camel_store_delete_folder (src->parent_store, src->full_name, &mm->ex);
+
+ done:
+ if (src)
+ camel_object_unref (CAMEL_OBJECT (src));
+
+ m->folder = dest;
+
+ camel_operation_unregister (mm->cancel);
+}
+
+static void
+xfer_folder_got (struct _mail_msg *mm)
+{
+ struct _xfer_folder_msg *m = (struct _xfer_folder_msg *)mm;
+
+ if (m->done)
+ m->done (m->src_uri, m->dest_uri, m->remove, m->folder, m->data);
+}
+
+static void
+xfer_folder_free (struct _mail_msg *mm)
+{
+ struct _xfer_folder_msg *m = (struct _xfer_folder_msg *)mm;
+
+ g_free (m->src_uri);
+ g_free (m->dest_uri);
+ if (m->folder)
+ camel_object_unref (CAMEL_OBJECT (m->folder));
+}
+
+static struct _mail_msg_op xfer_folder_op = {
+ xfer_folder_desc,
+ xfer_folder_get,
+ xfer_folder_got,
+ xfer_folder_free,
+};
+
+void
+mail_xfer_folder (const char *src_uri, const char *dest_uri, gboolean remove_source,
+ void (*done) (char *src_uri, char *dest_uri, gboolean remove, CamelFolder *folder, void *data),
+ void *data)
+{
+ struct _xfer_folder_msg *m;
+
+ m = mail_msg_new (&xfer_folder_op, NULL, sizeof(*m));
+ m->src_uri = g_strdup (src_uri);
+ m->dest_uri = g_strdup (dest_uri);
+ m->remove = remove_source;
+ m->data = data;
+ m->done = done;
+
+ e_thread_put (mail_thread_new, (EMsg *)m);
+}
+
/* ** SYNC FOLDER ********************************************************* */
struct _sync_folder_msg {
diff --git a/mail/mail-ops.h b/mail/mail-ops.h
index 305dae6b77..e6677c4443 100644
--- a/mail/mail-ops.h
+++ b/mail/mail-ops.h
@@ -100,6 +100,12 @@ void mail_remove_folder (const char *uri,
void (*done) (char *uri, gboolean removed, void *data),
void *data);
+/* transfer (copy/move) a folder */
+void mail_xfer_folder (const char *src_uri, const char *dest_uri, gboolean remove_source,
+ void (*done) (char *src_uri, char *dest_uri, gboolean remove_source,
+ CamelFolder *folder, void *data),
+ void *data);
+
/* save messages */
int mail_save_messages (CamelFolder *folder, GPtrArray *uids, const char *path,
void (*done) (CamelFolder *folder, GPtrArray *uids, char *path, void *data),