diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2004-03-13 05:28:41 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2004-03-13 05:28:41 +0800 |
commit | e28d5364ac2716e911c121657a20923682c5b2b2 (patch) | |
tree | 3a19fe2fc718a493d67b11498d2668094671b7f3 | |
parent | 3f727f063b1e13a89588f9cd1e5cf45a89c391e1 (diff) | |
download | gsoc2013-evolution-e28d5364ac2716e911c121657a20923682c5b2b2.tar.gz gsoc2013-evolution-e28d5364ac2716e911c121657a20923682c5b2b2.tar.zst gsoc2013-evolution-e28d5364ac2716e911c121657a20923682c5b2b2.zip |
Fixes for bug #55018.
2004-03-12 Jeffrey Stedfast <fejj@ximian.com>
Fixes for bug #55018.
* providers/local/camel-local-folder.c
(camel_local_folder_construct): Use camel_url_to_string() here
too, so we properly encode the fragment.
* providers/local/camel-mbox-store.c (get_folder_info): Use
CamelURL to properly encode the fi->uri. Pass the CamelURL into
scan_dir() so that scan_dir() can re-use it (rather than having to
malloc/parse/free for each file/dir)
(scan_dir): Use camel_url_to_string().
* providers/local/camel-maildir-store.c (get_folder_info): Same as
mbox.
(scan_dir): Same as mbox. We also need to set the
CAMEL_FOLDER_NOSELECT flag if appropriate.
* providers/local/camel-mh-store.c (get_folder_info): Same as mbox
and maildir.
(folders_scan): Now takes a url argument which we pass off to
folder_info_new().
(recursive_scan): Same.
(folder_info_new): Use camel_url_to_string().
svn path=/trunk/; revision=25050
-rw-r--r-- | camel/ChangeLog | 26 | ||||
-rw-r--r-- | camel/providers/local/camel-local-folder.c | 14 | ||||
-rw-r--r-- | camel/providers/local/camel-maildir-store.c | 64 | ||||
-rw-r--r-- | camel/providers/local/camel-mbox-store.c | 38 | ||||
-rw-r--r-- | camel/providers/local/camel-mh-store.c | 39 |
5 files changed, 122 insertions, 59 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index 10801c9a60..a962188994 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,29 @@ +2004-03-12 Jeffrey Stedfast <fejj@ximian.com> + + Fixes for bug #55018. + + * providers/local/camel-local-folder.c + (camel_local_folder_construct): Use camel_url_to_string() here + too, so we properly encode the fragment. + + * providers/local/camel-mbox-store.c (get_folder_info): Use + CamelURL to properly encode the fi->uri. Pass the CamelURL into + scan_dir() so that scan_dir() can re-use it (rather than having to + malloc/parse/free for each file/dir) + (scan_dir): Use camel_url_to_string(). + + * providers/local/camel-maildir-store.c (get_folder_info): Same as + mbox. + (scan_dir): Same as mbox. We also need to set the + CAMEL_FOLDER_NOSELECT flag if appropriate. + + * providers/local/camel-mh-store.c (get_folder_info): Same as mbox + and maildir. + (folders_scan): Now takes a url argument which we pass off to + folder_info_new(). + (recursive_scan): Same. + (folder_info_new): Use camel_url_to_string(). + 2004-03-11 Radek Doulik <rodo@ximian.com> * camel-folder.c (camel_folder_set_message_flags): watch for diff --git a/camel/providers/local/camel-local-folder.c b/camel/providers/local/camel-local-folder.c index 5ea484ef99..b61414074e 100644 --- a/camel/providers/local/camel-local-folder.c +++ b/camel/providers/local/camel-local-folder.c @@ -215,7 +215,8 @@ camel_local_folder_construct(CamelLocalFolder *lf, CamelStore *parent_store, con char folder_path[PATH_MAX]; struct stat st; int forceindex, len; - + CamelURL *url; + folder = (CamelFolder *)lf; name = strrchr(full_name, '/'); @@ -309,14 +310,19 @@ camel_local_folder_construct(CamelLocalFolder *lf, CamelStore *parent_store, con camel_object_unref (CAMEL_OBJECT (folder)); return NULL; } - + + url = camel_url_copy (((CamelService *) parent_store)->url); + camel_url_set_fragment (url, full_name); + fi = g_new0 (CamelFolderInfo, 1); fi->full_name = g_strdup (full_name); fi->name = g_strdup (name); - fi->uri = g_strdup_printf("%s:%s#%s", ((CamelService *)parent_store)->url->protocol, ((CamelService *)parent_store)->url->path, full_name); + fi->uri = camel_url_to_string (url, 0); fi->unread = camel_folder_get_unread_message_count(folder); camel_folder_info_build_path(fi, '/'); - + + camel_url_free (url); + camel_object_trigger_event(CAMEL_OBJECT (parent_store), "folder_created", fi); camel_folder_info_free(fi); diff --git a/camel/providers/local/camel-maildir-store.c b/camel/providers/local/camel-maildir-store.c index 5d0654c6e4..a7c3eb4624 100644 --- a/camel/providers/local/camel-maildir-store.c +++ b/camel/providers/local/camel-maildir-store.c @@ -222,7 +222,8 @@ static void delete_folder(CamelStore * store, const char *folder_name, CamelExce g_free(new); } -static CamelFolderInfo *camel_folder_info_new(const char *url, const char *full, const char *name) +static CamelFolderInfo * +camel_folder_info_new (const char *url, const char *full, const char *name, guint32 flags) { CamelFolderInfo *fi; @@ -232,12 +233,13 @@ static CamelFolderInfo *camel_folder_info_new(const char *url, const char *full, fi->name = g_strdup(name); fi->unread = -1; fi->total = -1; + fi->flags = flags; camel_folder_info_build_path(fi, '/'); - + if (!strcmp(full, ".")) fi->flags |= CAMEL_FOLDER_SYSTEM; - d(printf("Adding maildir info: '%s' '%s' '%s' '%s'\n", fi->path, fi->name, fi->full_name, fi->url)); + d(printf("Adding maildir info: '%s' '%s' '%s' '%s'\n", fi->path, fi->name, fi->full_name, fi->uri)); return fi; } @@ -281,13 +283,16 @@ struct _inode { }; /* returns number of records found at or below this level */ -static int scan_dir(CamelStore *store, GHashTable *visited, char *root, const char *path, guint32 flags, CamelFolderInfo *parent, CamelFolderInfo **fip, CamelException *ex) +static int +scan_dir (CamelStore *store, CamelURL *url, GHashTable *visited, char *root, const char *path, guint32 flags, + CamelFolderInfo *parent, CamelFolderInfo **fip, CamelException *ex) { DIR *dir; struct dirent *d; char *name, *uri, *tmp, *cur, *new; const char *base; CamelFolderInfo *fi = NULL; + guint32 fi_flags = 0; struct stat st; /* look for folders matching the right structure, recursively */ @@ -299,13 +304,11 @@ static int scan_dir(CamelStore *store, GHashTable *visited, char *root, const ch cur = g_strdup_printf("%s/cur", name); new = g_strdup_printf("%s/new", name); - if (stat(tmp, &st) == 0 && S_ISDIR(st.st_mode) - && stat(cur, &st) == 0 && S_ISDIR(st.st_mode) - && stat(new, &st) == 0 && S_ISDIR(st.st_mode)) { - uri = g_strdup_printf("maildir:%s#%s", root, path); - } else - uri = g_strdup_printf("maildir:%s;noselect=yes#%s", root, path); - + if (!(stat (tmp, &st) == 0 && S_ISDIR (st.st_mode) + && stat (cur, &st) == 0 && S_ISDIR (st.st_mode) + && stat (new, &st) == 0 && S_ISDIR (st.st_mode))) + fi_flags = CAMEL_FOLDER_NOSELECT; + base = strrchr(path, '/'); if (base) base++; @@ -351,22 +354,25 @@ static int scan_dir(CamelStore *store, GHashTable *visited, char *root, const ch closedir(dir); } } -#endif - fi = camel_folder_info_new(uri, path, base); - fill_fi(store, fi, flags); - - d(printf("found! uri = %s\n", fi->url)); +#endif + + g_free (tmp); + g_free (new); + g_free (cur); + + uri = camel_url_to_string (url, 0); + fi = camel_folder_info_new (uri, path, base, fi_flags); + g_free (uri); + + fill_fi (store, fi, flags); + + d(printf("found! uri = %s\n", fi->uri)); d(printf(" full_name = %s\n name = '%s'\n", fi->full_name, fi->name)); fi->parent = parent; fi->next = *fip; *fip = fi; - g_free(uri); - - g_free(tmp); - g_free(cur); - g_free(new); - + /* always look further if asked */ if (((flags & CAMEL_STORE_FOLDER_INFO_RECURSIVE) || parent == NULL)) { int children = 0; @@ -401,7 +407,7 @@ static int scan_dir(CamelStore *store, GHashTable *visited, char *root, const ch *inew = in; g_hash_table_insert(visited, inew, inew); new = g_strdup_printf("%s/%s", path, d->d_name); - if (scan_dir(store, visited, root, new, flags, fi, &fi->child, ex) == -1) { + if (scan_dir(store, url, visited, root, new, flags, fi, &fi->child, ex) == -1) { g_free(tmp); g_free(new); closedir(dir); @@ -450,16 +456,20 @@ get_folder_info (CamelStore *store, const char *top, guint32 flags, CamelExcepti CamelFolderInfo *fi = NULL; CamelLocalStore *local_store = (CamelLocalStore *)store; GHashTable *visited; - + CamelURL *url; + + url = camel_url_copy (((CamelService *) store)->url); + visited = g_hash_table_new(inode_hash, inode_equal); - - if (scan_dir(store, visited, ((CamelService *)local_store)->url->path, top?top:".", flags, NULL, &fi, ex) == -1 && fi != NULL) { + + if (scan_dir(store, url, visited, ((CamelService *)local_store)->url->path, top?top:".", flags, NULL, &fi, ex) == -1 && fi != NULL) { camel_store_free_folder_info_full(store, fi); fi = NULL; } g_hash_table_foreach(visited, inode_free, NULL); g_hash_table_destroy(visited); - + camel_url_free (url); + return fi; } diff --git a/camel/providers/local/camel-mbox-store.c b/camel/providers/local/camel-mbox-store.c index 595445f99c..45d91b1fa6 100644 --- a/camel/providers/local/camel-mbox-store.c +++ b/camel/providers/local/camel-mbox-store.c @@ -633,7 +633,7 @@ fill_fi(CamelStore *store, CamelFolderInfo *fi, guint32 flags) } static CamelFolderInfo * -scan_dir(CamelStore *store, GHashTable *visited, CamelFolderInfo *parent, const char *root, +scan_dir(CamelStore *store, CamelURL *url, GHashTable *visited, CamelFolderInfo *parent, const char *root, const char *name, guint32 flags, CamelException *ex) { CamelFolderInfo *folders, *tail, *fi; @@ -694,16 +694,14 @@ scan_dir(CamelStore *store, GHashTable *visited, CamelFolderInfo *parent, const fi->flags =(fi->flags & ~CAMEL_FOLDER_NOCHILDREN) | CAMEL_FOLDER_CHILDREN; } else { fi->flags &= ~CAMEL_FOLDER_NOSELECT; - if ((ext = strchr(fi->uri, ';')) && !strncmp(ext, ";noselect=yes", 13)) - memmove(ext, ext + 13, strlen(ext + 13) + 1); } } else { fi = g_new0(CamelFolderInfo, 1); fi->parent = parent; - /* add ";noselect=yes" if we haven't found the mbox file yet. when we find it, remove the noselect */ - fi->uri = g_strdup_printf("mbox:%s%s#%s",((CamelService *) store)->url->path, - S_ISDIR(st.st_mode) ? ";noselect=yes" : "", full_name); + camel_url_set_fragment (url, full_name); + + fi->uri = camel_url_to_string (url, 0); fi->name = short_name; fi->full_name = full_name; fi->path = g_strdup_printf("/%s", full_name); @@ -725,9 +723,9 @@ scan_dir(CamelStore *store, GHashTable *visited, CamelFolderInfo *parent, const g_hash_table_insert(folder_hash, fi->name, fi); } - if (!S_ISDIR(st.st_mode)) + if (!S_ISDIR(st.st_mode)) { fill_fi(store, fi, flags); - else if ((flags & CAMEL_STORE_FOLDER_INFO_RECURSIVE)) { + } else if ((flags & CAMEL_STORE_FOLDER_INFO_RECURSIVE)) { struct _inode in = { st.st_dev, st.st_ino }; if (g_hash_table_lookup(visited, &in) == NULL) { @@ -737,7 +735,7 @@ scan_dir(CamelStore *store, GHashTable *visited, CamelFolderInfo *parent, const g_hash_table_insert(visited, inew, inew); - if ((fi->child = scan_dir(store, visited, fi, path, fi->full_name, flags, ex))) + if ((fi->child = scan_dir (store, url, visited, fi, path, fi->full_name, flags, ex))) fi->flags |= CAMEL_FOLDER_CHILDREN; else fi->flags =(fi->flags & ~CAMEL_FOLDER_CHILDREN) | CAMEL_FOLDER_NOCHILDREN; @@ -763,10 +761,13 @@ get_folder_info(CamelStore *store, const char *top, guint32 flags, CamelExceptio CamelFolderInfo *fi; const char *base; struct stat st; + CamelURL *url; top = top ? top : ""; path = mbox_folder_name_to_path(store, top); + printf ("mbox_get_folder_info for '%s'; path = %s\n", top, path); + if (*top == '\0') { /* requesting root dir scan */ if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) { @@ -782,10 +783,12 @@ get_folder_info(CamelStore *store, const char *top, guint32 flags, CamelExceptio g_hash_table_insert(visited, inode, inode); - fi = scan_dir(store, visited, NULL, path, NULL, flags, ex); + url = camel_url_copy (((CamelService *) store)->url); + fi = scan_dir (store, url, visited, NULL, path, NULL, flags, ex); g_hash_table_foreach(visited, inode_free, NULL); g_hash_table_destroy(visited); - g_free(path); + camel_url_free (url); + g_free (path); return fi; } @@ -802,24 +805,31 @@ get_folder_info(CamelStore *store, const char *top, guint32 flags, CamelExceptio base = top; else base++; - + + url = camel_url_copy (((CamelService *) store)->url); + camel_url_set_fragment (url, top); + fi = g_new0(CamelFolderInfo, 1); fi->parent = NULL; - fi->uri = g_strdup_printf("mbox:%s#%s",((CamelService *) store)->url->path, top); + fi->uri = camel_url_to_string (url, 0); fi->name = g_strdup(base); fi->full_name = g_strdup(top); fi->unread = -1; fi->total = -1; fi->path = g_strdup_printf("/%s", top); + printf ("fi->uri = %s\n\n", fi->uri); + subdir = g_strdup_printf("%s.sbd", path); if (stat(subdir, &st) == 0) { if (S_ISDIR(st.st_mode)) - fi->child = scan_dir(store, visited, fi, subdir, top, flags, ex); + fi->child = scan_dir (store, url, visited, fi, subdir, top, flags, ex); else fill_fi(store, fi, flags); } + camel_url_free (url); + if (fi->child) fi->flags |= CAMEL_FOLDER_CHILDREN; else diff --git a/camel/providers/local/camel-mh-store.c b/camel/providers/local/camel-mh-store.c index e1c03c2349..65f783cac9 100644 --- a/camel/providers/local/camel-mh-store.c +++ b/camel/providers/local/camel-mh-store.c @@ -329,22 +329,26 @@ fill_fi(CamelStore *store, CamelFolderInfo *fi, guint32 flags) } } -static CamelFolderInfo *folder_info_new(CamelStore *store, const char *root, const char *path, guint32 flags) +static CamelFolderInfo * +folder_info_new (CamelStore *store, CamelURL *url, const char *root, const char *path, guint32 flags) { + /* FIXME: need to set fi->flags = CAMEL_FOLDER_NOSELECT (and possibly others) when appropriate */ CamelFolderInfo *fi; char *base; base = strrchr(path, '/'); - + + camel_url_set_fragment (url, path); + /* Build the folder info structure. */ fi = g_malloc0(sizeof(*fi)); - fi->uri = g_strdup_printf("mh:%s#%s", root, path); + fi->uri = camel_url_to_string (url, 0); fi->full_name = g_strdup(path); fi->name = g_strdup(base?base+1:path); camel_folder_info_build_path(fi, '/'); fill_fi(store, fi, flags); - d(printf("New folderinfo:\n '%s'\n '%s'\n '%s'\n", fi->full_name, fi->url, fi->path)); + d(printf("New folderinfo:\n '%s'\n '%s'\n '%s'\n", fi->full_name, fi->uri, fi->path)); return fi; } @@ -357,7 +361,9 @@ struct _inode { /* Scan path, under root, for directories to add folders for. Both * root and path should have a trailing "/" if they aren't empty. */ -static void recursive_scan(CamelStore *store, CamelFolderInfo **fip, CamelFolderInfo *parent, GHashTable *visited, const char *root, const char *path, guint32 flags) +static void +recursive_scan (CamelStore *store, CamelURL *url, CamelFolderInfo **fip, CamelFolderInfo *parent, + GHashTable *visited, const char *root, const char *path, guint32 flags) { char *fullpath, *tmp; DIR *dp; @@ -388,7 +394,7 @@ static void recursive_scan(CamelStore *store, CamelFolderInfo **fip, CamelFolder g_hash_table_insert(visited, inew, inew); /* link in ... */ - fi = folder_info_new(store, root, path, flags); + fi = folder_info_new(store, url, root, path, flags); fi->parent = parent; fi->next = *fip; *fip = fi; @@ -414,10 +420,10 @@ static void recursive_scan(CamelStore *store, CamelFolderInfo **fip, CamelFolder /* otherwise, treat at potential node, and recurse, a bit more expensive than needed, but tough! */ if (path[0]) { tmp = g_strdup_printf("%s/%s", path, d->d_name); - recursive_scan(store, &fi->child, fi, visited, root, tmp, flags); + recursive_scan(store, url, &fi->child, fi, visited, root, tmp, flags); g_free(tmp); } else { - recursive_scan(store, &fi->child, fi, visited, root, d->d_name, flags); + recursive_scan(store, url, &fi->child, fi, visited, root, d->d_name, flags); } } @@ -427,7 +433,7 @@ static void recursive_scan(CamelStore *store, CamelFolderInfo **fip, CamelFolder /* scan a .folders file */ static void -folders_scan(CamelStore *store, const char *root, const char *top, CamelFolderInfo **fip, guint32 flags) +folders_scan(CamelStore *store, CamelURL *url, const char *root, const char *top, CamelFolderInfo **fip, guint32 flags) { CamelFolderInfo *fi; char line[512], *path, *tmp; @@ -490,7 +496,7 @@ folders_scan(CamelStore *store, const char *root, const char *top, CamelFolderIn path = g_strdup_printf("%s/%s", root, line); if (stat(path, &st) == 0 && S_ISDIR(st.st_mode)) { - fi = folder_info_new(store, root, line, flags); + fi = folder_info_new(store, url, root, line, flags); g_ptr_array_add(folders, fi); } g_free(path); @@ -530,20 +536,23 @@ static CamelFolderInfo * get_folder_info (CamelStore *store, const char *top, guint32 flags, CamelException *ex) { CamelFolderInfo *fi = NULL; + CamelURL *url; char *root; - + root = ((CamelService *)store)->url->path; + url = camel_url_copy (((CamelService *) store)->url); + /* use .folders if we are supposed to */ if (((CamelMhStore *)store)->flags & CAMEL_MH_DOTFOLDERS) { - folders_scan(store, root, top, &fi, flags); + folders_scan(store, url, root, top, &fi, flags); } else { GHashTable *visited = g_hash_table_new(inode_hash, inode_equal); if (top == NULL) top = ""; - recursive_scan(store, &fi, NULL, visited, root, top, flags); + recursive_scan(store, url, &fi, NULL, visited, root, top, flags); /* if we actually scanned from root, we have a "" root node we dont want */ if (fi != NULL && top[0] == 0) { @@ -558,6 +567,8 @@ get_folder_info (CamelStore *store, const char *top, guint32 flags, CamelExcepti g_hash_table_foreach(visited, inode_free, NULL); g_hash_table_destroy(visited); } - + + camel_url_free (url); + return fi; } |