aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/imap/camel-imap-summary.c
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2000-10-13 04:55:11 +0800
committerDan Winship <danw@src.gnome.org>2000-10-13 04:55:11 +0800
commite81e64f8dd9facde47e93e3f4e8b190978eeb91b (patch)
tree3e7634780b337f499d385447bcc71c7e20a280c4 /camel/providers/imap/camel-imap-summary.c
parentdd388c63f597303b2f0d6f4d8346574183f307b6 (diff)
downloadgsoc2013-evolution-e81e64f8dd9facde47e93e3f4e8b190978eeb91b.tar
gsoc2013-evolution-e81e64f8dd9facde47e93e3f4e8b190978eeb91b.tar.gz
gsoc2013-evolution-e81e64f8dd9facde47e93e3f4e8b190978eeb91b.tar.bz2
gsoc2013-evolution-e81e64f8dd9facde47e93e3f4e8b190978eeb91b.tar.lz
gsoc2013-evolution-e81e64f8dd9facde47e93e3f4e8b190978eeb91b.tar.xz
gsoc2013-evolution-e81e64f8dd9facde47e93e3f4e8b190978eeb91b.tar.zst
gsoc2013-evolution-e81e64f8dd9facde47e93e3f4e8b190978eeb91b.zip
Simple subclass of CamelFolderSummary that also keeps a UIDVALIDITY value
* providers/imap/camel-imap-summary.c: Simple subclass of CamelFolderSummary that also keeps a UIDVALIDITY value (and doesn't, for the moment, build content info). * providers/imap/camel-imap-folder.c: (various): Use a CamelImapSummary to store/fetch summary info. (camel_imap_folder_new): Take a path to a file to use for the summary. Set the folder's permanent_flags correctly according to the server response. Read in the summary (checking the UIDVALIDITY) and update it if it's out of date. (imap_refresh_info): Just fetch UIDs and flags. If the UIDs all match, update the flags as needed and be done with it. Otherwise, delete messages that have been expunged from the server and fetch full summary info for any new messages. (imap_sync): Save the summary to disk. (imap_update_summary): Renamed from imap_get_summary_internal. Can now be told to get summary for only a subset of messages. Use camel-mime-utils functions rather than rolling our own header parsing. (imap_get_message_info_internal): Merged into imap_update_summary. (imap_set_message_flags): Don't marked the message FOLDER_FLAGGED if we're not actually changing the value of any of the flags. (camel_imap_folder_changed): Deal with EXISTS rather than RECENT. * providers/imap/camel-imap-store.c (imap_connect): Call camel_session_get_storage_path and save the value. (get_folder): Create a local directory to store summary information and pass a summary file name to camel_imap_folder_new. Don't call camel_folder_refresh_info from here any more since camel_imap_folder_new does it again. * providers/imap/camel-imap-command.c (camel_imap_command): Add a special case to this to make it possible to get the repsonses from a SELECT and still have store->current_folder be updated correctly. (imap_read_response): parse EXISTS rather than RECENT * camel-session.c (camel_session_get_storage_path): Use e_mkdir_hier. * camel-folder-summary.c (camel_folder_summary_remove_index): New function. * camel-mime-utils.c (header_raw_append_parse): fix this. (camel-mime-parser.c doesn't use this code because of the MEMPOOL optimization, so nothing was ever actually calling it before.) svn path=/trunk/; revision=5891
Diffstat (limited to 'camel/providers/imap/camel-imap-summary.c')
-rw-r--r--camel/providers/imap/camel-imap-summary.c147
1 files changed, 147 insertions, 0 deletions
diff --git a/camel/providers/imap/camel-imap-summary.c b/camel/providers/imap/camel-imap-summary.c
new file mode 100644
index 0000000000..ebdf8b9842
--- /dev/null
+++ b/camel/providers/imap/camel-imap-summary.c
@@ -0,0 +1,147 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2000 Helix Code Inc.
+ *
+ * Authors:
+ * Michael Zucchi <notzed@helixcode.com>
+ * Dan Winship <danw@helixcode.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#include "camel-imap-summary.h"
+#include <camel/camel-mime-message.h>
+
+#include <sys/stat.h>
+#include <sys/uio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+
+#define CAMEL_IMAP_SUMMARY_VERSION (0x1000)
+
+static int summary_header_load (CamelFolderSummary *, FILE *);
+static int summary_header_save (CamelFolderSummary *, FILE *);
+
+static void camel_imap_summary_class_init (CamelImapSummaryClass *klass);
+static void camel_imap_summary_init (CamelImapSummary *obj);
+
+static CamelFolderSummaryClass *camel_imap_summary_parent;
+
+CamelType
+camel_imap_summary_get_type (void)
+{
+ static CamelType type = CAMEL_INVALID_TYPE;
+
+ if (type == CAMEL_INVALID_TYPE) {
+ type = camel_type_register(
+ camel_folder_summary_get_type(), "CamelImapSummary",
+ sizeof (CamelImapSummary),
+ sizeof (CamelImapSummaryClass),
+ (CamelObjectClassInitFunc) camel_imap_summary_class_init,
+ NULL,
+ (CamelObjectInitFunc) camel_imap_summary_init,
+ NULL);
+ }
+
+ return type;
+}
+
+static void
+camel_imap_summary_class_init (CamelImapSummaryClass *klass)
+{
+ CamelFolderSummaryClass *cfs_class = (CamelFolderSummaryClass *) klass;
+
+ camel_imap_summary_parent = CAMEL_FOLDER_SUMMARY_CLASS (camel_type_get_global_classfuncs (camel_folder_summary_get_type()));
+
+ cfs_class->summary_header_load = summary_header_load;
+ cfs_class->summary_header_save = summary_header_save;
+}
+
+static void
+camel_imap_summary_init (CamelImapSummary *obj)
+{
+ CamelFolderSummary *s = (CamelFolderSummary *)obj;
+
+ /* subclasses need to set the right instance data sizes */
+ s->message_info_size = sizeof(CamelImapMessageInfo);
+ s->content_info_size = sizeof(CamelImapMessageContentInfo);
+
+ /* and a unique file version */
+ s->version += CAMEL_IMAP_SUMMARY_VERSION;
+}
+
+/**
+ * camel_imap_summary_new:
+ * @filename: the file to store the summary in.
+ * @validity: the current UIDVALIDITY value of the folder
+ *
+ * This will create a new CamelImapSummary object and read in the
+ * summary data from disk, if it exists and has the right UIDVALIDITY
+ * value.
+ *
+ * Return value: A new CamelImapSummary object.
+ **/
+CamelFolderSummary *
+camel_imap_summary_new (const char *filename, guint32 validity)
+{
+ CamelFolderSummary *summary = CAMEL_FOLDER_SUMMARY (
+ camel_object_new (camel_imap_summary_get_type ()));
+ CamelImapSummary *imap_summary = (CamelImapSummary *)summary;
+
+ camel_folder_summary_set_build_content (summary, FALSE);
+ camel_folder_summary_set_filename (summary, filename);
+
+ if (camel_folder_summary_load (summary) == -1) {
+ if (errno == ENOENT) {
+ imap_summary->validity = validity;
+ return summary;
+ } else {
+ camel_object_unref ((CamelObject *)summary);
+ return NULL;
+ }
+ }
+ if (imap_summary->validity != validity) {
+ camel_folder_summary_clear (summary);
+ imap_summary->validity = validity;
+ }
+
+ return summary;
+}
+
+
+static int
+summary_header_load (CamelFolderSummary *s, FILE *in)
+{
+ CamelImapSummary *ims = CAMEL_IMAP_SUMMARY (s);
+
+ if (camel_imap_summary_parent->summary_header_load (s, in) == -1)
+ return -1;
+
+ return camel_folder_summary_decode_uint32 (in, &ims->validity);
+}
+
+static int
+summary_header_save (CamelFolderSummary *s, FILE *out)
+{
+ CamelImapSummary *ims = CAMEL_IMAP_SUMMARY(s);
+
+ if (camel_imap_summary_parent->summary_header_save (s, out) == -1)
+ return -1;
+
+ return camel_folder_summary_encode_uint32 (out, ims->validity);
+}