diff options
-rw-r--r-- | mail/ChangeLog | 15 | ||||
-rw-r--r-- | mail/component-factory.c | 27 | ||||
-rw-r--r-- | mail/mail-local.c | 53 | ||||
-rw-r--r-- | mail/mail-ops.c | 206 | ||||
-rw-r--r-- | mail/mail-ops.h | 3 |
5 files changed, 261 insertions, 43 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog index 21c3d316fa..bbd36988bc 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,18 @@ +2001-02-14 Jeffrey Stedfast <fejj@ximian.com> + + * component-factory.c (owner_set_cb): Setup the Trash folder. + + * mail-ops.c (create_trash_vfolder): Do better error handling. + (populate_folder_urls): Oops, helps to strdup the url into the + array if we plan on freeing the data. + (mail_get_trash): New async function that may eventually replace + mail_do_setup_trash(). + (do_setup_trash): Do better error handling. + + * mail-local.c (mail_local_store_class_init): Override + get_folder_info. + (get_folder_info): Implement. + 2001-02-13 Christopher James Lahey <clahey@ximian.com> * mail-local.c (do_reconfigure_folder): Fix some uninitialized diff --git a/mail/component-factory.c b/mail/component-factory.c index 376b3b14a7..f46a0a5f9b 100644 --- a/mail/component-factory.c +++ b/mail/component-factory.c @@ -54,6 +54,7 @@ CamelFolder *drafts_folder = NULL; CamelFolder *outbox_folder = NULL; CamelFolder *sent_folder = NULL; /* this one should be configurable? */ +CamelFolder *trash_folder = NULL; char *evolution_dir; #define COMPONENT_FACTORY_ID "OAFIID:GNOME_Evolution_Mail_ShellComponentFactory" @@ -112,7 +113,7 @@ create_view (EvolutionShellComponent *shell_component, } static void -do_create_folder(char *uri, CamelFolder *folder, void *data) +do_create_folder (char *uri, CamelFolder *folder, void *data) { GNOME_Evolution_ShellComponentListener listener = data; CORBA_Environment ev; @@ -140,11 +141,12 @@ create_folder (EvolutionShellComponent *shell_component, CORBA_Environment ev; CORBA_exception_init(&ev); - if (!strcmp(type, "mail")) { + if (!strcmp (type, "mail")) { uri = g_strdup_printf ("mbox://%s", physical_uri); - mail_create_folder(uri, do_create_folder, CORBA_Object_duplicate(listener, &ev)); + mail_create_folder (uri, do_create_folder, CORBA_Object_duplicate (listener, &ev)); } else { - GNOME_Evolution_ShellComponentListener_notifyResult(listener, GNOME_Evolution_ShellComponentListener_UNSUPPORTED_TYPE, &ev); + GNOME_Evolution_ShellComponentListener_notifyResult ( + listener, GNOME_Evolution_ShellComponentListener_UNSUPPORTED_TYPE, &ev); } CORBA_exception_free(&ev); } @@ -158,13 +160,14 @@ static struct { { "Sent", &sent_folder }, }; -static void got_folder(char *uri, CamelFolder *folder, void *data) +static void +got_folder (char *uri, CamelFolder *folder, void *data) { CamelFolder **fp = data; - + if (folder) { *fp = folder; - camel_object_ref((CamelObject *)folder); + camel_object_ref (CAMEL_OBJECT (folder)); } } @@ -210,10 +213,14 @@ owner_set_cb (EvolutionShellComponent *shell_component, mail_msg_wait (mail_get_folder (uri, got_folder, standard_folders[i].folder)); g_free (uri); } - + + /*mail_msg_wait (mail_get_trash ("file:/", got_folder, &trash_folder));*/ + mail_do_setup_trash (_("Trash"), "file:/", &trash_folder); + mail_operation_wait_for_finish (); + mail_session_enable_interaction (TRUE); - - mail_autoreceive_setup(); + + mail_autoreceive_setup (); } static void diff --git a/mail/mail-local.c b/mail/mail-local.c index fca9e75e1e..2d63168dc3 100644 --- a/mail/mail-local.c +++ b/mail/mail-local.c @@ -197,10 +197,17 @@ CamelType mail_local_store_get_type (void); static void local_folder_changed_proxy (CamelObject *folder, gpointer event_data, gpointer user_data); -static char *get_name(CamelService *service, gboolean brief); -static CamelFolder *get_folder(CamelStore *store, const char *folder_name, guint32 flags, CamelException *ex); -static void delete_folder(CamelStore *store, const char *folder_name, CamelException *ex); -static void rename_folder(CamelStore *store, const char *old_name, const char *new_name, CamelException *ex); +static char *get_name (CamelService *service, gboolean brief); + +static CamelFolder *get_folder (CamelStore *store, const char *folder_name, + guint32 flags, CamelException *ex); +static CamelFolderInfo *get_folder_info (CamelStore *store, const char *top, + gboolean fast, gboolean recursive, + gboolean subscribed_only, CamelException *ex); +static void delete_folder (CamelStore *store, const char *folder_name, + CamelException *ex); +static void rename_folder (CamelStore *store, const char *old_name, + const char *new_name, CamelException *ex); static CamelStoreClass *local_parent_class; @@ -220,6 +227,8 @@ mail_local_store_class_init (MailLocalStoreClass *mail_local_store_class) camel_store_class->compare_folder_name = NULL; camel_store_class->get_folder = get_folder; + camel_store_class->get_folder_info = get_folder_info; + camel_store_class->free_folder_info = camel_store_free_folder_info_full; camel_store_class->delete_folder = delete_folder; camel_store_class->rename_folder = rename_folder; @@ -322,6 +331,42 @@ get_folder (CamelStore *store, const char *folder_name, } static void +populate_folders (gpointer key, gpointer data, gpointer user_data) +{ + GPtrArray *folders = user_data; + MailLocalFolder *folder; + CamelFolderInfo *fi; + + folder = data; + + fi = g_new0 (CamelFolderInfo, 1); + fi->full_name = g_strdup (folder->path); + fi->name = g_strdup (folder->name); + fi->url = g_strdup (folder->uri); + fi->unread_message_count = -1; + + g_ptr_array_add (folders, fi); +} + +static CamelFolderInfo * +get_folder_info (CamelStore *store, const char *top, + gboolean fast, gboolean recursive, + gboolean subscribed_only, CamelException *ex) +{ + MailLocalStore *local_store = MAIL_LOCAL_STORE (store); + CamelFolderInfo *fi = NULL; + GPtrArray *folders; + + folders = g_ptr_array_new (); + g_hash_table_foreach (local_store->folders, populate_folders, folders); + + fi = camel_folder_info_build (folders, top, '/', TRUE); + g_ptr_array_free (folders, TRUE); + + return fi; +} + +static void delete_folder (CamelStore *store, const char *folder_name, CamelException *ex) { /* No-op. The shell local storage deals with this. */ diff --git a/mail/mail-ops.c b/mail/mail-ops.c index 77a140aaf4..c6eadddeb0 100644 --- a/mail/mail-ops.c +++ b/mail/mail-ops.c @@ -828,8 +828,7 @@ typedef struct transfer_messages_input_s GPtrArray *uids; gboolean delete_from_source; gchar *dest_uri; -} -transfer_messages_input_t; +} transfer_messages_input_t; static gchar * describe_transfer_messages (gpointer in_data, gboolean gerund) @@ -1657,6 +1656,163 @@ mail_operation_run(const mail_operation_spec *op, void *in, int free) /* ** SETUP TRASH VFOLDER ************************************************* */ +struct _get_trash_msg { + struct _mail_msg msg; + + char *store_uri; + CamelFolder *folder; + void (*done) (char *store_uri, CamelFolder *folder, void *data); + void *data; +}; + +static char * +get_trash_desc (struct _mail_msg *mm, int done) +{ + struct _get_trash_msg *m = (struct _get_trash_msg *)mm; + + return g_strdup_printf (_("Opening Trash folder for %s"), m->store_uri); +} + +/* maps the shell's uri to the real vfolder uri and open the folder */ +static CamelFolder * +create_trash_vfolder (const char *name, GPtrArray *urls, CamelException *ex) +{ + void camel_vee_folder_add_folder (CamelFolder *, CamelFolder *); + + char *storeuri, *foldername; + CamelFolder *folder = NULL, *sourcefolder; + int source = 0; + + d(fprintf (stderr, "Creating Trash vfolder\n")); + + storeuri = g_strdup_printf ("vfolder:%s/vfolder/%s", evolution_dir, name); + foldername = g_strdup ("mbox?(match-all (system-flag \"Deleted\"))"); + + /* we dont have indexing on vfolders */ + folder = mail_tool_get_folder_from_urlname (storeuri, foldername, CAMEL_STORE_FOLDER_CREATE, ex); + g_free (foldername); + g_free (storeuri); + if (camel_exception_is_set (ex)) + return NULL; + + while (source < urls->len) { + const char *sourceuri; + + sourceuri = urls->pdata[source]; + d(fprintf (stderr, "adding vfolder source: %s\n", sourceuri)); + + sourcefolder = mail_tool_uri_to_folder (sourceuri, ex); + d(fprintf (stderr, "source folder = %p\n", sourcefolder)); + + if (sourcefolder) { + mail_tool_camel_lock_up (); + camel_vee_folder_add_folder (folder, sourcefolder); + mail_tool_camel_lock_down (); + } else { + /* we'll just silently ignore now-missing sources */ + camel_exception_clear (ex); + } + + g_free (urls->pdata[source]); + source++; + } + + g_ptr_array_free (urls, TRUE); + + return folder; +} + +static void +populate_folder_urls (CamelFolderInfo *info, GPtrArray *urls) +{ + if (!info) + return; + + g_ptr_array_add (urls, g_strdup (info->url)); + + if (info->child) + populate_folder_urls (info->child, urls); + + if (info->sibling) + populate_folder_urls (info->sibling, urls); +} + +static void +get_trash_get (struct _mail_msg *mm) +{ + struct _get_trash_msg *m = (struct _get_trash_msg *)mm; + CamelStore *store; + GPtrArray *urls; + + urls = g_ptr_array_new (); + + /* we don't want to connect */ + store = (CamelStore *) camel_session_get_service (session, m->store_uri, + CAMEL_PROVIDER_STORE, &mm->ex); + if (store == NULL) { + g_warning ("Couldn't get service %s: %s\n", m->store_uri, + camel_exception_get_description (&mm->ex)); + camel_exception_clear (&mm->ex); + + m->folder = NULL; + } else { + CamelFolderInfo *info; + + info = camel_store_get_folder_info (store, "/", TRUE, TRUE, TRUE, &mm->ex); + populate_folder_urls (info, urls); + camel_store_free_folder_info (store, info); + + m->folder = create_trash_vfolder (_("Trash"), urls, &mm->ex); + } +} + +static void +get_trash_got (struct _mail_msg *mm) +{ + struct _get_trash_msg *m = (struct _get_trash_msg *)mm; + + if (m->done) + m->done (m->store_uri, m->folder, m->data); +} + +static void +get_trash_free (struct _mail_msg *mm) +{ + struct _get_trash_msg *m = (struct _get_trash_msg *)mm; + + g_free (m->store_uri); + if (m->folder) + camel_object_unref (CAMEL_OBJECT (m->folder)); +} + +static struct _mail_msg_op get_trash_op = { + get_trash_desc, + get_trash_get, + get_trash_got, + get_trash_free, +}; + +int +mail_get_trash (const char *store_uri, + void (*done) (char *store_uri, CamelFolder *folder, void *data), + void *data) +{ + struct _get_trash_msg *m; + int id; + + m = mail_msg_new (&get_trash_op, NULL, sizeof (*m)); + m->store_uri = g_strdup (store_uri); + m->data = data; + m->done = done; + + id = m->msg.seq; + e_thread_put (mail_thread_new, (EMsg *)m); + + return id; +} + +/* This next one is the older implementation ... */ + typedef struct setup_trash_input_s { gchar *name; gchar *store_uri; @@ -1674,6 +1830,7 @@ describe_setup_trash (gpointer in_data, gboolean gerund) return g_strdup_printf (_("Load %s Folder for %s"), input->name, input->store_uri); } +#if 0 /* maps the shell's uri to the real vfolder uri and open the folder */ static CamelFolder * create_trash_vfolder (const char *name, GPtrArray *urls, CamelException *ex) @@ -1682,19 +1839,23 @@ create_trash_vfolder (const char *name, GPtrArray *urls, CamelException *ex) char *storeuri, *foldername; CamelFolder *folder = NULL, *sourcefolder; - const char *sourceuri; int source = 0; d(fprintf (stderr, "Creating Trash vfolder\n")); storeuri = g_strdup_printf ("vfolder:%s/vfolder/%s", evolution_dir, name); - foldername = g_strdup ("mbox?(match-all (system-flag Deleted))"); + foldername = g_strdup ("mbox?(match-all (system-flag \"Deleted\"))"); /* we dont have indexing on vfolders */ folder = mail_tool_get_folder_from_urlname (storeuri, foldername, CAMEL_STORE_FOLDER_CREATE, ex); + g_free (foldername); + g_free (storeuri); + if (camel_exception_is_set (ex)) + return NULL; - sourceuri = NULL; while (source < urls->len) { + const char *sourceuri; + sourceuri = urls->pdata[source]; fprintf (stderr, "adding vfolder source: %s\n", sourceuri); @@ -1716,9 +1877,6 @@ create_trash_vfolder (const char *name, GPtrArray *urls, CamelException *ex) g_ptr_array_free (urls, TRUE); - g_free (foldername); - g_free (storeuri); - return folder; } @@ -1728,7 +1886,7 @@ populate_folder_urls (CamelFolderInfo *info, GPtrArray *urls) if (!info) return; - g_ptr_array_add (urls, info->url); + g_ptr_array_add (urls, g_strdup (info->url)); if (info->child) populate_folder_urls (info->child, urls); @@ -1736,17 +1894,7 @@ populate_folder_urls (CamelFolderInfo *info, GPtrArray *urls) if (info->sibling) populate_folder_urls (info->sibling, urls); } - -static void -local_folder_urls (gpointer key, gpointer value, gpointer user_data) -{ - GPtrArray *urls = user_data; - CamelFolder *folder = value; - - g_ptr_array_add (urls, g_strdup_printf ("file://%s/local/%s", - evolution_dir, - folder->full_name)); -} +#endif static void do_setup_trash (gpointer in_data, gpointer op_data, CamelException *ex) @@ -1769,20 +1917,19 @@ do_setup_trash (gpointer in_data, gpointer op_data, CamelException *ex) } else { char *path, *uri; - if (!strcmp (input->store_uri, "file:/")) { - /* Yeah - this is a hack but then again so are local folders */ - g_hash_table_foreach (store->folders, local_folder_urls, urls); - } else { - info = camel_store_get_folder_info (store, "/", TRUE, TRUE, TRUE, ex); - populate_folder_urls (info, urls); - camel_store_free_folder_info (store, info); - } + info = camel_store_get_folder_info (store, "/", TRUE, TRUE, TRUE, ex); + populate_folder_urls (info, urls); + camel_store_free_folder_info (store, info); *(input->folder) = create_trash_vfolder (input->name, urls, ex); + if (camel_exception_is_set (ex)) + return; + + storage = mail_lookup_storage (store); + g_return_if_fail (storage != NULL); uri = g_strdup_printf ("vfolder:%s", input->name); path = g_strdup_printf ("/%s", input->name); - storage = mail_lookup_storage (store); evolution_storage_new_folder (storage, path, g_basename (path), "mail", uri, input->name, FALSE); gtk_object_unref (GTK_OBJECT (storage)); @@ -1814,6 +1961,7 @@ mail_do_setup_trash (const char *name, const char *store_uri, CamelFolder **fold setup_trash_input_t *input; g_return_if_fail (name != NULL); + g_return_if_fail (store_uri != NULL); g_return_if_fail (folder != NULL); input = g_new (setup_trash_input_t, 1); diff --git a/mail/mail-ops.h b/mail/mail-ops.h index ba2201cfdd..eb47c68c4f 100644 --- a/mail/mail-ops.h +++ b/mail/mail-ops.h @@ -58,6 +58,9 @@ void mail_get_messages(CamelFolder *folder, GPtrArray *uids, int mail_get_folder(const char *uri, void (*done) (char *uri, CamelFolder *folder, void *data), void *data); +int mail_get_trash (const char *uri, + void (*done) (char *store_uri, CamelFolder *folder, void *data), void *data); + /* and for a store */ int mail_get_store(const char *uri, void (*done) (char *uri, CamelStore *store, void *data), void *data); |