aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/local
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2004-02-16 17:38:24 +0800
committerMichael Zucci <zucchi@src.gnome.org>2004-02-16 17:38:24 +0800
commit1ceb4cd764fbdd89a3b67903251dc89ad3e7d723 (patch)
treea551592e442ee3404caa5d05a8362d7dd1d553b0 /camel/providers/local
parent22fdff59a00dbbdcc6c6a59f452cfa7141bc7aad (diff)
downloadgsoc2013-evolution-1ceb4cd764fbdd89a3b67903251dc89ad3e7d723.tar
gsoc2013-evolution-1ceb4cd764fbdd89a3b67903251dc89ad3e7d723.tar.gz
gsoc2013-evolution-1ceb4cd764fbdd89a3b67903251dc89ad3e7d723.tar.bz2
gsoc2013-evolution-1ceb4cd764fbdd89a3b67903251dc89ad3e7d723.tar.lz
gsoc2013-evolution-1ceb4cd764fbdd89a3b67903251dc89ad3e7d723.tar.xz
gsoc2013-evolution-1ceb4cd764fbdd89a3b67903251dc89ad3e7d723.tar.zst
gsoc2013-evolution-1ceb4cd764fbdd89a3b67903251dc89ad3e7d723.zip
** See bug #51045.
2004-02-16 Not Zed <NotZed@Ximian.com> ** See bug #51045. * providers/imap/camel-imap-store.c (fill_fi): similar to mbox version. (get_folder_counts): use fill_fi to try and get folder counts if we're not doing the hard slog. (get_one_folder_offline): use fill_fi to try to get folder counts from open folders or summaries. * providers/local/camel-maildir-store.c (fill_fi): similar to mbox version. (scan_dir): use fill_fi to get the unread count now. * providers/local/camel-mbox-store.c (fill_fi): helper to lookup unread count either from active folder or from summary file, if it's available. (scan_dir, get_folder_info): use helper above to get folder info. * devel-docs/camel-folder-summary.txt: New document describing the format/conventions in the CamelFolderSummary file. * providers/nntp/camel-nntp-summary.c (summary_header_load/save): * providers/imapp/camel-imapp-summary.c (summary_header_load/save): * providers/imap/camel-imap-summary.c (summary_header_load/save): Handle versions, per-class version number (1). * providers/local/camel-mbox-summary.c (summary_header_load/save): Handle versions properly, add a per-class version (1). Write out the folder size as a size_t rather than 32 bit int. * providers/local/camel-local-summary.c (summary_header_load/save): read/write the per-class version number (1). * camel-folder-summary.c (summary_header_load): do version checking differently, allow the version to be bumped without aborting the load. Added unread/deleted/junk counts to base header. (summary_header_save): Save out the new-format header. Version bumped to 13. * camel.c (camel_init): return 0 rather than spit a compiler warning. * camel-file-utils.c (camel_file_util_encode_*_t): macro-ise the type encoder/decoders. Also add size_t encoder/decoder. svn path=/trunk/; revision=24744
Diffstat (limited to 'camel/providers/local')
-rw-r--r--camel/providers/local/camel-local-summary.c38
-rw-r--r--camel/providers/local/camel-local-summary.h4
-rw-r--r--camel/providers/local/camel-maildir-store.c46
-rw-r--r--camel/providers/local/camel-mbox-store.c86
-rw-r--r--camel/providers/local/camel-mbox-summary.c17
-rw-r--r--camel/providers/local/camel-mbox-summary.h1
6 files changed, 154 insertions, 38 deletions
diff --git a/camel/providers/local/camel-local-summary.c b/camel/providers/local/camel-local-summary.c
index 42534b361d..a1f4831675 100644
--- a/camel/providers/local/camel-local-summary.c
+++ b/camel/providers/local/camel-local-summary.c
@@ -34,12 +34,16 @@
#include "camel-local-summary.h"
#include "camel/camel-mime-message.h"
#include "camel/camel-stream-null.h"
+#include "camel/camel-file-utils.h"
#define w(x)
#define io(x)
#define d(x) /*(printf("%s(%d): ", __FILE__, __LINE__),(x))*/
-#define CAMEL_LOCAL_SUMMARY_VERSION (0x200)
+#define CAMEL_LOCAL_SUMMARY_VERSION (1)
+
+static int summary_header_load (CamelFolderSummary *, FILE *);
+static int summary_header_save (CamelFolderSummary *, FILE *);
static CamelMessageInfo * message_info_new (CamelFolderSummary *, struct _camel_header_raw *);
@@ -81,6 +85,9 @@ camel_local_summary_class_init(CamelLocalSummaryClass *klass)
camel_local_summary_parent = CAMEL_FOLDER_SUMMARY_CLASS(camel_type_get_global_classfuncs(camel_folder_summary_get_type()));
+ sklass->summary_header_load = summary_header_load;
+ sklass->summary_header_save = summary_header_save;
+
sklass->message_info_new = message_info_new;
klass->load = local_summary_load;
@@ -577,6 +584,35 @@ local_summary_decode_x_evolution(CamelLocalSummary *cls, const char *xev, CamelM
return 0;
}
+static int
+summary_header_load(CamelFolderSummary *s, FILE *in)
+{
+ CamelLocalSummary *cls = (CamelLocalSummary *)s;
+
+ /* We dont actually add our own headers, but version that we don't anyway */
+
+ if (((CamelFolderSummaryClass *)camel_local_summary_parent)->summary_header_load(s, in) == -1)
+ return -1;
+
+ /* Legacy version, version is in summary only */
+ if ((s->version & 0xfff) == 0x20c)
+ return 0;
+
+ /* otherwise load the version number */
+ return camel_file_util_decode_fixed_int32(in, &cls->version);
+}
+
+static int
+summary_header_save(CamelFolderSummary *s, FILE *out)
+{
+ /*CamelLocalSummary *cls = (CamelLocalSummary *)s;*/
+
+ if (((CamelFolderSummaryClass *)camel_local_summary_parent)->summary_header_save(s, out) == -1)
+ return -1;
+
+ return camel_file_util_encode_fixed_int32(out, CAMEL_LOCAL_SUMMARY_VERSION);
+}
+
static CamelMessageInfo *
message_info_new(CamelFolderSummary *s, struct _camel_header_raw *h)
{
diff --git a/camel/providers/local/camel-local-summary.h b/camel/providers/local/camel-local-summary.h
index 25d77e62c3..99a520f243 100644
--- a/camel/providers/local/camel-local-summary.h
+++ b/camel/providers/local/camel-local-summary.h
@@ -42,7 +42,9 @@ enum {
struct _CamelLocalSummary {
CamelFolderSummary parent;
-
+
+ guint32 version; /* file version being loaded */
+
char *folder_path; /* name of matching folder */
CamelIndex *index;
diff --git a/camel/providers/local/camel-maildir-store.c b/camel/providers/local/camel-maildir-store.c
index 0eff01f1d2..df17bcd5d9 100644
--- a/camel/providers/local/camel-maildir-store.c
+++ b/camel/providers/local/camel-maildir-store.c
@@ -36,6 +36,7 @@
#include "camel-exception.h"
#include "camel-url.h"
#include "camel-private.h"
+#include "camel-maildir-summary.h"
#define d(x)
@@ -237,6 +238,45 @@ static CamelFolderInfo *camel_folder_info_new(const char *url, const char *full,
return fi;
}
+static void
+fill_fi(CamelStore *store, CamelFolderInfo *fi, guint32 flags)
+{
+ CamelFolder *folder;
+ int unread = -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);
+ unread = camel_folder_get_unread_message_count(folder);
+ camel_object_unref(folder);
+ } else {
+ char *path, *folderpath;
+ CamelFolderSummary *s;
+ const char *root;
+
+ printf("looking up counts from '%s'\n", fi->full_name);
+
+ /* This should be fast enough not to have to test for INFO_FAST */
+ root = camel_local_store_get_toplevel_dir((CamelLocalStore *)store);
+ path = g_strdup_printf("%s/%s.ev-summary", root, fi->full_name);
+ folderpath = g_strdup_printf("%s/%s", root, fi->full_name);
+ s = (CamelFolderSummary *)camel_maildir_summary_new(path, folderpath, NULL);
+ if (camel_folder_summary_header_load(s) != -1) {
+ unread = s->unread_count;
+ printf("loaded summary header unread = %d\n", unread);
+ } else {
+ printf("couldn't load summary header?\n");
+ }
+
+ camel_object_unref(s);
+ g_free(folderpath);
+ g_free(path);
+ }
+
+ fi->unread_message_count = unread;
+}
+
/* used to find out where we've visited already */
struct _inode {
dev_t dnode;
@@ -316,8 +356,10 @@ static int scan_dir(CamelStore *store, GHashTable *visited, char *root, const ch
}
}
- fi = camel_folder_info_new(uri, path, base, unread);
-
+ fi = camel_folder_info_new(uri, path, base, -1);
+ /* fills the unread count */
+ fill_fi(store, fi, flags);
+
d(printf("found! uri = %s\n", fi->url));
d(printf(" full_name = %s\n name = '%s'\n", fi->full_name, fi->name));
diff --git a/camel/providers/local/camel-mbox-store.c b/camel/providers/local/camel-mbox-store.c
index b1a5664c33..ef11791e8c 100644
--- a/camel/providers/local/camel-mbox-store.c
+++ b/camel/providers/local/camel-mbox-store.c
@@ -581,6 +581,47 @@ inode_free(void *k, void *v, void *d)
g_free(k);
}
+/* NB: duplicated in maildir store */
+static void
+fill_fi(CamelStore *store, CamelFolderInfo *fi, guint32 flags)
+{
+ CamelFolder *folder;
+ int unread = -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);
+ unread = camel_folder_get_unread_message_count(folder);
+ camel_object_unref(folder);
+ } else {
+ char *path, *folderpath;
+ CamelMboxSummary *mbs;
+ const char *root;
+
+ printf("looking up counts from '%s'\n", fi->full_name);
+
+ /* 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);
+
+ mbs = (CamelMboxSummary *)camel_mbox_summary_new(path, folderpath, NULL);
+ if (camel_folder_summary_header_load((CamelFolderSummary *)mbs) != -1) {
+ unread = ((CamelFolderSummary *)mbs)->unread_count;
+ printf("loaded summary header unread = %d\n", unread);
+ } else {
+ printf("couldn't load summary header?\n");
+ }
+
+ camel_object_unref(mbs);
+ g_free(folderpath);
+ g_free(path);
+ }
+
+ fi->unread_message_count = unread;
+}
+
static CamelFolderInfo *
scan_dir(CamelStore *store, GHashTable *visited, CamelFolderInfo *parent, const char *root,
const char *name, guint32 flags, CamelException *ex)
@@ -603,9 +644,7 @@ scan_dir(CamelStore *store, GHashTable *visited, CamelFolderInfo *parent, const
while ((dent = readdir(dir))) {
char *short_name, *full_name, *path, *ext;
- CamelFolder *folder;
struct stat st;
- int unread = -1;
if (dent->d_name[0] == '.')
continue;
@@ -636,17 +675,7 @@ scan_dir(CamelStore *store, GHashTable *visited, CamelFolderInfo *parent, const
full_name = g_strdup_printf("%s/%s", name, short_name);
else
full_name = g_strdup(short_name);
-
- if (!S_ISDIR(st.st_mode)) {
- folder = camel_object_bag_get(store->folders, full_name);
- if (folder) {
- if ((flags & CAMEL_STORE_FOLDER_INFO_FAST) == 0)
- camel_folder_refresh_info(folder, NULL);
- unread = camel_folder_get_unread_message_count(folder);
- camel_object_unref(folder);
- }
- }
-
+
if ((fi = g_hash_table_lookup(folder_hash, short_name)) != NULL) {
g_free(short_name);
g_free(full_name);
@@ -654,7 +683,6 @@ scan_dir(CamelStore *store, GHashTable *visited, CamelFolderInfo *parent, const
if (S_ISDIR(st.st_mode)) {
fi->flags =(fi->flags & ~CAMEL_FOLDER_NOCHILDREN) | CAMEL_FOLDER_CHILDREN;
} else {
- fi->unread_message_count = unread;
fi->flags &= ~CAMEL_FOLDER_NOSELECT;
if ((ext = strchr(fi->url, ';')) && !strncmp(ext, ";noselect=yes", 13))
memmove(ext, ext + 13, strlen(ext + 13) + 1);
@@ -669,7 +697,7 @@ scan_dir(CamelStore *store, GHashTable *visited, CamelFolderInfo *parent, const
fi->name = short_name;
fi->full_name = full_name;
fi->path = g_strdup_printf("/%s", full_name);
- fi->unread_message_count = unread;
+ fi->unread_message_count = -1;
if (S_ISDIR(st.st_mode))
fi->flags = CAMEL_FOLDER_NOSELECT;
@@ -686,7 +714,9 @@ scan_dir(CamelStore *store, GHashTable *visited, CamelFolderInfo *parent, const
g_hash_table_insert(folder_hash, fi->name, fi);
}
- if ((flags & CAMEL_STORE_FOLDER_INFO_RECURSIVE) && S_ISDIR(st.st_mode)) {
+ if (!S_ISDIR(st.st_mode))
+ fill_fi(store, fi, flags);
+ 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) {
@@ -718,10 +748,8 @@ get_folder_info(CamelStore *store, const char *top, guint32 flags, CamelExceptio
struct _inode *inode;
char *path, *subdir;
CamelFolderInfo *fi;
- CamelFolder *folder;
const char *base;
struct stat st;
- int unread = -1;
top = top ? top : "";
path = mbox_folder_name_to_path(store, top);
@@ -735,7 +763,7 @@ get_folder_info(CamelStore *store, const char *top, guint32 flags, CamelExceptio
visited = g_hash_table_new(inode_hash, inode_equal);
- inode = g_new(struct _inode, 1);
+ inode = g_malloc0(sizeof(*inode));
inode->dnode = st.st_dev;
inode->inode = st.st_ino;
@@ -761,26 +789,22 @@ get_folder_info(CamelStore *store, const char *top, guint32 flags, CamelExceptio
base = top;
else
base++;
-
- folder = camel_object_bag_get(store->folders, top);
- if (folder) {
- if ((flags & CAMEL_STORE_FOLDER_INFO_FAST) == 0)
- camel_folder_refresh_info(folder, NULL);
- unread = camel_folder_get_unread_message_count(folder);
- camel_object_unref(folder);
- }
-
+
fi = g_new0(CamelFolderInfo, 1);
fi->parent = NULL;
fi->url = g_strdup_printf("mbox:%s#%s",((CamelService *) store)->url->path, top);
fi->name = g_strdup(base);
fi->full_name = g_strdup(top);
- fi->unread_message_count = unread;
+ fi->unread_message_count = -1;
fi->path = g_strdup_printf("/%s", top);
subdir = g_strdup_printf("%s.sbd", path);
- if (stat(subdir, &st) == 0 && S_ISDIR(st.st_mode))
- fi->child = scan_dir(store, visited, fi, subdir, top, flags, ex);
+ if (stat(subdir, &st) == 0) {
+ if (S_ISDIR(st.st_mode))
+ fi->child = scan_dir(store, visited, fi, subdir, top, flags, ex);
+ else
+ fill_fi(store, fi, flags);
+ }
if (fi->child)
fi->flags |= CAMEL_FOLDER_CHILDREN;
diff --git a/camel/providers/local/camel-mbox-summary.c b/camel/providers/local/camel-mbox-summary.c
index 4018fc93c9..ac87fd2476 100644
--- a/camel/providers/local/camel-mbox-summary.c
+++ b/camel/providers/local/camel-mbox-summary.c
@@ -44,7 +44,7 @@
#define io(x)
#define d(x) /*(printf("%s(%d): ", __FILE__, __LINE__),(x))*/
-#define CAMEL_MBOX_SUMMARY_VERSION (0x1000)
+#define CAMEL_MBOX_SUMMARY_VERSION (1)
static int summary_header_load (CamelFolderSummary *, FILE *);
static int summary_header_save (CamelFolderSummary *, FILE *);
@@ -172,7 +172,16 @@ summary_header_load(CamelFolderSummary *s, FILE *in)
if (((CamelFolderSummaryClass *)camel_mbox_summary_parent)->summary_header_load(s, in) == -1)
return -1;
- return camel_file_util_decode_uint32(in, (guint32 *) &mbs->folder_size);
+ /* legacy version */
+ if (s->version == 0x120c)
+ return camel_file_util_decode_uint32(in, (guint32 *) &mbs->folder_size);
+
+ /* version 1 */
+ if (camel_file_util_decode_fixed_int32(in, &mbs->version) == -1
+ || camel_file_util_decode_size_t(in, &mbs->folder_size) == -1)
+ return -1;
+
+ return 0;
}
static int
@@ -183,7 +192,9 @@ summary_header_save(CamelFolderSummary *s, FILE *out)
if (((CamelFolderSummaryClass *)camel_mbox_summary_parent)->summary_header_save(s, out) == -1)
return -1;
- return camel_file_util_encode_uint32(out, mbs->folder_size);
+ camel_file_util_encode_fixed_int32(out, CAMEL_MBOX_SUMMARY_VERSION);
+
+ return camel_file_util_encode_size_t(out, mbs->folder_size);
}
static CamelMessageInfo *
diff --git a/camel/providers/local/camel-mbox-summary.h b/camel/providers/local/camel-mbox-summary.h
index dc64aa23fa..34402ad264 100644
--- a/camel/providers/local/camel-mbox-summary.h
+++ b/camel/providers/local/camel-mbox-summary.h
@@ -48,6 +48,7 @@ struct _CamelMboxSummary {
CamelFolderChangeInfo *changes; /* used to build change sets */
+ guint32 version;
size_t folder_size; /* size of the mbox file, last sync */
unsigned int xstatus:1; /* do we store/honour xstatus/status headers */