From 7fecce2d23b2b565a40bd6cf4cc99a9456ffba74 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Thu, 8 Apr 2004 18:23:29 +0000 Subject: We need to recursively copy the dragged folder tree over to the drop 2004-04-08 Jeffrey Stedfast * em-folder-tree.c (emft_drop_folder): We need to recursively copy the dragged folder tree over to the drop location, not just the parent folder. We also need to subscribe to the newly created folder in some cases. svn path=/trunk/; revision=25375 --- mail/ChangeLog | 7 ++++++ mail/em-folder-tree.c | 63 +++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/mail/ChangeLog b/mail/ChangeLog index 08bd398fcb..28a2869e86 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,10 @@ +2004-04-08 Jeffrey Stedfast + + * em-folder-tree.c (emft_drop_folder): We need to recursively copy + the dragged folder tree over to the drop location, not just the + parent folder. We also need to subscribe to the newly created + folder in some cases. + 2004-04-08 Not Zed * em-format-html.c (efh_format_headers): add the monkey button if diff --git a/mail/em-folder-tree.c b/mail/em-folder-tree.c index 102c87b65d..fdf75d9d17 100644 --- a/mail/em-folder-tree.c +++ b/mail/em-folder-tree.c @@ -744,6 +744,51 @@ emft_drop_uid_list(struct _DragDataReceivedAsync *m, CamelFolder *dest) m->moved = m->move && !camel_exception_is_set(&m->msg.ex); } +static void +emft_drop_folder_rec (CamelStore *store, CamelFolderInfo *fi, const char *parent_name, CamelException *ex) +{ + CamelFolder *src, *dest; + CamelFolderInfo *nfi; + char *new_name; + + while (fi != NULL) { + if (!(src = mail_tool_uri_to_folder (fi->uri, 0, ex))) + break; + + /* handles dropping to the root properly */ + if (parent_name[0]) + new_name = g_strdup_printf ("%s/%s", parent_name, src->name); + else + new_name = g_strdup (src->name); + + if ((nfi = camel_store_create_folder (store, parent_name, src->name, ex))) { + camel_store_free_folder_info (store, nfi); + + if (camel_store_supports_subscriptions (store)) + camel_store_subscribe_folder (store, new_name, ex); + + /* copy the folder to the new location */ + if ((dest = camel_store_get_folder (store, new_name, 0, ex))) { + GPtrArray *uids; + + uids = camel_folder_get_uids (src); + camel_folder_transfer_messages_to (src, uids, dest, NULL, FALSE, ex); + camel_folder_free_uids (src, uids); + + camel_object_unref (dest); + } + } + + camel_object_unref (src); + + if (fi->child) + emft_drop_folder_rec (store, fi->child, new_name, ex); + + g_free (new_name); + fi = fi->next; + } +} + static void emft_drop_folder(struct _DragDataReceivedAsync *m) { @@ -766,19 +811,19 @@ emft_drop_folder(struct _DragDataReceivedAsync *m) camel_store_rename_folder(m->store, src->full_name, new_name, &m->msg.ex); m->moved = !camel_exception_is_set (&m->msg.ex); } else { - CamelFolder *dest; + CamelFolderInfo *fi, *nfi; /* FIXME: should check we're not coming from a vfolder, otherwise bad stuff could happen */ - /* copy the folder to the new location */ - if ((dest = camel_store_get_folder(m->store, new_name, CAMEL_STORE_FOLDER_CREATE_EXCL, &m->msg.ex))) { - GPtrArray *uids; - - uids = camel_folder_get_uids (src); - camel_folder_transfer_messages_to (src, uids, dest, NULL, FALSE, &m->msg.ex); - camel_folder_free_uids (src, uids); + if ((fi = camel_store_get_folder_info (src->parent_store, src->full_name, CAMEL_STORE_FOLDER_INFO_FAST | + CAMEL_STORE_FOLDER_INFO_RECURSIVE, &m->msg.ex))) { + if (!(nfi = camel_store_get_folder_info (m->store, new_name, CAMEL_STORE_FOLDER_INFO_FAST, &m->msg.ex))) { + /* Good. The folder doesn't already exist... */ + camel_exception_clear (&m->msg.ex); + emft_drop_folder_rec (m->store, fi, m->full_name, &m->msg.ex); + } - camel_object_unref (dest); + camel_store_free_folder_info (src->parent_store, fi); } } -- cgit