From f3c3a422abf537dcfc24030433e9556d34d71492 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Tue, 28 Sep 2004 04:32:13 +0000 Subject: make sure body indexing is turned off always, missed the ~ bit. 2004-09-27 Not Zed * 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 :-/. svn path=/trunk/; revision=27407 --- camel/ChangeLog | 23 +++++ camel/providers/local/camel-local-folder.c | 31 ++++--- camel/providers/local/camel-local-folder.h | 6 +- camel/providers/local/camel-maildir-folder.c | 4 +- camel/providers/local/camel-mbox-folder.c | 15 ++-- camel/providers/local/camel-mbox-folder.h | 4 + camel/providers/local/camel-mbox-store.c | 19 ++-- camel/providers/local/camel-mh-folder.c | 4 +- camel/providers/local/camel-spool-folder.c | 37 +++++++- camel/providers/local/camel-spool-store.c | 128 ++++++++++++--------------- 10 files changed, 153 insertions(+), 118 deletions(-) diff --git a/camel/ChangeLog b/camel/ChangeLog index 361a07bc36..9d1c574e72 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,26 @@ +2004-09-27 Not Zed + + * 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-22 Jeffrey Stedfast * providers/imap/camel-imap-store.c (connect_to_server): Instead diff --git a/camel/providers/local/camel-local-folder.c b/camel/providers/local/camel-local-folder.c index 5900d48bea..70673d9687 100644 --- a/camel/providers/local/camel-local-folder.c +++ b/camel/providers/local/camel-local-folder.c @@ -20,7 +20,6 @@ * */ - #ifdef HAVE_CONFIG_H #include #endif @@ -74,8 +73,8 @@ static int local_setv(CamelObject *object, CamelException *ex, CamelArgV *args); 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); @@ -246,10 +245,10 @@ camel_local_folder_construct(CamelLocalFolder *lf, CamelStore *parent_store, con 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); @@ -300,7 +299,7 @@ camel_local_folder_construct(CamelLocalFolder *lf, CamelStore *parent_store, con 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, NULL) == -1) { /* ? */ } @@ -464,15 +463,15 @@ local_setv(CamelObject *object, CamelException *ex, CamelArgV *args) } 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 @@ -559,10 +558,10 @@ local_rename(CamelFolder *folder, const char *newname) 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); diff --git a/camel/providers/local/camel-local-folder.h b/camel/providers/local/camel-local-folder.h index 00669e738b..4aec420813 100644 --- a/camel/providers/local/camel-local-folder.h +++ b/camel/providers/local/camel-local-folder.h @@ -75,11 +75,11 @@ typedef struct { /* 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); diff --git a/camel/providers/local/camel-maildir-folder.c b/camel/providers/local/camel-maildir-folder.c index bd38dcf3d7..669e636527 100644 --- a/camel/providers/local/camel-maildir-folder.c +++ b/camel/providers/local/camel-maildir-folder.c @@ -50,7 +50,7 @@ static CamelLocalFolderClass *parent_class = NULL; #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); @@ -151,7 +151,7 @@ camel_maildir_folder_new(CamelStore *parent_store, const char *full_name, guint3 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); } diff --git a/camel/providers/local/camel-mbox-folder.c b/camel/providers/local/camel-mbox-folder.c index a28db10951..b4926b9b04 100644 --- a/camel/providers/local/camel-mbox-folder.c +++ b/camel/providers/local/camel-mbox-folder.c @@ -53,9 +53,6 @@ static CamelLocalFolderClass *parent_class = NULL; #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); @@ -68,7 +65,7 @@ static void mbox_set_message_user_tag(CamelFolder *folder, const char *uid, cons 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); @@ -148,7 +145,7 @@ camel_mbox_folder_new(CamelStore *parent_store, const char *full_name, guint32 f } 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; @@ -184,7 +181,7 @@ 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) +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 @@ -196,11 +193,11 @@ camel_mbox_folder_get_meta_path (const char *toplevel_dir, const char *full_name 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); @@ -208,7 +205,7 @@ camel_mbox_folder_get_meta_path (const char *toplevel_dir, const char *full_name #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); } diff --git a/camel/providers/local/camel-mbox-folder.h b/camel/providers/local/camel-mbox-folder.h index aa0b67201f..fa76001849 100644 --- a/camel/providers/local/camel-mbox-folder.h +++ b/camel/providers/local/camel-mbox-folder.h @@ -55,6 +55,10 @@ CamelFolder *camel_mbox_folder_new(CamelStore *parent_store, const char *full_na /* 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 */ diff --git a/camel/providers/local/camel-mbox-store.c b/camel/providers/local/camel-mbox-store.c index 76811949fd..f98c87a8ea 100644 --- a/camel/providers/local/camel-mbox-store.c +++ b/camel/providers/local/camel-mbox-store.c @@ -48,9 +48,6 @@ static CamelLocalStoreClass *parent_class = NULL; #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); @@ -97,7 +94,7 @@ mbox_folder_name_to_path(CamelStore *store, const char *folder_name) { 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 * @@ -105,7 +102,7 @@ mbox_folder_name_to_meta_path(CamelStore *store, const char *folder_name, const { 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[] = { @@ -419,11 +416,11 @@ xrename(CamelStore *store, const char *old_name, const char *new_name, const cha 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) { @@ -618,8 +615,8 @@ fill_fi(CamelStore *store, CamelFolderInfo *fi, guint32 flags) /* 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) { diff --git a/camel/providers/local/camel-mh-folder.c b/camel/providers/local/camel-mh-folder.c index 5f71ab09ea..fd054933c5 100644 --- a/camel/providers/local/camel-mh-folder.c +++ b/camel/providers/local/camel-mh-folder.c @@ -50,7 +50,7 @@ static CamelLocalFolderClass *parent_class = NULL; #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); @@ -115,7 +115,7 @@ camel_mh_folder_new(CamelStore *parent_store, const char *full_name, guint32 fla 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); } diff --git a/camel/providers/local/camel-spool-folder.c b/camel/providers/local/camel-spool-folder.c index 026d99402e..b9cb643189 100644 --- a/camel/providers/local/camel-spool-folder.c +++ b/camel/providers/local/camel-spool-folder.c @@ -41,6 +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" #include "camel-i18n.h" @@ -54,7 +56,9 @@ static CamelFolderClass *parent_class = NULL; #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); @@ -68,7 +72,8 @@ camel_spool_folder_class_init(CamelSpoolFolderClass *klass) 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; @@ -117,7 +122,7 @@ camel_spool_folder_new(CamelStore *parent_store, const char *full_name, guint32 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) { @@ -128,8 +133,32 @@ camel_spool_folder_new(CamelStore *parent_store, const char *full_name, guint32 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); } diff --git a/camel/providers/local/camel-spool-store.c b/camel/providers/local/camel-spool-store.c index f1f715e404..3dc21886c8 100644 --- a/camel/providers/local/camel-spool-store.c +++ b/camel/providers/local/camel-spool-store.c @@ -236,16 +236,51 @@ static void free_folder_info (CamelStore *store, CamelFolderInfo *fi) } } +/* 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)); @@ -263,11 +298,10 @@ static int scan_dir(CamelStore *store, GHashTable *visited, char *root, const ch { 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; @@ -287,24 +321,8 @@ static int scan_dir(CamelStore *store, GHashTable *visited, char *root, const ch } 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; } @@ -318,18 +336,7 @@ static int scan_dir(CamelStore *store, GHashTable *visited, char *root, const ch } 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; } @@ -347,38 +354,26 @@ static int scan_dir(CamelStore *store, GHashTable *visited, char *root, const ch 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 }; @@ -449,22 +444,13 @@ get_folder_info_elm(CamelStore *store, const char *top, guint32 flags, CamelExce 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; -- cgit