[evolution-patches] spool mail is totally broken




this should fix it, it stops trying to write droppings in public places, and fixes the filenaming things which seems to have got broken when we went to the .sbd thing for evolution mailboxes.

should also make the ui work a bit nicer, properly controlling where you can make directories, etc.
--
Michael Zucchi <notzed ximian com>
"born to die, live to work, it's all downhill from here"
Novell's Evolution and Free Software Developer
Index: camel/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/camel/ChangeLog,v
retrieving revision 1.2251.2.5
diff -u -3 -r1.2251.2.5 ChangeLog
--- camel/ChangeLog	23 Sep 2004 04:12:29 -0000	1.2251.2.5
+++ camel/ChangeLog	27 Sep 2004 02:58:59 -0000
@@ -1,3 +1,26 @@
+2004-09-27  Not Zed  <NotZed Ximian com>
+
+	* providers/local/camel-spool-folder.c (camel_spool_folder_new):
+	make sure body indexing is turned off always, missed the ~ bit.
+
+	* providers/local/camel-spool-store.c (camel_folder_info_new):
+	dont take unread count.
+	(spool_fill_fi): copied from mbox more or less.
+	(scan_dir): use fill_fi to setup counts.
+	(spool_new_fi): replace camel_foldeR_info_new with one that does
+	most of the work, also generates uri's properly.
+	(get_folder_info_mbox): make the 'system' inbox name translatable.
+
+	* providers/local/camel-mbox-folder.h: make the
+	camel_mbox_folder_get* functions properly public.
+
+	* providers/local/camel-local-folder.h: pass the object to the
+	virtual methods now, fix all callers.
+
+	* providers/local/camel-spool-folder.c (spool_get_full_path)
+	(spool_get_meta_path): implement, this needs to work differnetly
+	to the parent classes implementations :-/.
+
 2004-09-13  Not Zed  <NotZed Ximian com>
 
 	** See bug #47821.
Index: camel/providers/local/camel-local-folder.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/providers/local/camel-local-folder.c,v
retrieving revision 1.50.16.1
diff -u -3 -r1.50.16.1 camel-local-folder.c
--- camel/providers/local/camel-local-folder.c	20 Sep 2004 08:10:23 -0000	1.50.16.1
+++ camel/providers/local/camel-local-folder.c	27 Sep 2004 02:59:03 -0000
@@ -73,8 +73,8 @@
 static int local_lock(CamelLocalFolder *lf, CamelLockType type, CamelException *ex);
 static void local_unlock(CamelLocalFolder *lf);
 
-static char *local_get_full_path(const char *toplevel_dir, const char *full_name);
-static char *local_get_meta_path(const char *toplevel_dir, const char *full_name, const char *ext);
+static char *local_get_full_path(CamelLocalFolder *lf, const char *toplevel_dir, const char *full_name);
+static char *local_get_meta_path(CamelLocalFolder *lf, const char *toplevel_dir, const char *full_name, const char *ext);
 
 static void local_refresh_info(CamelFolder *folder, CamelException *ex);
 
@@ -245,10 +245,10 @@
 		lf->index_path = g_strdup_printf("%s.ibex", tmp);
 		statepath = g_strdup_printf("%s.cmeta", tmp);
 	} else {
-		lf->folder_path = CLOCALF_CLASS(lf)->get_full_path(root_dir_path, full_name);
-		lf->summary_path = CLOCALF_CLASS(lf)->get_meta_path(root_dir_path, full_name, ".ev-summary");
-		lf->index_path = CLOCALF_CLASS(lf)->get_meta_path(root_dir_path, full_name, ".ibex");
-		statepath = CLOCALF_CLASS(lf)->get_meta_path(root_dir_path, full_name, ".cmeta");
+		lf->folder_path = CLOCALF_CLASS(lf)->get_full_path(lf, root_dir_path, full_name);
+		lf->summary_path = CLOCALF_CLASS(lf)->get_meta_path(lf, root_dir_path, full_name, ".ev-summary");
+		lf->index_path = CLOCALF_CLASS(lf)->get_meta_path(lf, root_dir_path, full_name, ".ibex");
+		statepath = CLOCALF_CLASS(lf)->get_meta_path(lf, root_dir_path, full_name, ".cmeta");
 	}
 	camel_object_set(lf, NULL, CAMEL_OBJECT_STATE_FILE, statepath, NULL);
 	g_free(statepath);
@@ -299,7 +299,7 @@
 		forceindex = FALSE;
 	}
 
-	folder->summary = (CamelFolderSummary *)CLOCALF_CLASS(lf)->create_summary(lf->summary_path, lf->folder_path, lf->index);
+	folder->summary = (CamelFolderSummary *)CLOCALF_CLASS(lf)->create_summary(lf, lf->summary_path, lf->folder_path, lf->index);
 	if (camel_local_summary_load((CamelLocalSummary *)folder->summary, forceindex, ex) == -1) {
 		camel_exception_clear(ex);
 	}
@@ -463,15 +463,15 @@
 }
 
 static char *
-local_get_full_path (const char *toplevel_dir, const char *full_name)
+local_get_full_path(CamelLocalFolder *lf, const char *toplevel_dir, const char *full_name)
 {
-	return g_strdup_printf ("%s/%s", toplevel_dir, full_name);
+	return g_strdup_printf("%s/%s", toplevel_dir, full_name);
 }
 
 static char *
-local_get_meta_path (const char *toplevel_dir, const char *full_name, const char *ext)
+local_get_meta_path(CamelLocalFolder *lf, const char *toplevel_dir, const char *full_name, const char *ext)
 {
-	return g_strdup_printf ("%s/%s%s", toplevel_dir, full_name, ext);
+	return g_strdup_printf("%s/%s%s", toplevel_dir, full_name, ext);
 }
 
 static int
@@ -558,10 +558,10 @@
 	g_free(lf->summary_path);
 	g_free(lf->index_path);
 
-	lf->folder_path = CLOCALF_CLASS(lf)->get_full_path(lf->base_path, newname);
-	lf->summary_path = CLOCALF_CLASS(lf)->get_meta_path(lf->base_path, newname, ".ev-summary");
-	lf->index_path = CLOCALF_CLASS(lf)->get_meta_path(lf->base_path, newname, ".ibex");
-	statepath = CLOCALF_CLASS(lf)->get_meta_path(lf->base_path, newname, ".cmeta");
+	lf->folder_path = CLOCALF_CLASS(lf)->get_full_path(lf, lf->base_path, newname);
+	lf->summary_path = CLOCALF_CLASS(lf)->get_meta_path(lf, lf->base_path, newname, ".ev-summary");
+	lf->index_path = CLOCALF_CLASS(lf)->get_meta_path(lf, lf->base_path, newname, ".ibex");
+	statepath = CLOCALF_CLASS(lf)->get_meta_path(lf, lf->base_path, newname, ".cmeta");
 	camel_object_set(lf, NULL, CAMEL_OBJECT_STATE_FILE, statepath, NULL);
 	g_free(statepath);
 
Index: camel/providers/local/camel-local-folder.h
===================================================================
RCS file: /cvs/gnome/evolution/camel/providers/local/camel-local-folder.h,v
retrieving revision 1.13
diff -u -3 -r1.13 camel-local-folder.h
--- camel/providers/local/camel-local-folder.h	5 Feb 2004 08:18:35 -0000	1.13
+++ camel/providers/local/camel-local-folder.h	27 Sep 2004 02:59:03 -0000
@@ -75,11 +75,11 @@
 	/* Virtual methods */	
 	
 	/* path construction, only used at init */
-	char * (* get_full_path)(const char *toplevel_dir, const char *full_name);
-	char * (* get_meta_path)(const char *toplevel_dir, const char *full_name, const char *ext);
+	char * (* get_full_path)(CamelLocalFolder *lf, const char *toplevel_dir, const char *full_name);
+	char * (* get_meta_path)(CamelLocalFolder *lf, const char *toplevel_dir, const char *full_name, const char *ext);
 	
 	/* summary factory, only used at init */
-	CamelLocalSummary *(*create_summary)(const char *path, const char *folder, CamelIndex *index);
+	CamelLocalSummary *(*create_summary)(CamelLocalFolder *lf, const char *path, const char *folder, CamelIndex *index);
 
 	/* Lock the folder for my operations */
 	int (*lock)(CamelLocalFolder *, CamelLockType type, CamelException *ex);
Index: camel/providers/local/camel-maildir-folder.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/providers/local/camel-maildir-folder.c,v
retrieving revision 1.23
diff -u -3 -r1.23 camel-maildir-folder.c
--- camel/providers/local/camel-maildir-folder.c	28 Jun 2004 08:36:29 -0000	1.23
+++ camel/providers/local/camel-maildir-folder.c	27 Sep 2004 02:59:03 -0000
@@ -49,7 +49,7 @@
 #define CF_CLASS(so) CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
 #define CMAILDIRS_CLASS(so) CAMEL_STORE_CLASS (CAMEL_OBJECT_GET_CLASS(so))
 
-static CamelLocalSummary *maildir_create_summary(const char *path, const char *folder, CamelIndex *index);
+static CamelLocalSummary *maildir_create_summary(CamelLocalFolder *lf, const char *path, const char *folder, CamelIndex *index);
 
 static void maildir_append_message(CamelFolder * folder, CamelMimeMessage * message, const CamelMessageInfo *info, char **appended_uid, CamelException * ex);
 static CamelMimeMessage *maildir_get_message(CamelFolder * folder, const gchar * uid, CamelException * ex);
@@ -150,7 +150,7 @@
 	return folder;
 }
 
-static CamelLocalSummary *maildir_create_summary(const char *path, const char *folder, CamelIndex *index)
+static CamelLocalSummary *maildir_create_summary(CamelLocalFolder *lf, const char *path, const char *folder, CamelIndex *index)
 {
 	return (CamelLocalSummary *)camel_maildir_summary_new(path, folder, index);
 }
Index: camel/providers/local/camel-mbox-folder.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/providers/local/camel-mbox-folder.c,v
retrieving revision 1.34
diff -u -3 -r1.34 camel-mbox-folder.c
--- camel/providers/local/camel-mbox-folder.c	21 May 2004 03:30:00 -0000	1.34
+++ camel/providers/local/camel-mbox-folder.c	27 Sep 2004 02:59:03 -0000
@@ -52,9 +52,6 @@
 #define CF_CLASS(so) CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
 #define CMBOXS_CLASS(so) CAMEL_STORE_CLASS (CAMEL_OBJECT_GET_CLASS(so))
 
-char *camel_mbox_folder_get_full_path (const char *toplevel_dir, const char *full_name);
-char *camel_mbox_folder_get_meta_path (const char *toplevel_dir, const char *full_name, const char *ext);
-
 static int mbox_lock(CamelLocalFolder *lf, CamelLockType type, CamelException *ex);
 static void mbox_unlock(CamelLocalFolder *lf);
 
@@ -67,7 +64,7 @@
 
 static void mbox_append_message(CamelFolder *folder, CamelMimeMessage * message, const CamelMessageInfo * info,	char **appended_uid, CamelException *ex);
 static CamelMimeMessage *mbox_get_message(CamelFolder *folder, const gchar * uid, CamelException *ex);
-static CamelLocalSummary *mbox_create_summary(const char *path, const char *folder, CamelIndex *index);
+static CamelLocalSummary *mbox_create_summary(CamelLocalFolder *lf, const char *path, const char *folder, CamelIndex *index);
 
 static void mbox_finalise(CamelObject * object);
 
@@ -147,7 +144,7 @@
 }
 
 char *
-camel_mbox_folder_get_full_path (const char *toplevel_dir, const char *full_name)
+camel_mbox_folder_get_full_path (CamelLocalFolder *lf, const char *toplevel_dir, const char *full_name)
 {
 	const char *inptr = full_name;
 	int subdirs = 0;
@@ -183,7 +180,7 @@
 }
 
 char *
-camel_mbox_folder_get_meta_path (const char *toplevel_dir, const char *full_name, const char *ext)
+camel_mbox_folder_get_meta_path (CamelLocalFolder *lf, const char *toplevel_dir, const char *full_name, const char *ext)
 {
 /*#define USE_HIDDEN_META_FILES*/
 #ifdef USE_HIDDEN_META_FILES
@@ -195,11 +192,11 @@
 	else
 		sprintf (name, ".%s%s", full_name, ext);
 	
-	return camel_mbox_folder_get_full_path (toplevel_dir, name);
+	return camel_mbox_folder_get_full_path (lf, toplevel_dir, name);
 #else
 	char *full_path, *path;
 	
-	full_path = camel_mbox_folder_get_full_path (toplevel_dir, full_name);
+	full_path = camel_mbox_folder_get_full_path (lf, toplevel_dir, full_name);
 	path = g_strdup_printf ("%s%s", full_path, ext);
 	g_free (full_path);
 	
@@ -207,7 +204,7 @@
 #endif
 }
 
-static CamelLocalSummary *mbox_create_summary(const char *path, const char *folder, CamelIndex *index)
+static CamelLocalSummary *mbox_create_summary(CamelLocalFolder *lf, const char *path, const char *folder, CamelIndex *index)
 {
 	return (CamelLocalSummary *)camel_mbox_summary_new(path, folder, index);
 }
Index: camel/providers/local/camel-mbox-folder.h
===================================================================
RCS file: /cvs/gnome/evolution/camel/providers/local/camel-mbox-folder.h,v
retrieving revision 1.6
diff -u -3 -r1.6 camel-mbox-folder.h
--- camel/providers/local/camel-mbox-folder.h	27 Oct 2001 16:59:30 -0000	1.6
+++ camel/providers/local/camel-mbox-folder.h	27 Sep 2004 02:59:03 -0000
@@ -55,6 +55,10 @@
 /* Standard Camel function */
 CamelType camel_mbox_folder_get_type(void);
 
+/* utilities */
+char *camel_mbox_folder_get_full_path (CamelLocalFolder *lf, const char *toplevel_dir, const char *full_name);
+char *camel_mbox_folder_get_meta_path (CamelLocalFolder *lf, const char *toplevel_dir, const char *full_name, const char *ext);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
Index: camel/providers/local/camel-mbox-store.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/providers/local/camel-mbox-store.c,v
retrieving revision 1.37
diff -u -3 -r1.37 camel-mbox-store.c
--- camel/providers/local/camel-mbox-store.c	26 May 2004 04:24:01 -0000	1.37
+++ camel/providers/local/camel-mbox-store.c	27 Sep 2004 02:59:03 -0000
@@ -47,9 +47,6 @@
 #define CF_CLASS(so) CAMEL_FOLDER_CLASS(CAMEL_OBJECT_GET_CLASS(so))
 #define CMBOXF_CLASS(so) CAMEL_MBOX_FOLDER_CLASS(CAMEL_OBJECT_GET_CLASS(so))
 
-extern char *camel_mbox_folder_get_full_path(const char *toplevel_dir, const char *full_name);
-extern char *camel_mbox_folder_get_meta_path(const char *toplevel_dir, const char *full_name, const char *ext);
-
 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, const char *new, CamelException *ex);
@@ -96,7 +93,7 @@
 {
 	const char *toplevel_dir = CAMEL_LOCAL_STORE(store)->toplevel_dir;
 	
-	return camel_mbox_folder_get_full_path(toplevel_dir, folder_name);
+	return camel_mbox_folder_get_full_path(NULL, toplevel_dir, folder_name);
 }
 
 static char *
@@ -104,7 +101,7 @@
 {
 	const char *toplevel_dir = CAMEL_LOCAL_STORE(store)->toplevel_dir;
 	
-	return camel_mbox_folder_get_meta_path(toplevel_dir, folder_name, ext);
+	return camel_mbox_folder_get_meta_path(NULL, toplevel_dir, folder_name, ext);
 }
 
 static char *extensions[] = {
@@ -418,11 +415,11 @@
 	int err = 0;
 	
 	if (ext != NULL) {
-		oldpath = camel_mbox_folder_get_meta_path(toplevel_dir, old_name, ext);
-		newpath = camel_mbox_folder_get_meta_path(toplevel_dir, new_name, ext);
+		oldpath = camel_mbox_folder_get_meta_path(NULL, toplevel_dir, old_name, ext);
+		newpath = camel_mbox_folder_get_meta_path(NULL, toplevel_dir, new_name, ext);
 	} else {
-		oldpath = camel_mbox_folder_get_full_path(toplevel_dir, old_name);
-		newpath = camel_mbox_folder_get_full_path(toplevel_dir, new_name);
+		oldpath = camel_mbox_folder_get_full_path(NULL, toplevel_dir, old_name);
+		newpath = camel_mbox_folder_get_full_path(NULL, toplevel_dir, new_name);
 	}
 	
 	if (stat(oldpath, &st) == -1) {
@@ -617,8 +614,8 @@
 
 		/* This should be fast enough not to have to test for INFO_FAST */
 		root = camel_local_store_get_toplevel_dir((CamelLocalStore *)store);
-		path = camel_mbox_folder_get_meta_path(root, fi->full_name, ".ev-summary");
-		folderpath = camel_mbox_folder_get_full_path(root, fi->full_name);
+		path = camel_mbox_folder_get_meta_path(NULL, root, fi->full_name, ".ev-summary");
+		folderpath = camel_mbox_folder_get_full_path(NULL, root, fi->full_name);
 		
 		mbs = (CamelMboxSummary *)camel_mbox_summary_new(path, folderpath, NULL);
 		if (camel_folder_summary_header_load((CamelFolderSummary *)mbs) != -1) {
Index: camel/providers/local/camel-mh-folder.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/providers/local/camel-mh-folder.c,v
retrieving revision 1.18
diff -u -3 -r1.18 camel-mh-folder.c
--- camel/providers/local/camel-mh-folder.c	21 May 2004 03:30:00 -0000	1.18
+++ camel/providers/local/camel-mh-folder.c	27 Sep 2004 02:59:04 -0000
@@ -49,7 +49,7 @@
 #define CF_CLASS(so) CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
 #define CMHS_CLASS(so) CAMEL_STORE_CLASS (CAMEL_OBJECT_GET_CLASS(so))
 
-static CamelLocalSummary *mh_create_summary(const char *path, const char *folder, CamelIndex *index);
+static CamelLocalSummary *mh_create_summary(CamelLocalFolder *lf, const char *path, const char *folder, CamelIndex *index);
 
 static void mh_append_message(CamelFolder * folder, CamelMimeMessage * message, const CamelMessageInfo *info, char **appended_uid, CamelException * ex);
 static CamelMimeMessage *mh_get_message(CamelFolder * folder, const gchar * uid, CamelException * ex);
@@ -114,7 +114,7 @@
 	return folder;
 }
 
-static CamelLocalSummary *mh_create_summary(const char *path, const char *folder, CamelIndex *index)
+static CamelLocalSummary *mh_create_summary(CamelLocalFolder *lf, const char *path, const char *folder, CamelIndex *index)
 {
 	return (CamelLocalSummary *)camel_mh_summary_new(path, folder, index);
 }
Index: camel/providers/local/camel-spool-folder.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/providers/local/camel-spool-folder.c,v
retrieving revision 1.18
diff -u -3 -r1.18 camel-spool-folder.c
--- camel/providers/local/camel-spool-folder.c	24 Jun 2004 17:44:13 -0000	1.18
+++ camel/providers/local/camel-spool-folder.c	27 Sep 2004 02:59:04 -0000
@@ -41,7 +41,8 @@
 #include "camel-stream-filter.h"
 #include "camel-mime-filter-from.h"
 #include "camel-exception.h"
-
+#include "camel-session.h"
+#include "camel-file-utils.h"
 #include "camel-lock-client.h"
 
 #include "camel-local-private.h"
@@ -55,7 +56,9 @@
 #define CF_CLASS(so) CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
 #define CSPOOLS_CLASS(so) CAMEL_STORE_CLASS (CAMEL_OBJECT_GET_CLASS(so))
 
-static CamelLocalSummary *spool_create_summary(const char *path, const char *folder, CamelIndex *index);
+static char *spool_get_full_path(CamelLocalFolder *lf, const char *toplevel_dir, const char *full_name);
+static char *spool_get_meta_path(CamelLocalFolder *lf, const char *toplevel_dir, const char *full_name, const char *ext);
+static CamelLocalSummary *spool_create_summary(CamelLocalFolder *lf, const char *path, const char *folder, CamelIndex *index);
 
 static int spool_lock(CamelLocalFolder *lf, CamelLockType type, CamelException *ex);
 static void spool_unlock(CamelLocalFolder *lf);
@@ -69,7 +72,8 @@
 
 	parent_class = (CamelFolderClass *)camel_mbox_folder_get_type();
 
-	/* virtual method overload */
+	lklass->get_full_path = spool_get_full_path;
+	lklass->get_meta_path = spool_get_meta_path;
 	lklass->create_summary = spool_create_summary;
 	lklass->lock = spool_lock;
 	lklass->unlock = spool_unlock;
@@ -118,7 +122,7 @@
 	if (parent_store->flags & CAMEL_STORE_FILTER_INBOX
 	    && strcmp(full_name, "INBOX") == 0)
 		folder->folder_flags |= CAMEL_FOLDER_FILTER_RECENT;
-	flags &= CAMEL_STORE_FOLDER_BODY_INDEX;
+	flags &= ~CAMEL_STORE_FOLDER_BODY_INDEX;
 
 	folder = (CamelFolder *)camel_local_folder_construct((CamelLocalFolder *)folder, parent_store, full_name, flags, ex);
 	if (folder) {
@@ -129,8 +133,32 @@
 	return folder;
 }
 
+static char *
+spool_get_full_path(CamelLocalFolder *lf, const char *toplevel_dir, const char *full_name)
+{
+	return g_strdup_printf ("%s/%s", toplevel_dir, full_name);
+}
+
+static char *
+spool_get_meta_path(CamelLocalFolder *lf, const char *toplevel_dir, const char *full_name, const char *ext)
+{
+	CamelService *service = (CamelService *)((CamelFolder *)lf)->parent_store;
+	char *root = camel_session_get_storage_path(service->session, service, NULL);
+	char *path;
+
+	if (root == NULL)
+		return NULL;
+
+
+	camel_mkdir(root, 0777);
+	path = g_strdup_printf("%s/%s%s", root, full_name, ext);
+	g_free(root);
+
+	return path;
+}
+
 static CamelLocalSummary *
-spool_create_summary(const char *path, const char *folder, CamelIndex *index)
+spool_create_summary(CamelLocalFolder *lf, const char *path, const char *folder, CamelIndex *index)
 {
 	return (CamelLocalSummary *)camel_spool_summary_new(folder);
 }
Index: camel/providers/local/camel-spool-store.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/providers/local/camel-spool-store.c,v
retrieving revision 1.22
diff -u -3 -r1.22 camel-spool-store.c
--- camel/providers/local/camel-spool-store.c	26 May 2004 04:24:01 -0000	1.22
+++ camel/providers/local/camel-spool-store.c	27 Sep 2004 02:59:04 -0000
@@ -235,16 +235,51 @@
 	}
 }
 
+/* partially copied from mbox */
+static void
+spool_fill_fi(CamelStore *store, CamelFolderInfo *fi, guint32 flags)
+{
+	CamelFolder *folder;
+
+	fi->unread = -1;
+	fi->total = -1;
+	folder = camel_object_bag_get(store->folders, fi->full_name);
+	if (folder) {
+		if ((flags & CAMEL_STORE_FOLDER_INFO_FAST) == 0)
+			camel_folder_refresh_info(folder, NULL);
+		fi->unread = camel_folder_get_unread_message_count(folder);
+		fi->total = camel_folder_get_message_count(folder);
+		camel_object_unref(folder);
+	}
+}
+
 static CamelFolderInfo *
-camel_folder_info_new(const char *url, const char *full, const char *name, int unread)
+spool_new_fi(CamelStore *store, CamelFolderInfo *parent, CamelFolderInfo **fip, const char *full, guint32 flags)
 {
 	CamelFolderInfo *fi;
+	const char *name;
+	CamelURL *url;
+
+	name = strrchr(full, '/');
+	if (name)
+		name++;
+	else
+		name = full;
 
 	fi = g_malloc0(sizeof(*fi));
-	fi->uri = g_strdup(url);
+	url = camel_url_copy(((CamelService *)store)->url);
+	camel_url_set_fragment(url, full);
+	fi->uri = camel_url_to_string(url, 0);
+	camel_url_free(url);
 	fi->full_name = g_strdup(full);
 	fi->name = g_strdup(name);
-	fi->unread = unread;
+	fi->unread = -1;
+	fi->total = -1;
+	fi->flags = flags;
+
+	fi->parent = parent;
+	fi->next = *fip;
+	*fip = fi;
 
 	d(printf("Adding spoold info: '%s' '%s' '%s' '%s'\n", fi->path, fi->name, fi->full_name, fi->url));
 
@@ -262,11 +297,10 @@
 {
 	DIR *dir;
 	struct dirent *d;
-	char *name, *uri, *tmp, *fname;
+	char *name, *tmp, *fname;
 	CamelFolderInfo *fi = NULL;
 	struct stat st;
 	CamelFolder *folder;
-	int unread;
 	char from[80];
 	FILE *fp;
 
@@ -286,24 +320,8 @@
 	} else if (S_ISREG(st.st_mode)) {
 		/* incase we start scanning from a file.  messy duplication :-/ */
 		if (path) {
-			folder = camel_object_bag_get(store->folders, path);
-			if (folder) {
-				/* should this refresh if ! FAST? */
-				unread = camel_folder_get_unread_message_count(folder);
-				camel_object_unref(folder);
-			} else
-				unread = -1;
-			tmp = strrchr(path, '/');
-			if (tmp)
-				tmp++;
-			else
-				tmp = (char *)path;
-			uri = g_strdup_printf("%s:%s#%s", ((CamelService *)store)->url->protocol, root, path);
-			fi = camel_folder_info_new(uri, path, tmp, unread);
-			fi->parent = parent;
-			fi->next = *fip;
-			*fip = fi;
-			g_free(uri);
+			fi = spool_new_fi(store, parent, fip, path, CAMEL_FOLDER_NOINFERIORS|CAMEL_FOLDER_NOCHILDREN);
+			spool_fill_fi(store, fi, flags);
 		}
 		return 0;
 	}
@@ -317,18 +335,7 @@
 	}
 
 	if (path != NULL) {
-		uri = g_strdup_printf("%s:%s;noselect=yes#%s", ((CamelService *)store)->url->protocol, root, path);
-		tmp = strrchr(path, '/');
-		if (tmp == NULL)
-			tmp = (char *)path;
-		else
-			tmp++;
-		fi = camel_folder_info_new(uri, path, tmp, -1);
-		fi->parent = parent;
-		fi->next = *fip;
-		*fip = fi;
-		g_free(uri);
-	
+		fi = spool_new_fi(store, parent, fip, path, CAMEL_FOLDER_NOSELECT);	
 		fip = &fi->child;
 		parent = fi;
 	}
@@ -346,38 +353,26 @@
 				fname = g_strdup(d->d_name);
 
 			if (S_ISREG(st.st_mode)) {
+				int isfolder = FALSE;
+
 				/* first, see if we already have it open */
 				folder = camel_object_bag_get(store->folders, fname);
-				if (folder) {
-					/* should this refresh if ! FAST? */
-					unread = camel_folder_get_unread_message_count(folder);
-					camel_object_unref(folder);
-				} else
-					unread = -1;
-
-				/* no?  check its content to see if its a folder or not */
 				if (folder == NULL) {
 					fp = fopen(tmp, "r");
 					if (fp != NULL) {
-						if (st.st_size == 0
-						    || (fgets(from, sizeof(from), fp) != NULL
-							&& strncmp(from, "From ", 5) == 0)) {
-							folder = (CamelFolder *)1;
-							/* TODO: if slow mode selected, we could look up unread counts here -
-							   but its pretty expensive */
-						}
+						isfolder = (st.st_size == 0
+							    || (fgets(from, sizeof(from), fp) != NULL
+								&& strncmp(from, "From ", 5) == 0));
 						fclose(fp);
 					}
 				}
 
-				if (folder != NULL) {
-					uri = g_strdup_printf("%s:%s#%s", ((CamelService *)store)->url->protocol, root, fname);
-					fi = camel_folder_info_new(uri, fname, d->d_name, unread);
-					fi->parent = parent;
-					fi->next = *fip;
-					*fip = fi;
-					g_free(uri);
+				if (folder != NULL || isfolder) {
+					fi = spool_new_fi(store, parent, fip, fname, CAMEL_FOLDER_NOINFERIORS|CAMEL_FOLDER_NOCHILDREN);
+					spool_fill_fi(store, fi, flags);
 				}
+				if (folder)
+					camel_object_unref(folder);
 
 			} else if (S_ISDIR(st.st_mode)) {
 				struct _inode in = { st.st_dev, st.st_ino };
@@ -448,22 +443,13 @@
 static CamelFolderInfo *
 get_folder_info_mbox(CamelStore *store, const char *top, guint32 flags, CamelException *ex)
 {
-	CamelFolderInfo *fi = NULL;
-	CamelService *service = (CamelService *)store;
-	CamelFolder *folder;
+	CamelFolderInfo *fi = NULL, *fip = NULL;
 
 	if (top == NULL || strcmp(top, "INBOX") == 0) {
-		fi = g_malloc0(sizeof(*fi));
-		fi->full_name = g_strdup("INBOX");
-		fi->name = g_strdup("INBOX");
-		fi->uri = g_strdup_printf("%s:%s#%s", service->url->protocol, service->url->path, fi->name);
-
-		folder = camel_object_bag_get(store->folders, fi->full_name);
-		if (folder) {
-			fi->unread = camel_folder_get_unread_message_count(folder);
-			camel_object_unref(folder);
-		} else
-			fi->unread = -1;
+		fi = spool_new_fi(store, NULL, &fip, "INBOX", CAMEL_FOLDER_NOINFERIORS|CAMEL_FOLDER_NOCHILDREN|CAMEL_FOLDER_SYSTEM);
+		g_free(fi->name);
+		fi->name = g_strdup(_("Inbox"));
+		spool_fill_fi(store, fi, flags);
 	}
 
 	return fi;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]