diff options
author | Not Zed <NotZed@Ximian.com> | 2002-09-26 13:34:10 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2002-09-26 13:34:10 +0800 |
commit | a007d6d2084df436d5f1fa2b6804064c6e7c62e0 (patch) | |
tree | b74d0961cc17c7935369ca6724785eaef1adce4b /camel | |
parent | e45b3e48281defcf3df2761b4bf3ce0c3b2d5357 (diff) | |
download | gsoc2013-evolution-a007d6d2084df436d5f1fa2b6804064c6e7c62e0.tar gsoc2013-evolution-a007d6d2084df436d5f1fa2b6804064c6e7c62e0.tar.gz gsoc2013-evolution-a007d6d2084df436d5f1fa2b6804064c6e7c62e0.tar.bz2 gsoc2013-evolution-a007d6d2084df436d5f1fa2b6804064c6e7c62e0.tar.lz gsoc2013-evolution-a007d6d2084df436d5f1fa2b6804064c6e7c62e0.tar.xz gsoc2013-evolution-a007d6d2084df436d5f1fa2b6804064c6e7c62e0.tar.zst gsoc2013-evolution-a007d6d2084df436d5f1fa2b6804064c6e7c62e0.zip |
Implement FOLDER_CREATE flag. (scan_dir): Dont free name on exception, its
2002-09-26 Not Zed <NotZed@Ximian.com>
* providers/local/camel-spool-store.c (get_folder): Implement
FOLDER_CREATE flag.
(scan_dir): Dont free name on exception, its alloca'd.
(scan_dir): If we start scanning from a file, just add that
directly.
(scan_dir): Allow empty files to also show up in folder list, as
well as files starting with "From ".
* providers/local/camel-spool-folder.c (camel_spool_folder_new):
Check folder != NULL before writing to it.
* providers/local/camel-local-store.c (create_folder): Handle a
parent of NULL for creating top-level dirs. Part of #31186.
svn path=/trunk/; revision=18230
Diffstat (limited to 'camel')
-rw-r--r-- | camel/ChangeLog | 14 | ||||
-rw-r--r-- | camel/providers/local/camel-local-store.c | 12 | ||||
-rw-r--r-- | camel/providers/local/camel-spool-folder.c | 7 | ||||
-rw-r--r-- | camel/providers/local/camel-spool-store.c | 88 |
4 files changed, 101 insertions, 20 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index 651cede20a..ab75d5d5df 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,5 +1,19 @@ 2002-09-26 Not Zed <NotZed@Ximian.com> + * providers/local/camel-spool-store.c (get_folder): Implement + FOLDER_CREATE flag. + (scan_dir): Dont free name on exception, its alloca'd. + (scan_dir): If we start scanning from a file, just add that + directly. + (scan_dir): Allow empty files to also show up in folder list, as + well as files starting with "From ". + + * providers/local/camel-spool-folder.c (camel_spool_folder_new): + Check folder != NULL before writing to it. + + * providers/local/camel-local-store.c (create_folder): Handle a + parent of NULL for creating top-level dirs. Part of #31186. + * providers/imap/camel-imap-store.c (parse_list_response_as_folder_info): Store the folder flags in the store summary. diff --git a/camel/providers/local/camel-local-store.c b/camel/providers/local/camel-local-store.c index 0fbb9eb14e..567b2b316a 100644 --- a/camel/providers/local/camel-local-store.c +++ b/camel/providers/local/camel-local-store.c @@ -222,15 +222,16 @@ create_folder(CamelStore *store, const char *parent_name, const char *folder_nam /* This is a pretty hacky version of create folder, but should basically work */ - /* FIXME: The strings here are funny because of string freeze */ - if (path[0] != '/') { camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, _("Store root %s is not an absolute path"), path); return NULL; } - name = g_strdup_printf("%s/%s/%s", path, parent_name, folder_name); + if (parent_name) + name = g_strdup_printf("%s/%s/%s", path, parent_name, folder_name); + else + name = g_strdup_printf("%s/%s", path, folder_name); if (stat(name, &st) == 0 || errno != ENOENT) { camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, @@ -241,7 +242,10 @@ create_folder(CamelStore *store, const char *parent_name, const char *folder_nam g_free(name); - name = g_strdup_printf("%s/%s", parent_name, folder_name); + if (parent_name) + name = g_strdup_printf("%s/%s", parent_name, folder_name); + else + name = g_strdup_printf("%s", folder_name); folder = ((CamelStoreClass *)((CamelObject *)store)->klass)->get_folder(store, name, CAMEL_STORE_FOLDER_CREATE, ex); if (folder) { diff --git a/camel/providers/local/camel-spool-folder.c b/camel/providers/local/camel-spool-folder.c index 55df340c26..8118468a60 100644 --- a/camel/providers/local/camel-spool-folder.c +++ b/camel/providers/local/camel-spool-folder.c @@ -122,9 +122,10 @@ camel_spool_folder_new(CamelStore *parent_store, const char *full_name, guint32 flags &= CAMEL_STORE_FOLDER_BODY_INDEX; folder = (CamelFolder *)camel_local_folder_construct((CamelLocalFolder *)folder, parent_store, full_name, flags, ex); - - if (camel_url_get_param(((CamelService *)parent_store)->url, "xstatus")) - camel_mbox_summary_xstatus((CamelMboxSummary *)folder->summary, TRUE); + if (folder) { + if (camel_url_get_param(((CamelService *)parent_store)->url, "xstatus")) + camel_mbox_summary_xstatus((CamelMboxSummary *)folder->summary, TRUE); + } return folder; } diff --git a/camel/providers/local/camel-spool-store.c b/camel/providers/local/camel-spool-store.c index 6c26f780a0..b1e7c7e091 100644 --- a/camel/providers/local/camel-spool-store.c +++ b/camel/providers/local/camel-spool-store.c @@ -23,7 +23,9 @@ #include <config.h> #endif +#include <sys/types.h> #include <sys/stat.h> +#include <fcntl.h> #include <errno.h> #include <string.h> #include <unistd.h> @@ -134,21 +136,52 @@ construct (CamelService *service, CamelSession *session, CamelProvider *provider static CamelFolder * get_folder(CamelStore * store, const char *folder_name, guint32 flags, CamelException * ex) { - CamelFolder *folder; + CamelFolder *folder = NULL; + int fd; + struct stat st; + char *name; d(printf("opening folder %s on path %s\n", folder_name, path)); /* we only support an 'INBOX' in mbox mode */ - if (((CamelSpoolStore *)store)->type == CAMEL_SPOOL_STORE_MBOX - && strcmp(folder_name, "INBOX") != 0) { - camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, - _("Folder `%s/%s' does not exist."), - ((CamelService *)store)->url->path, folder_name); - return NULL; + if (((CamelSpoolStore *)store)->type == CAMEL_SPOOL_STORE_MBOX) { + if (strcmp(folder_name, "INBOX") != 0) { + camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, + _("Folder `%s/%s' does not exist."), + ((CamelService *)store)->url->path, folder_name); + } else { + folder = camel_spool_folder_new(store, folder_name, flags, ex); + } + } else { + name = g_strdup_printf("%s%s", CAMEL_LOCAL_STORE(store)->toplevel_dir, folder_name); + if (stat(name, &st) == -1) { + if (errno != ENOENT) { + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + _("Could not open folder `%s':\n%s"), + folder_name, strerror(errno)); + } else if ((flags & CAMEL_STORE_FOLDER_CREATE) == 0) { + camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, + _("Folder `%s' does not exist."), folder_name); + } else { + fd = open(name, O_CREAT, 0600); + if (fd == -1) { + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + _("Could not create folder `%s':\n%s"), + folder_name, strerror(errno)); + } else { + close(fd); + folder = camel_spool_folder_new(store, folder_name, flags, ex); + } + } + } else if (!S_ISREG(st.st_mode)) { + camel_exception_setv(ex, CAMEL_EXCEPTION_STORE_NO_FOLDER, + _("`%s' is not a mailbox file."), name); + } else { + folder = camel_spool_folder_new(store, folder_name, flags, ex); + } + g_free(name); } - folder = camel_spool_folder_new(store, folder_name, flags, ex); - return folder; } @@ -246,12 +279,40 @@ static int scan_dir(CamelStore *store, GHashTable *visited, char *root, const ch } else name = root; + if (stat(name, &st) == -1) { + camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, + _("Could not scan folder `%s': %s"), + name, strerror(errno)); + } else if (S_ISREG(st.st_mode)) { + /* incase we start scanning from a file. messy duplication :-/ */ + if (path) { + CAMEL_STORE_LOCK(store, cache_lock); + folder = g_hash_table_lookup(store->folders, path); + if (folder) + unread = camel_folder_get_unread_message_count(folder); + else + unread = -1; + CAMEL_STORE_UNLOCK(store, cache_lock); + 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->sibling = *fip; + *fip = fi; + g_free(uri); + } + return 0; + } + dir = opendir(name); if (dir == NULL) { camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Could not scan folder `%s': %s"), - root, strerror(errno)); - g_free(name); + name, strerror(errno)); return -1; } @@ -298,8 +359,9 @@ static int scan_dir(CamelStore *store, GHashTable *visited, char *root, const ch if (folder == NULL) { fp = fopen(tmp, "r"); if (fp != NULL) { - if (fgets(from, sizeof(from), fp) != NULL - && strncmp(from, "From ", 5) == 0) { + 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 */ |