Re: [Evolution-hackers] Memory consumption and virtual machines



On Tue, 2006-07-18 at 16:05 -0500, Federico Mena Quintero wrote:
> On Tue, 2006-07-18 at 14:46 -0400, Jeffrey Stedfast wrote:

> 
> I've been talking to Philip on IRC, and gave him these requirements for
> his patch:
> 
> 1. Don't change the external ABI of Camel, so that Evo needs no changes,
> *OR* also submit a patch to update Evo for the changed API.

Achieved

> 2. Make sure the summary format on disk works with older Evos without
> making *them* rewrite the summaries.  This is for deployments which have
> machines with old and new versions of GNOME, but NFS homedirs accessible
> from any machine.

Achieved my renaming all the summary filenames

> 3. Keep the coding style, variable naming convention, indentation, etc.

Done


For you, attached and on a plate:

	o. The patch for evolution-data-server
	o. The patch for evolution-exchange


Trying to get this upstream is, for me, saying thank you.

Looking at the patch technically AND testing it (and if it doesn't
perform, giving me numbers that compare it with the original implement-
ation) is all I'm asking for.

If Novell wants me to implement unit tests (or other tests) for this, I
will ask for payment.

-- 
Philip Van Hoof, software developer at x-tend 
home: me at pvanhoof dot be 
gnome: pvanhoof at gnome dot org 
work: vanhoof at x-tend dot be 
http://www.pvanhoof.be - http://www.x-tend.be
Index: camel/camel-file-utils.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-file-utils.c,v
retrieving revision 1.17
diff -p -u -r1.17 camel-file-utils.c
--- camel/camel-file-utils.c	2 Jun 2006 00:52:29 -0000	1.17
+++ camel/camel-file-utils.c	18 Jul 2006 22:48:49 -0000
@@ -49,135 +49,117 @@
 
 #define IO_TIMEOUT (60*4)
 
+
 /**
- * camel_file_util_encode_uint32:
+ * camel_file_util_encode_fixed_int32:
  * @out: file to output to
  * @value: value to output
  * 
- * Utility function to save an uint32 to a file.
+ * Encode a gint32, performing no compression, but converting
+ * to network order.
  * 
  * Return value: 0 on success, -1 on error.
  **/
 int
-camel_file_util_encode_uint32 (FILE *out, guint32 value)
+camel_file_util_encode_fixed_int32 (FILE *out, gint32 value)
 {
-	int i;
+	guint32 save;
 
-	for (i = 28; i > 0; i -= 7) {
-		if (value >= (1 << i)) {
-			unsigned int c = (value >> i) & 0x7f;
-			if (fputc (c, out) == -1)
-				return -1;
-		}
-	}
-	return fputc (value | 0x80, out);
+	save = g_htonl (value);
+	if (fwrite (&save, sizeof (save), 1, out) != 1)
+		return -1;
+	return 0;
 }
 
 
 /**
- * camel_file_util_decode_uint32:
+ * camel_file_util_decode_fixed_int32:
  * @in: file to read from
  * @dest: pointer to a variable to store the value in
  * 
- * Retrieve an encoded uint32 from a file.
+ * Retrieve a gint32.
  * 
- * Return value: 0 on success, -1 on error.  @*dest will contain the
- * decoded value.
+ * Return value: 0 on success, -1 on error.
  **/
 int
-camel_file_util_decode_uint32 (FILE *in, guint32 *dest)
+camel_file_util_decode_fixed_int32 (FILE *in, gint32 *dest)
 {
-        guint32 value = 0;
-	int v;
+	guint32 save;
 
-        /* until we get the last byte, keep decoding 7 bits at a time */
-        while ( ((v = fgetc (in)) & 0x80) == 0 && v!=EOF) {
-                value |= v;
-                value <<= 7;
-        }
-	if (v == EOF) {
-		*dest = value >> 7;
+	if (fread (&save, sizeof (save), 1, in) == 1) {
+		*dest = g_ntohl (save);
+		return 0;
+	} else {
 		return -1;
 	}
-	*dest = value | (v & 0x7f);
-
-        return 0;
 }
 
 
 /**
- * camel_file_util_encode_fixed_int32:
+ * camel_file_util_encode_uint32:
  * @out: file to output to
  * @value: value to output
  * 
- * Encode a gint32, performing no compression, but converting
- * to network order.
+ * Utility function to save an uint32 to a file.
  * 
  * Return value: 0 on success, -1 on error.
  **/
 int
-camel_file_util_encode_fixed_int32 (FILE *out, gint32 value)
+camel_file_util_encode_uint32 (FILE *out, guint32 value)
 {
-	guint32 save;
-
-	save = g_htonl (value);
-	if (fwrite (&save, sizeof (save), 1, out) != 1)
-		return -1;
-	return 0;
+	return camel_file_util_encode_fixed_int32 (out, value);
 }
 
 
 /**
- * camel_file_util_decode_fixed_int32:
+ * camel_file_util_decode_uint32:
  * @in: file to read from
  * @dest: pointer to a variable to store the value in
  * 
- * Retrieve a gint32.
+ * Retrieve an encoded uint32 from a file.
  * 
- * Return value: 0 on success, -1 on error.
+ * Return value: 0 on success, -1 on error.  @*dest will contain the
+ * decoded value.
  **/
 int
-camel_file_util_decode_fixed_int32 (FILE *in, gint32 *dest)
+camel_file_util_decode_uint32 (FILE *in, guint32 *dest)
 {
-	guint32 save;
+	return camel_file_util_decode_fixed_int32 (in, (gint32*)dest);
+}
 
-	if (fread (&save, sizeof (save), 1, in) == 1) {
-		*dest = g_ntohl (save);
-		return 0;
-	} else {
-		return -1;
-	}
+
+unsigned char*
+camel_file_util_mmap_decode_uint32 (unsigned char *start, guint32 *dest, gboolean is_string)
+{
+	guint32 value = 0;
+	value = g_ntohl(get_unaligned_u32(start)); start += 4;
+	*dest = value;
+	return start;
 }
 
-#define CFU_ENCODE_T(type)						\
-int									\
-camel_file_util_encode_##type(FILE *out, type value)			\
-{									\
-	int i;								\
-									\
-	for (i = sizeof (type) - 1; i >= 0; i--) {			\
-		if (fputc((value >> (i * 8)) & 0xff, out) == -1)	\
-			return -1;					\
-	}								\
-	return 0;							\
+/* This casting should be okay, because it also gets BOTH written and read from
+   the file using a 4 byte integer. */
+
+#define CFU_ENCODE_T(type)						  \
+int									  \
+camel_file_util_encode_##type(FILE *out, type value)			  \
+{									  \
+	return camel_file_util_encode_fixed_int32 (out, (guint32) value); \
 }
 
-#define CFU_DECODE_T(type)				\
-int							\
-camel_file_util_decode_##type(FILE *in, type *dest)	\
-{							\
-	type save = 0;					\
-	int i = sizeof(type) - 1;			\
-	int v = EOF;					\
-							\
-        while (i >= 0 && (v = fgetc (in)) != EOF) {	\
-		save |= ((type)v) << (i * 8);		\
-		i--;					\
-	}						\
-	*dest = save;					\
-	if (v == EOF)					\
-		return -1;				\
-	return 0;					\
+#define CFU_DECODE_T(type)						  \
+int									  \
+camel_file_util_decode_##type(FILE *in, type *dest)			  \
+{									  \
+	return camel_file_util_decode_fixed_int32 (in, (gint32*) dest);  \
+}
+
+
+#define MMAP_DECODE_T(type)						    \
+unsigned char*								    \
+camel_file_util_mmap_decode_##type(unsigned char *start, type *dest)	    \
+{									    \
+	return camel_file_util_mmap_decode_uint32 (start, (guint32*) dest, FALSE); \
 }
 
 
@@ -202,6 +184,7 @@ CFU_ENCODE_T(time_t)
  * Return value: 0 on success, -1 on error.
  **/
 CFU_DECODE_T(time_t)
+MMAP_DECODE_T(time_t)
 
 /**
  * camel_file_util_encode_off_t:
@@ -225,6 +208,7 @@ CFU_ENCODE_T(off_t)
  * Return value: 0 on success, -1 on failure.
  **/
 CFU_DECODE_T(off_t)
+MMAP_DECODE_T(off_t)
 
 /**
  * camel_file_util_encode_size_t:
@@ -248,6 +232,7 @@ CFU_ENCODE_T(size_t)
  * Return value: 0 on success, -1 on failure.
  **/
 CFU_DECODE_T(size_t)
+MMAP_DECODE_T(size_t)
 
 
 /**
@@ -262,18 +247,31 @@ CFU_DECODE_T(size_t)
 int
 camel_file_util_encode_string (FILE *out, const char *str)
 {
-	register int len;
+	register int lena, len;
+
+	if (str == NULL) {
+		if (camel_file_util_encode_uint32 (out, 0) == -1)
+			return -1;
 
-	if (str == NULL)
-		return camel_file_util_encode_uint32 (out, 1);
-	
-	if ((len = strlen (str)) > 65536)
-		len = 65536;
-	
-	if (camel_file_util_encode_uint32 (out, len+1) == -1)
-		return -1;
-	if (len == 0 || fwrite (str, len, 1, out) == 1)
 		return 0;
+	}
+
+	lena = len = strlen (str) + 1;
+
+	if (lena % G_MEM_ALIGN)
+		lena += G_MEM_ALIGN - (lena % G_MEM_ALIGN);
+
+	if (camel_file_util_encode_uint32 (out, lena) == -1)
+		return -1;
+
+	if (fwrite (str, len, 1, out) == 1) {
+		if (lena > len) {
+			if (fwrite ("\0\0\0\0\0\0\0\0", lena-len, 1, out) == 1)
+				return 0;
+			else return -1;
+		}
+	}
+
 	return -1;
 }
 
@@ -298,12 +296,6 @@ camel_file_util_decode_string (FILE *in,
 		return -1;
 	}
 
-	len--;
-	if (len > 65536) {
-		*str = NULL;
-		return -1;
-	}
-
 	ret = g_malloc (len+1);
 	if (len > 0 && fread (ret, len, 1, in) != 1) {
 		g_free (ret);
@@ -313,6 +305,7 @@ camel_file_util_decode_string (FILE *in,
 
 	ret[len] = 0;
 	*str = ret;
+
 	return 0;
 }
 
Index: camel/camel-file-utils.h
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-file-utils.h,v
retrieving revision 1.11
diff -p -u -r1.11 camel-file-utils.h
--- camel/camel-file-utils.h	10 Jan 2006 07:56:46 -0000	1.11
+++ camel/camel-file-utils.h	18 Jul 2006 22:48:49 -0000
@@ -46,6 +46,7 @@ int camel_file_util_encode_fixed_int32 (
 int camel_file_util_decode_fixed_int32 (FILE *in, gint32 *);
 int camel_file_util_encode_uint32 (FILE *out, guint32);
 int camel_file_util_decode_uint32 (FILE *in, guint32 *);
+
 int camel_file_util_encode_time_t (FILE *out, time_t);
 int camel_file_util_decode_time_t (FILE *in, time_t *);
 int camel_file_util_encode_off_t (FILE *out, off_t);
@@ -55,6 +56,11 @@ int camel_file_util_decode_size_t (FILE 
 int camel_file_util_encode_string (FILE *out, const char *);
 int camel_file_util_decode_string (FILE *in, char **);
 
+unsigned char* camel_file_util_mmap_decode_time_t(unsigned char *start, time_t *dest);
+unsigned char* camel_file_util_mmap_decode_off_t(unsigned char *start, off_t *dest);
+unsigned char* camel_file_util_mmap_decode_size_t(unsigned char *start, size_t *dest);
+unsigned char* camel_file_util_mmap_decode_uint32 (unsigned char *start, guint32 *dest, gboolean is_string);
+
 char *camel_file_util_safe_filename (const char *name);
 
 /* Code that intends to be portable to Win32 should use camel_read()
@@ -71,6 +77,11 @@ ssize_t camel_read_socket (int fd, char 
 ssize_t camel_write_socket (int fd, const char *buf, size_t n);
 
 char *camel_file_util_savename(const char *filename);
+
+#define get_unaligned_u32(p) ((((unsigned char*)(p))[0]) | \
+	(((unsigned char*)(p))[1] << 8) | \
+	(((unsigned char*)(p))[2] << 16) | \
+	(((unsigned char*)(p))[3] << 24))
 
 #ifdef __cplusplus
 }
Index: camel/camel-folder-summary.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-folder-summary.c,v
retrieving revision 1.149
diff -p -u -r1.149 camel-folder-summary.c
--- camel/camel-folder-summary.c	6 Jul 2006 19:43:46 -0000	1.149
+++ camel/camel-folder-summary.c	18 Jul 2006 22:48:53 -0000
@@ -50,6 +50,7 @@
 #include "camel-stream-null.h"
 #include "camel-stream-filter.h"
 #include "camel-string-utils.h"
+#include "camel-disco-folder.h"
 
 #include "libedataserver/md5-utils.h"
 #include "libedataserver/e-memory.h"
@@ -66,15 +67,15 @@ static pthread_mutex_t info_lock = PTHRE
 /* this should probably be conditional on it existing */
 #define USE_BSEARCH
 
-#define d(x)
+#define d(x)	
 #define io(x)			/* io debug */
-#define w(x)
+#define w(x)	
 
 #if 0
 extern int strdup_count, malloc_count, free_count;
 #endif
 
-#define CAMEL_FOLDER_SUMMARY_VERSION (13)
+#define CAMEL_FOLDER_SUMMARY_VERSION (15)
 
 #define _PRIVATE(o) (((CamelFolderSummary *)(o))->priv)
 
@@ -86,20 +87,20 @@ struct _node {
 static struct _node *my_list_append(struct _node **list, struct _node *n);
 static int my_list_size(struct _node **list);
 
-static int summary_header_load(CamelFolderSummary *, FILE *);
-static int summary_header_save(CamelFolderSummary *, FILE *);
+static int summary_header_load(CamelFolderSummary *);
+static int summary_header_save(CamelFolderSummary *, FILE *out);
 
 static CamelMessageInfo * message_info_new_from_header(CamelFolderSummary *, struct _camel_header_raw *);
 static CamelMessageInfo * message_info_new_from_parser(CamelFolderSummary *, CamelMimeParser *);
 static CamelMessageInfo * message_info_new_from_message(CamelFolderSummary *s, CamelMimeMessage *msg);
-static CamelMessageInfo * message_info_load(CamelFolderSummary *, FILE *);
+static CamelMessageInfo * message_info_load(CamelFolderSummary *);
 static int		  message_info_save(CamelFolderSummary *, FILE *, CamelMessageInfo *);
 static void		  message_info_free(CamelFolderSummary *, CamelMessageInfo *);
 
 static CamelMessageContentInfo * content_info_new_from_header(CamelFolderSummary *, struct _camel_header_raw *);
 static CamelMessageContentInfo * content_info_new_from_parser(CamelFolderSummary *, CamelMimeParser *);
 static CamelMessageContentInfo * content_info_new_from_message(CamelFolderSummary *s, CamelMimePart *mp);
-static CamelMessageContentInfo * content_info_load(CamelFolderSummary *, FILE *);
+static CamelMessageContentInfo * content_info_load(CamelFolderSummary *);
 static int		         content_info_save(CamelFolderSummary *, FILE *, CamelMessageContentInfo *);
 static void		         content_info_free(CamelFolderSummary *, CamelMessageContentInfo *);
 
@@ -138,6 +139,7 @@ camel_folder_summary_init (CamelFolderSu
 	s->time = 0;
 	s->nextuid = 1;
 
+
 	s->messages = g_ptr_array_new();
 	s->messages_uid = g_hash_table_new(g_str_hash, g_str_equal);
 	
@@ -160,6 +162,11 @@ camel_folder_summary_finalize (CamelObje
 	struct _CamelFolderSummaryPrivate *p;
 	CamelFolderSummary *s = (CamelFolderSummary *)obj;
 
+
+	if (s->file)
+		g_mapped_file_free (s->file);
+	s->file = NULL;
+
 	p = _PRIVATE(obj);
 
 	camel_folder_summary_clear(s);
@@ -236,7 +243,7 @@ camel_folder_summary_new (struct _CamelF
 	CamelFolderSummary *new = CAMEL_FOLDER_SUMMARY ( camel_object_new (camel_folder_summary_get_type ()));
 
 	new->folder = folder;
-
+	
 	return new;
 }
 
@@ -499,23 +506,30 @@ camel_folder_summary_next_uid_string(Cam
 
 /* loads the content descriptions, recursively */
 static CamelMessageContentInfo *
-perform_content_info_load(CamelFolderSummary *s, FILE *in)
+perform_content_info_load(CamelFolderSummary *s)
 {
 	int i;
 	guint32 count;
 	CamelMessageContentInfo *ci, *part;
+	unsigned char *ptrchr = s->filepos;
+
+	ci = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->content_info_load(s);
 
-	ci = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->content_info_load(s, in);
 	if (ci == NULL)
 		return NULL;
 
-	if (camel_file_util_decode_uint32(in, &count) == -1 || count > 500) {
+	ptrchr = s->filepos;
+	ptrchr = camel_file_util_mmap_decode_uint32 ((unsigned char*)ptrchr, &count, FALSE);
+	s->filepos = ptrchr;
+
+	if (count > 500) {
 		camel_folder_summary_content_info_free(s, ci);
 		return NULL;
 	}
 
 	for (i=0;i<count;i++) {
-		part = perform_content_info_load(s, in);
+
+		part = perform_content_info_load(s);
 		if (part) {
 			my_list_append((struct _node **)&ci->childs, (struct _node *)part);
 			part->parent = ci;
@@ -540,31 +554,34 @@ perform_content_info_load(CamelFolderSum
 int
 camel_folder_summary_load(CamelFolderSummary *s)
 {
-	FILE *in;
 	int i;
 	CamelMessageInfo *mi;
 
-	if (s->summary_path == NULL)
-		return 0;
 
-	in = g_fopen(s->summary_path, "rb");
-	if (in == NULL)
-		return -1;
+	if (s->summary_path == NULL || !g_file_test (s->summary_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))
+		return 0;
 
 	CAMEL_SUMMARY_LOCK(s, io_lock);
-	if ( ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_load(s, in) == -1)
+
+	if (!s->file)
+		s->file = g_mapped_file_new (s->summary_path, FALSE, NULL);
+
+	s->filepos = (unsigned char*) g_mapped_file_get_contents (s->file);
+
+	if ( ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_load(s) == -1)
 		goto error;
 
 	/* now read in each message ... */
 	for (i=0;i<s->saved_count;i++) {
-		mi = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->message_info_load(s, in);
+		mi = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->message_info_load(s);
 
 		if (mi == NULL)
 			goto error;
 
 		/* FIXME: this should be done differently, how i don't know */
+
 		if (s->build_content) {
-			((CamelMessageInfoBase *)mi)->content = perform_content_info_load(s, in);
+			((CamelMessageInfoBase *)mi)->content = perform_content_info_load(s);
 			if (((CamelMessageInfoBase *)mi)->content == NULL) {
 				camel_message_info_free(mi);
 				goto error;
@@ -574,13 +591,12 @@ camel_folder_summary_load(CamelFolderSum
 		camel_folder_summary_add(s, mi);
 	}
 
+
 	CAMEL_SUMMARY_UNLOCK(s, io_lock);
-	
-	if (fclose (in) != 0)
-		return -1;
 
 	s->flags &= ~CAMEL_SUMMARY_DIRTY;
 
+
 	return 0;
 
 error:
@@ -588,7 +604,6 @@ error:
 		g_warning ("Cannot load summary file: `%s': %s", s->summary_path, g_strerror (errno));
 	
 	CAMEL_SUMMARY_UNLOCK(s, io_lock);
-	fclose (in);
 	s->flags |= ~CAMEL_SUMMARY_DIRTY;
 
 	return -1;
@@ -646,6 +661,7 @@ camel_folder_summary_save(CamelFolderSum
 	fd = g_open(path, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0600);
 	if (fd == -1)
 		return -1;
+
 	out = fdopen(fd, "wb");
 	if (out == NULL) {
 		i = errno;
@@ -678,10 +694,11 @@ camel_folder_summary_save(CamelFolderSum
 	
 	if (fflush (out) != 0 || fsync (fileno (out)) == -1)
 		goto exception;
+
+	CAMEL_SUMMARY_UNLOCK(s, io_lock);
 	
 	fclose (out);
-	
-	CAMEL_SUMMARY_UNLOCK(s, io_lock);
+
 	
 #ifdef G_OS_WIN32
 	g_unlink(s->summary_path);
@@ -694,19 +711,21 @@ camel_folder_summary_save(CamelFolderSum
 	}
 	
 	s->flags &= ~CAMEL_SUMMARY_DIRTY;
+
 	return 0;
 	
  exception:
+
+	CAMEL_SUMMARY_UNLOCK(s, io_lock);
 	
 	i = errno;
 	
 	fclose (out);
-	
-	CAMEL_SUMMARY_UNLOCK(s, io_lock);
-	
+		
 	g_unlink (path);
 	errno = i;
 	
+
 	return -1;
 }
 
@@ -724,22 +743,24 @@ camel_folder_summary_save(CamelFolderSum
 int
 camel_folder_summary_header_load(CamelFolderSummary *s)
 {
-	FILE *in;
 	int ret;
 
-	if (s->summary_path == NULL)
+	if (s->summary_path == NULL || !g_file_test (s->summary_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))
 		return 0;
 
-	in = g_fopen(s->summary_path, "rb");
-	if (in == NULL)
-		return -1;
-
 	CAMEL_SUMMARY_LOCK(s, io_lock);
-	ret = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_load(s, in);
-	CAMEL_SUMMARY_UNLOCK(s, io_lock);
+
+	if (!s->file)
+		s->file = g_mapped_file_new (s->summary_path, FALSE, NULL);
+
+	s->filepos = (unsigned char*) g_mapped_file_get_contents (s->file);
+
+	
+	ret = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_load(s);
 	
-	fclose(in);
 	s->flags &= ~CAMEL_SUMMARY_DIRTY;
+	CAMEL_SUMMARY_UNLOCK(s, io_lock);
+
 	return ret;
 }
 
@@ -748,11 +769,15 @@ summary_assign_uid(CamelFolderSummary *s
 {
 	const char *uid;
 	CamelMessageInfo *mi;
+	CamelMessageInfoBase *bi = (CamelMessageInfoBase*)info;
 
 	uid = camel_message_info_uid(info);
 	if (uid == NULL || uid[0] == 0) {
-		g_free(info->uid);
+
+		if (bi->uid_needs_free || bi->needs_free)
+			g_free(info->uid);
 		uid = info->uid = camel_folder_summary_next_uid_string(s);
+		bi->uid_needs_free = TRUE;
 	}
 
 	CAMEL_SUMMARY_LOCK(s, summary_lock);
@@ -762,8 +787,13 @@ summary_assign_uid(CamelFolderSummary *s
 		if (mi == info)
 			return 0;
 		d(printf ("Trying to insert message with clashing uid (%s).  new uid re-assigned", camel_message_info_uid(info)));
-		g_free(info->uid);
+
+
+		if (bi->uid_needs_free || bi->needs_free)
+			g_free(info->uid);
 		uid = info->uid = camel_folder_summary_next_uid_string(s);
+		bi->uid_needs_free = TRUE;
+
 		camel_message_info_set_flags(info, CAMEL_MESSAGE_FOLDER_FLAGGED, CAMEL_MESSAGE_FOLDER_FLAGGED);
 		CAMEL_SUMMARY_LOCK(s, summary_lock);
 	}
@@ -1302,12 +1332,26 @@ camel_folder_summary_encode_token(FILE *
 		if (token != -1) {
 			return camel_file_util_encode_uint32(out, token+1);
 		} else {
-			if (camel_file_util_encode_uint32(out, len+32) == -1)
-				return -1;
-			if (fwrite(str, len, 1, out) != 1)
+			int lena;
+
+			lena = len = strlen (str) + 1;
+
+			if (lena % G_MEM_ALIGN)
+				lena += G_MEM_ALIGN - (lena % G_MEM_ALIGN);
+
+			if (camel_file_util_encode_uint32(out, lena+32) == -1)
 				return -1;
+
+			if (fwrite (str, len, 1, out) == 1) {
+				if (lena > len) {
+					if (fwrite ("\0\0\0\0\0\0\0\0", lena-len, 1, out) == 1)
+						return 0;
+					else return -1;
+				}
+			}
 		}
 	}
+
 	return 0;
 }
 
@@ -1322,24 +1366,22 @@ camel_folder_summary_encode_token(FILE *
  * Returns %0 on success or %-1 on fail
  **/
 int
-camel_folder_summary_decode_token(FILE *in, char **str)
+camel_folder_summary_decode_token(CamelFolderSummary *s, char **str)
 {
 	char *ret;
 	guint32 len;
+	unsigned char *ptrchr = s->filepos;
 
 	io(printf("Decode token ...\n"));
-	
-	if (camel_file_util_decode_uint32(in, &len) == -1) {
-		io(printf ("Could not decode token from file"));
-		*str = NULL;
-		return -1;
-	}
+
+	ptrchr = camel_file_util_mmap_decode_uint32 ((unsigned char*)ptrchr, &len, FALSE);
 
 	if (len<32) {
+
 		if (len <= 0) {
 			ret = NULL;
 		} else if (len<= tokens_len) {
-			ret = g_strdup(tokens[len-1]);
+			ret = tokens[len-1];
 		} else {
 			io(printf ("Invalid token encountered: %d", len));
 			*str = NULL;
@@ -1350,17 +1392,17 @@ camel_folder_summary_decode_token(FILE *
 		*str = NULL;
 		return -1;
 	} else {
+
 		len -= 32;
-		ret = g_malloc(len+1);
-		if (len > 0 && fread(ret, len, 1, in) != 1) {
-			g_free(ret);
-			*str = NULL;
-			return -1;
-		}
-		ret[len]=0;
+
+		if (len != 0)
+			ret = (char*)ptrchr;
+		else ret = NULL;
+
+		ptrchr += len;
 	}
 
-	io(printf("Token = '%s'\n", ret));
+	s->filepos = ptrchr;
 
 	*str = ret;
 	return 0;
@@ -1390,42 +1432,45 @@ my_list_size(struct _node **list)
 }
 
 static int
-summary_header_load(CamelFolderSummary *s, FILE *in)
+summary_header_load(CamelFolderSummary *s)
 {
-	fseek(in, 0, SEEK_SET);
+	s->version = g_ntohl(get_unaligned_u32(s->filepos)); 
+	s->filepos += 4;
 
-	io(printf("Loading header\n"));
+	io(printf("Loading header %d", (s->version&0xff)));
 
-	if (camel_file_util_decode_fixed_int32(in, &s->version) == -1)
-		return -1;
-
-	/* Legacy version check, before version 12 we have no upgrade knowledge */
+	/* Legacy version check, before version 13 we have no upgrade knowledge */
 	if ((s->version > 0xff) && (s->version & 0xff) < 12) {
 		io(printf ("Summary header version mismatch"));
 		errno = EINVAL;
 		return -1;
 	}
 
-	if (!(s->version < 0x100 && s->version >= 13))
-		io(printf("Loading legacy summary\n"));
-	else
-		io(printf("loading new-format summary\n"));
-
-	/* legacy version */
-	if (camel_file_util_decode_fixed_int32(in, &s->flags) == -1
-	    || camel_file_util_decode_fixed_int32(in, &s->nextuid) == -1
-	    || camel_file_util_decode_time_t(in, &s->time) == -1
-	    || camel_file_util_decode_fixed_int32(in, &s->saved_count) == -1) {
+	/* Check for MMAPable file */
+	if (s->version != CAMEL_FOLDER_SUMMARY_VERSION) {
+		errno = EINVAL;
 		return -1;
 	}
 
-	/* version 13 */
-	if (s->version < 0x100 && s->version >= 13
-	    && (camel_file_util_decode_fixed_int32(in, &s->unread_count) == -1
-		|| camel_file_util_decode_fixed_int32(in, &s->deleted_count) == -1
-		|| camel_file_util_decode_fixed_int32(in, &s->junk_count) == -1)) {
-		return -1;
+	s->flags = g_ntohl(get_unaligned_u32(s->filepos)); 
+	s->filepos += 4;
+	s->nextuid = g_ntohl(get_unaligned_u32(s->filepos)); 
+	s->filepos += 4;
+	s->time = (time_t)g_ntohl(get_unaligned_u32(s->filepos)); 
+	s->filepos += 4;
+	s->saved_count = g_ntohl(get_unaligned_u32(s->filepos)); 
+	s->filepos += 4;
+
+
+	if (s->version < 0x100 && s->version >= 13) {
+		s->unread_count = g_ntohl(get_unaligned_u32(s->filepos)); 
+		s->filepos += 4;
+		s->deleted_count = g_ntohl(get_unaligned_u32(s->filepos)); 
+		s->filepos += 4;
+		s->junk_count = g_ntohl(get_unaligned_u32(s->filepos)); 
+		s->filepos += 4;
 	}
+     
 
 	return 0;
 }
@@ -1559,6 +1604,7 @@ summary_format_string (struct _camel_hea
 	const char *text;
 	
 	text = camel_header_raw_find (&h, name, NULL);
+
 	if (text) {
 		while (isspace ((unsigned) *text))
 			text++;
@@ -1588,8 +1634,9 @@ camel_folder_summary_content_info_new(Ca
 		s->content_info_chunks = e_memchunk_new(32, s->content_info_size);
 	ci = e_memchunk_alloc(s->content_info_chunks);
 	CAMEL_SUMMARY_UNLOCK(s, alloc_lock);
-
+	ci->needs_free = FALSE;
 	memset(ci, 0, s->content_info_size);
+
 	return ci;
 }
 
@@ -1608,6 +1655,8 @@ message_info_new_from_header(CamelFolder
 
 	mi = (CamelMessageInfoBase *)camel_message_info_new(s);
 
+	mi->needs_free = TRUE;
+
 	if ((content = camel_header_raw_find(&h, "Content-Type", NULL))
 	     && (ct = camel_content_type_decode(content))
 	     && (charset = camel_content_type_param(ct, "charset"))
@@ -1624,17 +1673,32 @@ message_info_new_from_header(CamelFolder
 
 	if (ct)
 		camel_content_type_unref(ct);
-	
-	mi->subject = camel_pstring_add (subject, TRUE);
-	mi->from = camel_pstring_add (from, TRUE);
-	mi->to = camel_pstring_add (to, TRUE);
-	mi->cc = camel_pstring_add (cc, TRUE);
-	mi->mlist = camel_pstring_add (mlist, TRUE);
-	
+
+	if (subject)
+		mi->subject = camel_pstring_add (subject, TRUE);
+	else mi->subject = NULL;
+
+	if (from)
+		mi->from = camel_pstring_add (from, TRUE);
+	else mi->from = NULL;
+
+	if (to)
+		mi->to = camel_pstring_add (to, TRUE);
+	else mi->to = NULL;
+
+	if (cc)
+		mi->cc = camel_pstring_add (cc, TRUE);
+	else mi->cc = NULL;
+
+	if (mlist)
+		mi->mlist = camel_pstring_add (mlist, TRUE);
+	else mi->mlist = NULL;
+
 	mi->user_flags = NULL;
 	mi->user_tags = NULL;
 	mi->date_sent = camel_header_decode_date(camel_header_raw_find(&h, "date", NULL), NULL);
 	received = camel_header_raw_find(&h, "received", NULL);
+
 	if (received)
 		received = strrchr(received, ';');
 	if (received)
@@ -1681,84 +1745,125 @@ message_info_new_from_header(CamelFolder
 	return (CamelMessageInfo *)mi;
 }
 
+
 static CamelMessageInfo *
-message_info_load(CamelFolderSummary *s, FILE *in)
+message_info_load(CamelFolderSummary *s)
 {
 	CamelMessageInfoBase *mi;
-	guint count;
-	int i;
-	char *subject, *from, *to, *cc, *mlist, *uid;
+	guint count, len;
+	unsigned char *ptrchr = s->filepos;
+	unsigned int i;
 
 	mi = (CamelMessageInfoBase *)camel_message_info_new(s);
 
+	mi->needs_free = FALSE;
+
 	io(printf("Loading message info\n"));
 
-	camel_file_util_decode_string(in, &uid);
-	camel_file_util_decode_uint32(in, &mi->flags);
-	camel_file_util_decode_uint32(in, &mi->size);
-	camel_file_util_decode_time_t(in, &mi->date_sent);
-	camel_file_util_decode_time_t(in, &mi->date_received);
-	camel_file_util_decode_string(in, &subject);
-	camel_file_util_decode_string(in, &from);
-	camel_file_util_decode_string(in, &to);
-	camel_file_util_decode_string(in, &cc);
-	camel_file_util_decode_string(in, &mlist);
-	
-	mi->uid = uid;
-	mi->subject = camel_pstring_add (subject, TRUE);
-	mi->from = camel_pstring_add (from, TRUE);
-	mi->to = camel_pstring_add (to, TRUE);
-	mi->cc = camel_pstring_add (cc, TRUE);
-	mi->mlist = camel_pstring_add (mlist, TRUE);
-	
+	ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &len, TRUE);
+	if (len) 
+		mi->uid = (char*)ptrchr;
+	ptrchr += len;
+
+	ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &mi->flags, FALSE);
+
+	ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &mi->size, FALSE);
+
+	ptrchr = camel_file_util_mmap_decode_time_t (ptrchr, &mi->date_sent);
+	ptrchr = camel_file_util_mmap_decode_time_t (ptrchr, &mi->date_received);
+
+	ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &len, TRUE);
+
+	if (len) 
+		mi->subject = (const char*)ptrchr;
+
+	ptrchr += len;
+	ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &len, TRUE);
+
+	if (len) 
+		mi->from = (const char*)ptrchr;
+	ptrchr += len;
+
+	ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &len, TRUE);
+
+	if (len) 
+		mi->to = (const char*)ptrchr;
+	ptrchr += len;
+
+	ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &len, TRUE);
+
+	if (len) 
+		mi->cc = (const char*)ptrchr;
+	ptrchr += len;
+
+	ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &len, TRUE);
+
+	if (len) 
+		mi->mlist = (const char*)ptrchr;
+	ptrchr += len;	
+
 	mi->content = NULL;
 
-	camel_file_util_decode_fixed_int32(in, &mi->message_id.id.part.hi);
-	camel_file_util_decode_fixed_int32(in, &mi->message_id.id.part.lo);
+	s->filepos = ptrchr;
+	mi->message_id.id.part.hi = g_ntohl(get_unaligned_u32(s->filepos)); 
+	s->filepos += 4;
+	mi->message_id.id.part.lo = g_ntohl(get_unaligned_u32(s->filepos)); 
+	s->filepos += 4;
 
-	if (camel_file_util_decode_uint32(in, &count) == -1 || count > 500)
-		goto error;
+	ptrchr = (unsigned char*) s->filepos;
+	ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &count, FALSE);
 
-	if (count > 0) {
-		mi->references = g_malloc(sizeof(*mi->references) + ((count-1) * sizeof(mi->references->references[0])));
-		mi->references->size = count;
-		for (i=0;i<count;i++) {
-			camel_file_util_decode_fixed_int32(in, &mi->references->references[i].id.part.hi);
-			camel_file_util_decode_fixed_int32(in, &mi->references->references[i].id.part.lo);
-		}
+	mi->references = g_malloc(sizeof(*mi->references) + ((count-1) * sizeof(mi->references->references[0])));
+	mi->references->size = count;
+	
+	s->filepos = ptrchr;
+
+	for (i=0;i<count;i++) {
+		mi->references->references[i].id.part.hi = g_ntohl(get_unaligned_u32(s->filepos)); 
+		s->filepos += 4;
+		mi->references->references[i].id.part.lo = g_ntohl(get_unaligned_u32(s->filepos));
+		s->filepos += 4;
 	}
 
-	if (camel_file_util_decode_uint32(in, &count) == -1 || count > 500)
-		goto error;
+	ptrchr = s->filepos;
+	ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &count, FALSE);
 
 	for (i=0;i<count;i++) {
-		char *name;
-		if (camel_file_util_decode_string(in, &name) == -1 || name == NULL)
-			goto error;
+		char *name = NULL;
+
+		ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &len, TRUE);
+		if (len) 
+			name = (char*) ptrchr;
+		ptrchr += len;
+
 		camel_flag_set(&mi->user_flags, name, TRUE);
-		g_free(name);
 	}
 
-	if (camel_file_util_decode_uint32(in, &count) == -1 || count > 500)
-		goto error;
+	ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &count, FALSE);
+	if (!ptrchr) return NULL;
 
 	for (i=0;i<count;i++) {
-		char *name, *value;
-		if (camel_file_util_decode_string(in, &name) == -1 || name == NULL
-		    || camel_file_util_decode_string(in, &value) == -1)
-			goto error;
+		char *name = NULL, *value = NULL;
+
+		ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &len, TRUE);
+
+		if (len) 
+			name = (char*)ptrchr;
+		ptrchr += len;
+		ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &len, TRUE);
+
+		if (len) 
+			value =(char*) ptrchr;
+		ptrchr += len;
+
 		camel_tag_set(&mi->user_tags, name, value);
-		g_free(name);
-		g_free(value);
 	}
 
-	if (!ferror(in))
-		return (CamelMessageInfo *)mi;
 
-error:
-	camel_message_info_free((CamelMessageInfo *)mi);
+	s->filepos = ptrchr;
+
+	return (CamelMessageInfo *)mi;
 
-	return NULL;
 }
 
 static int
@@ -1821,15 +1926,32 @@ message_info_free(CamelFolderSummary *s,
 {
 	CamelMessageInfoBase *mi = (CamelMessageInfoBase *)info;
 
-	g_free(mi->uid);
-	camel_pstring_free(mi->subject);
-	camel_pstring_free(mi->from);
-	camel_pstring_free(mi->to);
-	camel_pstring_free(mi->cc);
-	camel_pstring_free(mi->mlist);
+	if (mi->needs_free) {
+		g_free(mi->uid);
+
+		if (mi->subject)
+			camel_pstring_free(mi->subject);
+
+		if (mi->from)
+			camel_pstring_free(mi->from);
+
+		if (mi->to)
+			camel_pstring_free(mi->to);
+		
+		if (mi->cc)
+			camel_pstring_free(mi->cc);
+
+		if (mi->mlist)
+			camel_pstring_free(mi->mlist);
+
+		camel_flag_list_free(&mi->user_flags);
+		camel_tag_list_free(&mi->user_tags);
+
+	} else if (mi->uid_needs_free)
+		g_free (mi->uid);
+
 	g_free(mi->references);
-	camel_flag_list_free(&mi->user_flags);
-	camel_tag_list_free(&mi->user_tags);
+
 	if (s)
 		e_memchunk_free(s->message_info_chunks, mi);
 	else
@@ -1843,8 +1965,10 @@ content_info_new_from_header(CamelFolder
 	const char *charset;
 	
 	ci = camel_folder_summary_content_info_new (s);
+	ci->needs_free = TRUE;
 	
 	charset = e_iconv_locale_charset ();
+
 	ci->id = camel_header_msgid_decode (camel_header_raw_find (&h, "content-id", NULL));
 	ci->description = camel_header_decode_string (camel_header_raw_find (&h, "content-description", NULL), charset);
 	ci->encoding = camel_content_transfer_encoding_decode (camel_header_raw_find (&h, "content-transfer-encoding", NULL));
@@ -1854,64 +1978,63 @@ content_info_new_from_header(CamelFolder
 }
 
 static CamelMessageContentInfo *
-content_info_load(CamelFolderSummary *s, FILE *in)
+content_info_load(CamelFolderSummary *s)
 {
 	CamelMessageContentInfo *ci;
 	char *type, *subtype;
 	guint32 count, i;
 	CamelContentType *ct;
 
+	unsigned char *ptrchr = s->filepos;
+
 	io(printf("Loading content info\n"));
 
 	ci = camel_folder_summary_content_info_new(s);
-	
-	camel_folder_summary_decode_token(in, &type);
-	camel_folder_summary_decode_token(in, &subtype);
+	ci->needs_free = FALSE;
+
+	camel_folder_summary_decode_token(s, &type);
+	camel_folder_summary_decode_token(s, &subtype);
+
 	ct = camel_content_type_new(type, subtype);
-	g_free(type);		/* can this be removed? */
-	g_free(subtype);
-	if (camel_file_util_decode_uint32(in, &count) == -1 || count > 500)
-		goto error;
+
+	ptrchr = s->filepos;
+	ptrchr = camel_file_util_mmap_decode_uint32 ((unsigned char*)ptrchr, &count, FALSE);	
+	s->filepos = ptrchr;
 	
 	for (i=0;i<count;i++) {
 		char *name, *value;
-		camel_folder_summary_decode_token(in, &name);
-		camel_folder_summary_decode_token(in, &value);
-		if (!(name && value))
-			goto error;
+
+		camel_folder_summary_decode_token(s, &name);
+		camel_folder_summary_decode_token(s, &value);
 		
-		camel_content_type_set_param(ct, name, value);
-		/* TODO: do this so we dont have to double alloc/free */
-		g_free(name);
-		g_free(value);
+		camel_content_type_set_param (ct, name, value);
 	}
-	ci->type = ct;
 
-	camel_folder_summary_decode_token(in, &ci->id);
-	camel_folder_summary_decode_token(in, &ci->description);
-	camel_folder_summary_decode_token(in, &ci->encoding);
+	ci->type = ct;
 
-	camel_file_util_decode_uint32(in, &ci->size);
+	camel_folder_summary_decode_token(s, &ci->id);
+	camel_folder_summary_decode_token(s, &ci->description);
+	camel_folder_summary_decode_token(s, &ci->encoding);
+
+	ptrchr = s->filepos;
+	ptrchr = camel_file_util_mmap_decode_uint32 ((unsigned char*)ptrchr, &ci->size, FALSE);
+	s->filepos = ptrchr;
 
 	ci->childs = NULL;
 
-	if (!ferror(in))
-		return ci;
-
- error:
-	camel_folder_summary_content_info_free(s, ci);
-	return NULL;
+	return ci;
 }
 
 static int
 content_info_save(CamelFolderSummary *s, FILE *out, CamelMessageContentInfo *ci)
 {
-	CamelContentType *ct;
+	CamelContentType *ct=NULL;
 	struct _camel_header_param *hp;
 
 	io(printf("Saving content info\n"));
 
 	ct = ci->type;
+
 	if (ct) {
 		camel_folder_summary_encode_token(out, ct->type);
 		camel_folder_summary_encode_token(out, ct->subtype);
@@ -1937,9 +2060,13 @@ static void
 content_info_free(CamelFolderSummary *s, CamelMessageContentInfo *ci)
 {
 	camel_content_type_unref(ci->type);
-	g_free(ci->id);
-	g_free(ci->description);
-	g_free(ci->encoding);
+
+	if (ci->needs_free) {
+		g_free (ci->id);
+		g_free (ci->description);
+		g_free (ci->encoding);
+	}
+
 	e_memchunk_free(s->content_info_chunks, ci);
 }
 
@@ -2693,6 +2820,8 @@ message_info_clone(CamelFolderSummary *s
 	to->refcount = 1;
 
 	/* NB: We don't clone the uid */
+
+	from->needs_free = TRUE;
 
 	to->subject = camel_pstring_strdup(from->subject);
 	to->from = camel_pstring_strdup(from->from);
Index: camel/camel-folder-summary.h
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-folder-summary.h,v
retrieving revision 1.86
diff -p -u -r1.86 camel-folder-summary.h
--- camel/camel-folder-summary.h	31 Aug 2005 04:21:56 -0000	1.86
+++ camel/camel-folder-summary.h	18 Jul 2006 22:48:53 -0000
@@ -33,6 +33,7 @@ extern "C" {
 #include <camel/camel-object.h>
 #include <camel/camel-index.h>
 
+
 struct _CamelFolder;
 
 #define CAMEL_FOLDER_SUMMARY_TYPE         camel_folder_summary_get_type ()
@@ -59,6 +60,7 @@ struct _CamelMessageContentInfo {
 	char *description;
 	char *encoding;		/* this should be an enum?? */
 	guint32 size;
+	gboolean needs_free;
 };
 
 /* system flag bits */
@@ -178,6 +180,7 @@ struct _CamelMessageInfoBase {
 
 	/* tree of content description - NULL if it is not available */
 	CamelMessageContentInfo *content;
+	gboolean needs_free, uid_needs_free;
 };
 
 /* probably do this as well, removing CamelFolderChangeInfo and interfaces 
@@ -224,20 +227,23 @@ struct _CamelFolderSummary {
 	GHashTable *messages_uid; /* CamelMessageInfo's by uid */
 
 	struct _CamelFolder *folder; /* parent folder, for events */
+
+	GMappedFile *file;
+	unsigned char *filepos;
 };
 
 struct _CamelFolderSummaryClass {
 	CamelObjectClass parent_class;
 
 	/* load/save the global info */
-	int (*summary_header_load)(CamelFolderSummary *, FILE *);
+	int (*summary_header_load)(CamelFolderSummary *);
 	int (*summary_header_save)(CamelFolderSummary *, FILE *);
 
 	/* create/save/load an individual message info */
 	CamelMessageInfo * (*message_info_new_from_header)(CamelFolderSummary *, struct _camel_header_raw *);
 	CamelMessageInfo * (*message_info_new_from_parser)(CamelFolderSummary *, CamelMimeParser *);
 	CamelMessageInfo * (*message_info_new_from_message)(CamelFolderSummary *, CamelMimeMessage *);
-	CamelMessageInfo * (*message_info_load)(CamelFolderSummary *, FILE *);
+	CamelMessageInfo * (*message_info_load)(CamelFolderSummary *);
 	int		   (*message_info_save)(CamelFolderSummary *, FILE *, CamelMessageInfo *);
 
 	void		   (*message_info_free)(CamelFolderSummary *, CamelMessageInfo *);
@@ -247,7 +253,7 @@ struct _CamelFolderSummaryClass {
 	CamelMessageContentInfo * (*content_info_new_from_header)(CamelFolderSummary *, struct _camel_header_raw *);
 	CamelMessageContentInfo * (*content_info_new_from_parser)(CamelFolderSummary *, CamelMimeParser *);
 	CamelMessageContentInfo * (*content_info_new_from_message)(CamelFolderSummary *, CamelMimePart *);
-	CamelMessageContentInfo * (*content_info_load)(CamelFolderSummary *, FILE *);
+	CamelMessageContentInfo * (*content_info_load)(CamelFolderSummary *);
 	int		          (*content_info_save)(CamelFolderSummary *, FILE *, CamelMessageContentInfo *);
 	void		          (*content_info_free)(CamelFolderSummary *, CamelMessageContentInfo *);
 
@@ -277,6 +283,9 @@ struct _CamelFolderSummaryClass {
 CamelType			 camel_folder_summary_get_type	(void);
 CamelFolderSummary      *camel_folder_summary_new	(struct _CamelFolder *folder);
 
+unsigned char*
+decode_uint32 (unsigned char *start, guint32 *dest, gboolean is_string);
+
 void camel_folder_summary_set_filename(CamelFolderSummary *summary, const char *filename);
 void camel_folder_summary_set_index(CamelFolderSummary *summary, CamelIndex *index);
 void camel_folder_summary_set_build_content(CamelFolderSummary *summary, gboolean state);
@@ -329,7 +338,7 @@ void camel_folder_summary_array_free(Cam
 
 /* basically like strings, but certain keywords can be compressed and de-cased */
 int camel_folder_summary_encode_token(FILE *out, const char *str);
-int camel_folder_summary_decode_token(FILE *in, char **str);
+int camel_folder_summary_decode_token(CamelFolderSummary *s, char **str);
 
 /* message flag operations */
 gboolean	camel_flag_get(CamelFlag **list, const char *name);
Index: camel/camel-object.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-object.c,v
retrieving revision 1.60
diff -p -u -r1.60 camel-object.c
--- camel/camel-object.c	12 Apr 2006 19:14:13 -0000	1.60
+++ camel/camel-object.c	18 Jul 2006 22:48:56 -0000
@@ -580,7 +580,7 @@ cobject_state_write(CamelObject *obj, FI
 
 	res = 0;
 abort:
-	for (i=0;i<argv->argc;i++) {
+/*	for (i=0;i<argv->argc;i++) {
 		CamelArg *arg = &argv->argv[i];
 
 		if ((argv->argv[i].tag & CAMEL_ARG_TYPE) == CAMEL_ARG_STR)
@@ -595,7 +595,7 @@ abort:
 
 	if (meta)
 		camel_object_free(obj, CAMEL_OBJECT_METADATA, meta);
-
+*/
 	return res;
 }
 
Index: camel/providers/groupwise/camel-groupwise-folder.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/groupwise/camel-groupwise-folder.c,v
retrieving revision 1.140
diff -p -u -r1.140 camel-groupwise-folder.c
--- camel/providers/groupwise/camel-groupwise-folder.c	5 Jul 2006 10:03:16 -0000	1.140
+++ camel/providers/groupwise/camel-groupwise-folder.c	18 Jul 2006 22:49:00 -0000
@@ -744,7 +744,7 @@ camel_gw_folder_new(CamelStore *store, c
 		short_name = (char *) folder_name;
 	camel_folder_construct (folder, store, folder_name, short_name);
 
-	summary_file = g_strdup_printf ("%s/summary",folder_dir);
+	summary_file = g_strdup_printf ("%s/summary.mmap",folder_dir);
 	folder->summary = camel_groupwise_summary_new(folder, summary_file);
 	g_free(summary_file);
 	if (!folder->summary) {
Index: camel/providers/groupwise/camel-groupwise-summary.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/groupwise/camel-groupwise-summary.c,v
retrieving revision 1.11
diff -p -u -r1.11 camel-groupwise-summary.c
--- camel/providers/groupwise/camel-groupwise-summary.c	20 Apr 2006 07:47:21 -0000	1.11
+++ camel/providers/groupwise/camel-groupwise-summary.c	18 Jul 2006 22:49:00 -0000
@@ -42,10 +42,10 @@
 #define CAMEL_GW_SUMMARY_VERSION (1)
 
 /*Prototypes*/
-static int gw_summary_header_load (CamelFolderSummary *, FILE *);
+static int gw_summary_header_load (CamelFolderSummary *);
 static int gw_summary_header_save (CamelFolderSummary *, FILE *);
 
-static CamelMessageInfo *gw_message_info_load (CamelFolderSummary *s, FILE *in) ;
+static CamelMessageInfo *gw_message_info_load (CamelFolderSummary *s) ;
 
 static int gw_message_info_save (CamelFolderSummary *s, FILE *out, CamelMessageInfo *info) ;
 static CamelMessageContentInfo * gw_content_info_load (CamelFolderSummary *s, FILE *in) ;
@@ -153,19 +153,27 @@ camel_groupwise_summary_new (struct _Cam
 }
 
 static int
-gw_summary_header_load (CamelFolderSummary *s, FILE *in)
+gw_summary_header_load (CamelFolderSummary *s)
 {
 	CamelGroupwiseSummary *ims = CAMEL_GROUPWISE_SUMMARY (s);
+	unsigned char *ptrchr;
+	gint len;
 
-	if (camel_groupwise_summary_parent->summary_header_load (s, in) == -1)
+	if (camel_groupwise_summary_parent->summary_header_load (s) == -1)
 		return -1 ;
 
-	if (camel_file_util_decode_fixed_int32(in, &ims->version) == -1
-			|| camel_file_util_decode_fixed_int32(in, &ims->validity) == -1)
-		return -1;
-	
-	if (camel_file_util_decode_string (in, &ims->time_string) == -1)
-		return -1;
+	ims->version = g_ntohl(get_unaligned_u32(s->filepos));
+	s->filepos += 4;
+	ims->validity = g_ntohl(get_unaligned_u32(s->filepos));
+	s->filepos += 4;
+
+	ptrchr = s->filepos;
+	ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &len, TRUE);
+	if (len) 
+		ims->time_string = ptrchr;
+	ptrchr += len;		
+	s->filepos = ptrchr;
+
 	return 0 ;
 }
 
@@ -186,23 +194,21 @@ gw_summary_header_save (CamelFolderSumma
 }
 
 static CamelMessageInfo *
-gw_message_info_load (CamelFolderSummary *s, FILE *in)
+gw_message_info_load (CamelFolderSummary *s)
 {
 	CamelMessageInfo *info ;
 	CamelGroupwiseMessageInfo *gw_info ;
 
-
-	info = camel_groupwise_summary_parent->message_info_load(s,in) ;
+	info = camel_groupwise_summary_parent->message_info_load(s) ;
 	if (info) {
+		unsigned char *ptrchr = s->filepos;
 		gw_info = (CamelGroupwiseMessageInfo*) info ;
-		if (camel_file_util_decode_uint32 (in, &gw_info->server_flags) == -1)
-			goto error ;
+
+		ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &gw_info->server_flags, FALSE);
+		s->filepos = ptrchr;
 	}
 
 	return info ;
-error:
-	camel_message_info_free (info) ;
-	return NULL ;
 }
 
 
@@ -220,9 +226,15 @@ gw_message_info_save (CamelFolderSummary
 
 static CamelMessageContentInfo *
 gw_content_info_load (CamelFolderSummary *s, FILE *in)
-{       
-	if (fgetc (in))
-		return camel_groupwise_summary_parent->content_info_load (s, in);
+{      
+	int yes=0;
+
+	unsigned char *ptrchr = s->filepos;
+	ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &yes, FALSE);
+	s->filepos = ptrchr;
+
+	if (yes == 1)
+		return camel_groupwise_summary_parent->content_info_load (s);
 	else
 		return camel_folder_summary_content_info_new (s);
 }
@@ -309,6 +321,7 @@ camel_gw_summary_add_offline (CamelFolde
 
 	mi->info.size = camel_message_info_size(info);
 	mi->info.uid = g_strdup (uid);
+	mi->info.uid_needs_free = TRUE;
 
 	camel_folder_summary_add (summary, (CamelMessageInfo *)mi);
 
@@ -321,6 +334,8 @@ camel_gw_summary_add_offline_uncached (C
 
 	mi = camel_message_info_clone(info);
 	mi->info.uid = g_strdup(uid);
+	mi->info.uid_needs_free = TRUE;
+
 	camel_folder_summary_add (summary, (CamelMessageInfo *)mi);
 }
 
Index: camel/providers/imap/camel-imap-folder.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/imap/camel-imap-folder.c,v
retrieving revision 1.361
diff -p -u -r1.361 camel-imap-folder.c
--- camel/providers/imap/camel-imap-folder.c	19 May 2006 15:25:08 -0000	1.361
+++ camel/providers/imap/camel-imap-folder.c	18 Jul 2006 22:49:04 -0000
@@ -238,7 +238,7 @@ camel_imap_folder_new (CamelStore *paren
 		short_name = folder_name;
 	camel_folder_construct (folder, parent, folder_name, short_name);
 
-	summary_file = g_strdup_printf ("%s/summary", folder_dir);
+	summary_file = g_strdup_printf ("%s/summary.mmap", folder_dir);
 	folder->summary = camel_imap_summary_new (folder, summary_file);
 	g_free (summary_file);
 	if (!folder->summary) {
@@ -2296,6 +2296,7 @@ add_message_from_data (CamelFolder *fold
 	}
 	
 	mi = (CamelImapMessageInfo *)camel_folder_summary_info_new_from_message (folder->summary, msg);
+	
 	camel_object_unref (CAMEL_OBJECT (msg));
 	
 	if ((idate = g_datalist_get_data (&data, "INTERNALDATE")))
@@ -2511,8 +2512,11 @@ imap_update_summary (CamelFolder *folder
 		}
 		
 		uid = g_datalist_get_data (&data, "UID");
+
+		/* This strdup() might not get freed since the mmap() patch! */
 		if (uid)
 			mi->info.uid = g_strdup (uid);
+
 		flags = GPOINTER_TO_INT (g_datalist_get_data (&data, "FLAGS"));
 		if (flags) {
 			((CamelImapMessageInfo *)mi)->server_flags = flags;
Index: camel/providers/imap/camel-imap-store-summary.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/imap/camel-imap-store-summary.c,v
retrieving revision 1.18
diff -p -u -r1.18 camel-imap-store-summary.c
--- camel/providers/imap/camel-imap-store-summary.c	12 Apr 2006 19:14:14 -0000	1.18
+++ camel/providers/imap/camel-imap-store-summary.c	18 Jul 2006 22:49:05 -0000
@@ -469,27 +469,44 @@ namespace_load(CamelStoreSummary *s, FIL
 	guint32 sep = '/';
 
 	ns = g_malloc0(sizeof(*ns));
-	if (camel_file_util_decode_string(in, &ns->path) == -1
-	    || camel_file_util_decode_string(in, &ns->full_name) == -1
-	    || camel_file_util_decode_uint32(in, &sep) == -1) {
-		namespace_free(s, ns);
-		ns = NULL;
-	} else {
-		ns->sep = sep;
-	}
+
+	if (camel_file_util_decode_string(in, &ns->path) == -1)
+		goto nserror;
+
+	if (camel_file_util_decode_string(in, &ns->full_name) == -1)
+		goto nserror;
+	
+	if (camel_file_util_decode_uint32(in, &sep) == -1)
+		goto nserror;
+
+	ns->sep = sep;
 
 	return ns;
+
+ nserror:
+
+	namespace_free(s, ns);
+	return NULL;
 }
 
 static int
 namespace_save(CamelStoreSummary *s, FILE *in, CamelImapStoreNamespace *ns)
 {
-	if (camel_file_util_encode_string(in, ns->path) == -1
-	    || camel_file_util_encode_string(in, ns->full_name) == -1
-	    || camel_file_util_encode_uint32(in, (guint32)ns->sep) == -1)
-		return -1;
+	if (camel_file_util_encode_string(in, ns->path) == -1)
+		goto serr;
+
+	if (camel_file_util_encode_string(in, ns->full_name) == -1)
+		goto serr;
+
+	if (camel_file_util_encode_uint32(in, (guint32)ns->sep) == -1)
+		goto serr;
 
 	return 0;
+
+ serr:
+	printf ("Error happend while writing\n");
+	return -1;
+
 }
 
 static int
Index: camel/providers/imap/camel-imap-summary.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/imap/camel-imap-summary.c,v
retrieving revision 1.25
diff -p -u -r1.25 camel-imap-summary.c
--- camel/providers/imap/camel-imap-summary.c	31 Aug 2005 04:26:02 -0000	1.25
+++ camel/providers/imap/camel-imap-summary.c	18 Jul 2006 22:49:05 -0000
@@ -37,14 +37,14 @@
 
 #define CAMEL_IMAP_SUMMARY_VERSION (3)
 
-static int summary_header_load (CamelFolderSummary *, FILE *);
+static int summary_header_load (CamelFolderSummary *);
 static int summary_header_save (CamelFolderSummary *, FILE *);
 
-static CamelMessageInfo *message_info_load (CamelFolderSummary *s, FILE *in);
+static CamelMessageInfo *message_info_load (CamelFolderSummary *s);
 static int message_info_save (CamelFolderSummary *s, FILE *out,
 			      CamelMessageInfo *info);
 static gboolean info_set_user_tag(CamelMessageInfo *info, const char *name, const char  *value);
-static CamelMessageContentInfo *content_info_load (CamelFolderSummary *s, FILE *in);
+static CamelMessageContentInfo *content_info_load (CamelFolderSummary *s);
 static int content_info_save (CamelFolderSummary *s, FILE *out,
 			      CamelMessageContentInfo *info);
 
@@ -145,31 +145,31 @@ camel_imap_summary_new (struct _CamelFol
 }
 
 static int
-summary_header_load (CamelFolderSummary *s, FILE *in)
+summary_header_load (CamelFolderSummary *s)
 {
 	CamelImapSummary *ims = CAMEL_IMAP_SUMMARY (s);
 	
-	if (camel_imap_summary_parent->summary_header_load (s, in) == -1)
+	if (camel_imap_summary_parent->summary_header_load (s) == -1)
 		return -1;
 
 	/* Legacy version */
-	if (s->version == 0x30c)
-		return camel_file_util_decode_uint32(in, &ims->validity);
+	if (s->version == 0x30c) {
+		unsigned char* ptrchr = s->filepos;
+		ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &ims->validity, FALSE);
+		s->filepos = ptrchr;
+		return 0;
+	}
 
 	/* Version 1 */
-	if (camel_file_util_decode_fixed_int32(in, &ims->version) == -1)
-		return -1;
+	ims->version = g_ntohl(get_unaligned_u32(s->filepos)); s->filepos += 4;
 	
 	if (ims->version == 2) {
 		/* Version 2: for compat with version 2 of the imap4 summary files */
 		int have_mlist;
-		
-		if (camel_file_util_decode_fixed_int32 (in, &have_mlist) == -1)
-			return -1;
+		have_mlist = g_ntohl(get_unaligned_u32(s->filepos)); s->filepos += 4;
 	}
-	
-	if (camel_file_util_decode_fixed_int32(in, &ims->validity) == -1)
-		return -1;
+
+	ims->validity = g_ntohl(get_unaligned_u32(s->filepos)); s->filepos += 4;
 	
 	if (ims->version > CAMEL_IMAP_SUMMARY_VERSION) {
 		g_warning("Unkown summary version\n");
@@ -206,25 +206,22 @@ label_to_flags(CamelImapMessageInfo *inf
 }
 
 static CamelMessageInfo *
-message_info_load (CamelFolderSummary *s, FILE *in)
+message_info_load (CamelFolderSummary *s)
 {
 	CamelMessageInfo *info;
 	CamelImapMessageInfo *iinfo;
 
-	info = camel_imap_summary_parent->message_info_load (s, in);
-	if (info) {
-		iinfo = (CamelImapMessageInfo *)info;
-
-		if (camel_file_util_decode_uint32 (in, &iinfo->server_flags) == -1)
-			goto error;
+	info = camel_imap_summary_parent->message_info_load (s);
+	iinfo = (CamelImapMessageInfo*)info;
 
+	if (info) {
+		unsigned char* ptrchr = s->filepos;
+		ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &iinfo->server_flags, FALSE);
+		s->filepos = ptrchr;
 		label_to_flags(iinfo);
 	}
 
 	return info;
-error:
-	camel_message_info_free(info);
-	return NULL;
 }
 
 static int
@@ -252,10 +249,16 @@ info_set_user_tag(CamelMessageInfo *info
 }
 
 static CamelMessageContentInfo *
-content_info_load (CamelFolderSummary *s, FILE *in)
+content_info_load (CamelFolderSummary *s)
 {
-	if (fgetc (in))
-		return camel_imap_summary_parent->content_info_load (s, in);
+	guint32 doit;
+	unsigned char* ptrchr = s->filepos;
+
+	ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &doit, FALSE);
+	s->filepos = ptrchr;
+
+	if (doit == 1)
+		return camel_imap_summary_parent->content_info_load (s);
 	else
 		return camel_folder_summary_content_info_new (s);
 }
@@ -265,10 +268,10 @@ content_info_save (CamelFolderSummary *s
 		   CamelMessageContentInfo *info)
 {
 	if (info->type) {
-		fputc (1, out);
+		camel_file_util_encode_uint32 (out, 1);
 		return camel_imap_summary_parent->content_info_save (s, out, info);
 	} else
-		return fputc (0, out);
+		return camel_file_util_encode_uint32 (out, 0);
 }
 
 void
@@ -298,6 +301,8 @@ camel_imap_summary_add_offline (CamelFol
 	}
 
 	mi->info.size = camel_message_info_size(info);
+
+	mi->info.uid_needs_free = TRUE;
 	mi->info.uid = g_strdup (uid);
 
 	label_to_flags(mi);
@@ -312,7 +317,9 @@ camel_imap_summary_add_offline_uncached 
 	CamelImapMessageInfo *mi;
 
 	mi = camel_message_info_clone(info);
+
 	mi->info.uid = g_strdup(uid);
+	mi->info.uid_needs_free = TRUE;
 
 	label_to_flags(mi);
 
Index: camel/providers/imap4/camel-imap4-folder.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/imap4/camel-imap4-folder.c,v
retrieving revision 1.50
diff -p -u -r1.50 camel-imap4-folder.c
--- camel/providers/imap4/camel-imap4-folder.c	15 Jun 2006 16:41:58 -0000	1.50
+++ camel/providers/imap4/camel-imap4-folder.c	18 Jul 2006 22:49:07 -0000
@@ -241,7 +241,7 @@ static char *
 imap4_get_summary_filename (const char *path)
 {
 	/* /path/to/imap/summary */
-	return g_build_filename (path, "summary", NULL);
+	return g_build_filename (path, "summary.mmap", NULL);
 }
 
 static char *
Index: camel/providers/imap4/camel-imap4-summary.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/imap4/camel-imap4-summary.c,v
retrieving revision 1.46
diff -p -u -r1.46 camel-imap4-summary.c
--- camel/providers/imap4/camel-imap4-summary.c	18 May 2006 15:28:10 -0000	1.46
+++ camel/providers/imap4/camel-imap4-summary.c	18 Jul 2006 22:49:09 -0000
@@ -58,13 +58,13 @@ static void camel_imap4_summary_class_in
 static void camel_imap4_summary_init (CamelIMAP4Summary *summary, CamelIMAP4SummaryClass *klass);
 static void camel_imap4_summary_finalize (CamelObject *object);
 
-static int imap4_header_load (CamelFolderSummary *summary, FILE *fin);
+static int imap4_header_load (CamelFolderSummary *summary);
 static int imap4_header_save (CamelFolderSummary *summary, FILE *fout);
 static CamelMessageInfo *imap4_message_info_new_from_header (CamelFolderSummary *summary, struct _camel_header_raw *header);
-static CamelMessageInfo *imap4_message_info_load (CamelFolderSummary *summary, FILE *fin);
+static CamelMessageInfo *imap4_message_info_load (CamelFolderSummary *summary);
 static int imap4_message_info_save (CamelFolderSummary *summary, FILE *fout, CamelMessageInfo *info);
 static CamelMessageInfo *imap4_message_info_clone (CamelFolderSummary *summary, const CamelMessageInfo *mi);
-static CamelMessageContentInfo *imap4_content_info_load (CamelFolderSummary *summary, FILE *in);
+static CamelMessageContentInfo *imap4_content_info_load (CamelFolderSummary *summary);
 static int imap4_content_info_save (CamelFolderSummary *summary, FILE *out, CamelMessageContentInfo *info);
 
 static CamelFolderSummaryClass *parent_class = NULL;
@@ -127,7 +127,7 @@ camel_imap4_summary_init (CamelIMAP4Summ
 static void
 camel_imap4_summary_finalize (CamelObject *object)
 {
-	;
+	return;
 }
 
 
@@ -143,16 +143,16 @@ camel_imap4_summary_new (CamelFolder *fo
 }
 
 static int
-imap4_header_load (CamelFolderSummary *summary, FILE *fin)
+imap4_header_load (CamelFolderSummary *summary)
 {
 	CamelIMAP4Summary *imap4_summary = (CamelIMAP4Summary *) summary;
 	
-	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_load (summary, fin) == -1)
-		return -1;
-	
-	if (camel_file_util_decode_fixed_int32 (fin, &imap4_summary->version) == -1)
+	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_load (summary) == -1)
 		return -1;
 	
+	imap4_summary->version = g_ntohl(get_unaligned_u32(summary->filepos)); 
+	summary->filepos += 4;
+
 	if (imap4_summary->version > CAMEL_IMAP4_SUMMARY_VERSION) {
 		g_warning ("Unknown IMAP4 summary version\n");
 		errno = EINVAL;
@@ -162,9 +162,9 @@ imap4_header_load (CamelFolderSummary *s
 	if (imap4_summary->version == 2) {
 		/* check that we have Mailing-List info */
 		int have_mlist;
-		
-		if (camel_file_util_decode_fixed_int32 (fin, &have_mlist) == -1)
-			return -1;
+
+		have_mlist = g_ntohl(get_unaligned_u32(summary->filepos)); 
+		summary->filepos += 4;
 		
 		if (have_mlist)
 			summary->flags |= CAMEL_IMAP4_SUMMARY_HAVE_MLIST;
@@ -172,8 +172,8 @@ imap4_header_load (CamelFolderSummary *s
 			summary->flags ^= CAMEL_IMAP4_SUMMARY_HAVE_MLIST;
 	}
 	
-	if (camel_file_util_decode_fixed_int32 (fin, &imap4_summary->uidvalidity) == -1)
-		return -1;
+	imap4_summary->uidvalidity = g_ntohl(get_unaligned_u32(summary->filepos)); 
+	summary->filepos += 4;
 	
 	return 0;
 }
@@ -492,6 +492,9 @@ decode_envelope (CamelIMAP4Engine *engin
 	/* subject */
 	if (envelope_decode_nstring (engine, &nstring, TRUE, ex) == -1)
 		goto exception;
+
+	iinfo->info.needs_free = TRUE;
+
 	iinfo->info.subject = camel_pstring_strdup (nstring);
 	g_free(nstring);
 	
@@ -992,8 +995,11 @@ untagged_fetch_all (CamelIMAP4Engine *en
 					g_assert_not_reached ();
 				}
 			} else {
-				g_free (info->uid);
+				if (((CamelMessageInfoBase*)info)->uid_needs_free)
+					g_free (info->uid);
 				info->uid = g_strdup (uid);
+				((CamelMessageInfoBase*)info)->uid_needs_free = TRUE;
+
 				g_hash_table_insert (fetch->uid_hash, (void *) camel_message_info_uid (info), envelope);
 				changed |= IMAP4_FETCH_UID;
 			}
@@ -1063,9 +1069,12 @@ untagged_fetch_all (CamelIMAP4Engine *en
 				h = camel_mime_parser_headers_raw (parser);
 				
 				/* find our mailing-list header */
-				mlist = camel_header_raw_check_mailing_list (&h);
-				iinfo->info.mlist = camel_pstring_strdup (mlist);
-				g_free (mlist);
+
+				/* This introduces a problem for the mmap() implementation */
+
+				// mlist = camel_header_raw_check_mailing_list (&h);
+				// iinfo->info.mlist = camel_pstring_strdup (mlist);
+				// g_free (mlist);
 				
 				/* check if we possibly have attachments */
 				if ((str = camel_header_raw_find (&h, "Content-Type", NULL))) {
@@ -1245,26 +1254,21 @@ imap4_message_info_new_from_header (Came
 }
 
 static CamelMessageInfo *
-imap4_message_info_load (CamelFolderSummary *summary, FILE *fin)
+imap4_message_info_load (CamelFolderSummary *summary)
 {
 	CamelIMAP4MessageInfo *minfo;
 	CamelMessageInfo *info;
-	
-	if (!(info = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_load (summary, fin)))
+	unsigned char *ptrchr = summary->filepos;
+
+	if (!(info = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_load (summary)))
 		return NULL;
 	
 	minfo = (CamelIMAP4MessageInfo *) info;
 	
-	if (camel_file_util_decode_uint32 (fin, &minfo->server_flags) == -1)
-		goto exception;
-	
+	ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &minfo->server_flags, FALSE);
+	summary->filepos = ptrchr;
+
 	return info;
-	
- exception:
-	
-	camel_message_info_free(info);
-	
-	return NULL;
 }
 
 static int
@@ -1297,10 +1301,16 @@ imap4_message_info_clone (CamelFolderSum
 }
 
 static CamelMessageContentInfo *
-imap4_content_info_load (CamelFolderSummary *summary, FILE *in)
+imap4_content_info_load (CamelFolderSummary *summary)
 {
-	if (fgetc (in))
-		return CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->content_info_load (summary, in);
+	guint32 doit;
+	unsigned char* ptrchr = summary->filepos;
+
+	ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &doit, FALSE);
+	summary->filepos = ptrchr;
+
+	if (doit == 1)
+		return CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->content_info_load (summary);
 	else
 		return camel_folder_summary_content_info_new (summary);
 }
Index: camel/providers/imapp/camel-imapp-folder.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/imapp/camel-imapp-folder.c,v
retrieving revision 1.7
diff -p -u -r1.7 camel-imapp-folder.c
--- camel/providers/imapp/camel-imapp-folder.c	10 Jan 2006 07:56:48 -0000	1.7
+++ camel/providers/imapp/camel-imapp-folder.c	18 Jul 2006 22:49:10 -0000
@@ -133,7 +133,7 @@ camel_imapp_folder_new(CamelStore *store
 	root = camel_session_get_storage_path(((CamelService *)store)->session, (CamelService *)store, NULL);
 	if (root) {
 		char *base = g_build_filename(root, path, NULL);
-		char *file = g_build_filename(base, ".ev-summary", NULL);
+		char *file = g_build_filename(base, ".ev-summary.mmap", NULL);
 
 		e_util_mkdir_hier(base, 0777);
 		g_free(base);
Index: camel/providers/imapp/camel-imapp-summary.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/imapp/camel-imapp-summary.c,v
retrieving revision 1.4
diff -p -u -r1.4 camel-imapp-summary.c
--- camel/providers/imapp/camel-imapp-summary.c	31 Aug 2005 04:26:05 -0000	1.4
+++ camel/providers/imapp/camel-imapp-summary.c	18 Jul 2006 22:49:10 -0000
@@ -37,10 +37,10 @@
 
 #define CAMEL_IMAPP_SUMMARY_VERSION (1)
 
-static int summary_header_load(CamelFolderSummary *, FILE *);
+static int summary_header_load(CamelFolderSummary *);
 static int summary_header_save(CamelFolderSummary *, FILE *);
 
-static CamelMessageInfo *message_info_load(CamelFolderSummary *s, FILE *in);
+static CamelMessageInfo *message_info_load(CamelFolderSummary *s);
 static int message_info_save(CamelFolderSummary *s, FILE *out, CamelMessageInfo *info);
 
 static void camel_imapp_summary_class_init(CamelIMAPPSummaryClass *klass);
@@ -112,20 +112,26 @@ camel_imapp_summary_new(void)
 
 
 static int
-summary_header_load(CamelFolderSummary *s, FILE *in)
+summary_header_load(CamelFolderSummary *s)
 {
 	CamelIMAPPSummary *ims = CAMEL_IMAPP_SUMMARY(s);
+	unsigned char *ptrchr = s->filepos;
 
-	if (camel_imapp_summary_parent->summary_header_load(s, in) == -1)
+	if (camel_imapp_summary_parent->summary_header_load(s) == -1)
 		return -1;
 
 	/* Legacy version */
-	if (s->version == 0x100c)
-		return camel_file_util_decode_uint32(in, &ims->uidvalidity);
+	if (s->version == 0x100c) {		
+		ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &ims->uidvalidity, FALSE);
+		s->filepos = ptrchr;
 
-	if (camel_file_util_decode_fixed_int32(in, &ims->version) == -1
-	    || camel_file_util_decode_fixed_int32(in, &ims->uidvalidity) == -1)
-		return -1;
+		return 0;
+	}
+
+	ims->version = g_ntohl(get_unaligned_u32(s->filepos)); 
+	s->filepos += 4;
+	ims->uidvalidity = g_ntohl(get_unaligned_u32(s->filepos)); 
+	s->filepos += 4;
 
 	if (ims->version > CAMEL_IMAPP_SUMMARY_VERSION) {
 		g_warning("Unkown summary version\n");
@@ -153,23 +159,21 @@ summary_header_save(CamelFolderSummary *
 
 
 static CamelMessageInfo *
-message_info_load(CamelFolderSummary *s, FILE *in)
+message_info_load(CamelFolderSummary *s)
 {
 	CamelMessageInfo *info;
 	CamelIMAPPMessageInfo *iinfo;
 
-	info = camel_imapp_summary_parent->message_info_load(s, in);
+	info = camel_imapp_summary_parent->message_info_load(s);
 	if (info) {
+		unsigned char *ptrchr = s->filepos;
 		iinfo =(CamelIMAPPMessageInfo *)info;
 
-		if (camel_file_util_decode_uint32(in, &iinfo->server_flags) == -1)
-			goto error;
+		ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &iinfo->server_flags, FALSE);
+		s->filepos = ptrchr;		
 	}
 
 	return info;
-error:
-	camel_message_info_free(info);
-	return NULL;
 }
 
 static int
Index: camel/providers/local/camel-local-folder.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/local/camel-local-folder.c,v
retrieving revision 1.59
diff -p -u -r1.59 camel-local-folder.c
--- camel/providers/local/camel-local-folder.c	9 Dec 2005 07:46:20 -0000	1.59
+++ camel/providers/local/camel-local-folder.c	18 Jul 2006 22:49:10 -0000
@@ -235,7 +235,7 @@ camel_local_folder_construct(CamelLocalF
 	lf->base_path = g_strdup(root_dir_path);
 
 	lf->folder_path = camel_local_store_get_full_path(ls, full_name);
-	lf->summary_path = camel_local_store_get_meta_path(ls, full_name, ".ev-summary");
+	lf->summary_path = camel_local_store_get_meta_path(ls, full_name, ".ev-summary.mmap");
 	lf->index_path = camel_local_store_get_meta_path(ls, full_name, ".ibex");
 	statepath = camel_local_store_get_meta_path(ls, full_name, ".cmeta");
 
Index: camel/providers/local/camel-local-summary.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/local/camel-local-summary.c,v
retrieving revision 1.34
diff -p -u -r1.34 camel-local-summary.c
--- camel/providers/local/camel-local-summary.c	9 Jun 2006 01:21:53 -0000	1.34
+++ camel/providers/local/camel-local-summary.c	18 Jul 2006 22:49:11 -0000
@@ -46,7 +46,7 @@
 
 #define CAMEL_LOCAL_SUMMARY_VERSION (1)
 
-static int summary_header_load (CamelFolderSummary *, FILE *);
+static int summary_header_load (CamelFolderSummary *);
 static int summary_header_save (CamelFolderSummary *, FILE *);
 
 static CamelMessageInfo * message_info_new_from_header (CamelFolderSummary *, struct _camel_header_raw *);
@@ -590,13 +590,13 @@ local_summary_decode_x_evolution(CamelLo
 }
 
 static int
-summary_header_load(CamelFolderSummary *s, FILE *in)
+summary_header_load(CamelFolderSummary *s)
 {
 	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)
+	if (((CamelFolderSummaryClass *)camel_local_summary_parent)->summary_header_load(s) == -1)
 		return -1;
 
 	/* Legacy version, version is in summary only */
@@ -604,7 +604,11 @@ summary_header_load(CamelFolderSummary *
 		return 0;
 
 	/* otherwise load the version number */
-	return camel_file_util_decode_fixed_int32(in, &cls->version);
+	
+	cls->version = g_ntohl(get_unaligned_u32(s->filepos)); 
+	s->filepos += 4;
+
+	return 0;
 }
 
 static int
Index: camel/providers/local/camel-maildir-summary.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/local/camel-maildir-summary.c,v
retrieving revision 1.28
diff -p -u -r1.28 camel-maildir-summary.c
--- camel/providers/local/camel-maildir-summary.c	31 Aug 2005 04:26:06 -0000	1.28
+++ camel/providers/local/camel-maildir-summary.c	18 Jul 2006 22:49:12 -0000
@@ -48,7 +48,7 @@
 
 #define CAMEL_MAILDIR_SUMMARY_VERSION (0x2000)
 
-static CamelMessageInfo *message_info_load(CamelFolderSummary *s, FILE *in);
+static CamelMessageInfo *message_info_load(CamelFolderSummary *s);
 static CamelMessageInfo *message_info_new_from_header(CamelFolderSummary *, struct _camel_header_raw *);
 static void message_info_free(CamelFolderSummary *, CamelMessageInfo *mi);
 
@@ -385,12 +385,12 @@ static char *maildir_summary_next_uid_st
 }
 
 static CamelMessageInfo *
-message_info_load(CamelFolderSummary *s, FILE *in)
+message_info_load(CamelFolderSummary *s)
 {
 	CamelMessageInfo *mi;
 	CamelMaildirSummary *mds = (CamelMaildirSummary *)s;
 
-	mi = ((CamelFolderSummaryClass *) parent_class)->message_info_load(s, in);
+	mi = ((CamelFolderSummaryClass *) parent_class)->message_info_load(s);
 	if (mi) {
 		char *name;
 
Index: camel/providers/local/camel-mbox-summary.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/local/camel-mbox-summary.c,v
retrieving revision 1.60
diff -p -u -r1.60 camel-mbox-summary.c
--- camel/providers/local/camel-mbox-summary.c	15 Jun 2006 11:16:25 -0000	1.60
+++ camel/providers/local/camel-mbox-summary.c	18 Jul 2006 22:49:14 -0000
@@ -48,12 +48,12 @@
 
 #define CAMEL_MBOX_SUMMARY_VERSION (1)
 
-static int summary_header_load (CamelFolderSummary *, FILE *);
+static int summary_header_load (CamelFolderSummary *);
 static int summary_header_save (CamelFolderSummary *, FILE *);
 
 static CamelMessageInfo * message_info_new_from_header(CamelFolderSummary *, struct _camel_header_raw *);
 static CamelMessageInfo * message_info_new_from_parser(CamelFolderSummary *, CamelMimeParser *);
-static CamelMessageInfo * message_info_load (CamelFolderSummary *, FILE *);
+static CamelMessageInfo * message_info_load (CamelFolderSummary *);
 static int		  message_info_save (CamelFolderSummary *, FILE *, CamelMessageInfo *);
 /*static void		  message_info_free (CamelFolderSummary *, CamelMessageInfo *);*/
 
@@ -233,22 +233,31 @@ mbox_summary_encode_x_evolution (CamelLo
 	}
 }
 
+
+	
 static int
-summary_header_load(CamelFolderSummary *s, FILE *in)
+summary_header_load(CamelFolderSummary *s)
 {
 	CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY(s);
+	unsigned char *ptrchr;
 
-	if (((CamelFolderSummaryClass *)camel_mbox_summary_parent)->summary_header_load(s, in) == -1)
+	if (((CamelFolderSummaryClass *)camel_mbox_summary_parent)->summary_header_load(s) == -1)
 		return -1;
 
 	/* legacy version */
-	if (s->version == 0x120c)
-		return camel_file_util_decode_uint32(in, (guint32 *) &mbs->folder_size);
+	if (s->version == 0x120c) {
+		unsigned char* ptrchr = s->filepos;
+		ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &mbs->folder_size, FALSE);
+		s->filepos = ptrchr;
+	}
 
 	/* 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;
+	mbs->version = g_ntohl(get_unaligned_u32(s->filepos)); 
+	s->filepos += 4;
+
+	ptrchr = s->filepos;
+	ptrchr = camel_file_util_mmap_decode_size_t (ptrchr, &mbs->folder_size);
+	s->filepos = ptrchr;
 
 	return 0;
 }
@@ -361,27 +370,27 @@ message_info_new_from_parser(CamelFolder
 	return mi;
 }
 
+
 static CamelMessageInfo *
-message_info_load(CamelFolderSummary *s, FILE *in)
+message_info_load(CamelFolderSummary *s)
 {
 	CamelMessageInfo *mi;
 
 	io(printf("loading mbox message info\n"));
 
-	mi = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_load(s, in);
+	mi = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_load(s);
 	if (mi) {
 		CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)mi;
-		
-		if (camel_file_util_decode_off_t(in, &mbi->frompos) == -1)
-			goto error;
+
+		unsigned char *ptrchr = s->filepos;
+		ptrchr = camel_file_util_mmap_decode_off_t (ptrchr, &mbi->frompos);
+		s->filepos = ptrchr;
 	}
 	
 	return mi;
-error:
-	camel_message_info_free(mi);
-	return NULL;
 }
 
+
 static int
 message_info_save(CamelFolderSummary *s, FILE *out, CamelMessageInfo *mi)
 {
@@ -390,7 +399,7 @@ message_info_save(CamelFolderSummary *s,
 	io(printf("saving mbox message info\n"));
 
 	if (((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_save(s, out, mi) == -1
-	    || camel_file_util_encode_off_t(out, mbi->frompos) == -1)
+	    || camel_file_util_encode_off_t (out, mbi->frompos) == -1)
 		return -1;
 
 	return 0;
Index: camel/providers/nntp/camel-nntp-folder.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/nntp/camel-nntp-folder.c,v
retrieving revision 1.56
diff -p -u -r1.56 camel-nntp-folder.c
--- camel/providers/nntp/camel-nntp-folder.c	15 Jun 2006 16:41:57 -0000	1.56
+++ camel/providers/nntp/camel-nntp-folder.c	18 Jul 2006 22:49:14 -0000
@@ -508,7 +508,7 @@ camel_nntp_folder_new (CamelStore *paren
 	camel_object_state_read(nntp_folder);
 	g_free(root);
 
-	root = g_strdup_printf("%s.ev-summary", nntp_folder->storage_path);
+	root = g_strdup_printf("%s.ev-summary.mmap", nntp_folder->storage_path);
 	folder->summary = (CamelFolderSummary *) camel_nntp_summary_new (folder, root);
 	g_free(root);
 	camel_folder_summary_load (folder->summary);
Index: camel/providers/nntp/camel-nntp-summary.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/nntp/camel-nntp-summary.c,v
retrieving revision 1.23
diff -p -u -r1.23 camel-nntp-summary.c
--- camel/providers/nntp/camel-nntp-summary.c	9 Jun 2006 01:21:53 -0000	1.23
+++ camel/providers/nntp/camel-nntp-summary.c	18 Jul 2006 22:49:15 -0000
@@ -60,7 +60,7 @@ struct _CamelNNTPSummaryPrivate {
 #define _PRIVATE(o) (((CamelNNTPSummary *)(o))->priv)
 
 static CamelMessageInfo * message_info_new_from_header (CamelFolderSummary *, struct _camel_header_raw *);
-static int summary_header_load(CamelFolderSummary *, FILE *);
+static int summary_header_load(CamelFolderSummary *);
 static int summary_header_save(CamelFolderSummary *, FILE *);
 
 static void camel_nntp_summary_class_init (CamelNNTPSummaryClass *klass);
@@ -159,21 +159,26 @@ message_info_new_from_header(CamelFolder
 }
 
 static int
-summary_header_load(CamelFolderSummary *s, FILE *in)
+summary_header_load(CamelFolderSummary *s)
 {
 	CamelNNTPSummary *cns = CAMEL_NNTP_SUMMARY(s);
+	unsigned char *ptrchr = s->filepos;
 
-	if (((CamelFolderSummaryClass *)camel_nntp_summary_parent)->summary_header_load(s, in) == -1)
+	if (((CamelFolderSummaryClass *)camel_nntp_summary_parent)->summary_header_load(s) == -1)
 		return -1;
 
 	/* Legacy version */
 	if (s->version == 0x20c) {
-		camel_file_util_decode_fixed_int32(in, &cns->high);
-		return camel_file_util_decode_fixed_int32(in, &cns->low);
+		cns->high = g_ntohl(get_unaligned_u32(s->filepos));
+		s->filepos += 4;
+		cns->low = g_ntohl(get_unaligned_u32(s->filepos));
+		s->filepos += 4;
+
+		return 0;
 	}
 
-	if (camel_file_util_decode_fixed_int32(in, &cns->version) == -1)
-		return -1;
+	cns->version = g_ntohl(get_unaligned_u32(s->filepos)); 
+	s->filepos += 4;
 
 	if (cns->version > CAMEL_NNTP_SUMMARY_VERSION) {
 		g_warning("Unknown NNTP summary version");
@@ -181,9 +186,10 @@ summary_header_load(CamelFolderSummary *
 		return -1;
 	}
 
-	if (camel_file_util_decode_fixed_int32(in, &cns->high) == -1
-	    || camel_file_util_decode_fixed_int32(in, &cns->low) == -1)
-		return -1;
+	cns->high = g_ntohl(get_unaligned_u32(s->filepos)); 
+	s->filepos += 4;
+	cns->low = g_ntohl(get_unaligned_u32(s->filepos)); 
+	s->filepos += 4;
 
 	return 0;
 }
Index: camel/camel-exchange-summary.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/camel/camel-exchange-summary.c,v
retrieving revision 1.5
diff -u -p -r1.5 camel-exchange-summary.c
--- camel/camel-exchange-summary.c	30 Jul 2005 10:08:07 -0000	1.5
+++ camel/camel-exchange-summary.c	18 Jul 2006 22:35:11 -0000
@@ -38,11 +38,10 @@
 
 #define CAMEL_EXCHANGE_SUMMARY_VERSION (1)
 
-static int header_load (CamelFolderSummary *summary, FILE *in);
+static int header_load (CamelFolderSummary *summary);
 static int header_save (CamelFolderSummary *summary, FILE *out);
 
-static CamelMessageInfo *message_info_load (CamelFolderSummary *summary,
-					    FILE *in);
+static CamelMessageInfo *message_info_load (CamelFolderSummary *summary);
 static int               message_info_save (CamelFolderSummary *summary,
 					    FILE *out,
 					    CamelMessageInfo *info);
@@ -129,21 +128,23 @@ camel_exchange_summary_new (struct _Came
 
 
 static int
-header_load (CamelFolderSummary *summary, FILE *in)
+header_load (CamelFolderSummary *summary)
 {
 	CamelExchangeSummary *exchange = (CamelExchangeSummary *) summary;
 	guint32 version, readonly;
 	
-	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_load (summary, in) == -1)
+	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_load (summary) == -1)
 		return -1;
 	
-	if (camel_file_util_decode_uint32 (in, &version) == -1)
-		return -1;
+	version = g_ntohl(get_unaligned_u32(s->filepos));
+	s->filepos += 4;
+		
 	if (version > CAMEL_EXCHANGE_SUMMARY_VERSION)
 		return -1;
 
-	if (camel_file_util_decode_uint32 (in, &readonly) == -1)
-		return -1;
+	readonly = g_ntohl(get_unaligned_u32(s->filepos));
+	s->filepos += 4;
+	
 	exchange->readonly = readonly;
 	
 	return 0;
@@ -167,18 +168,23 @@ header_save (CamelFolderSummary *summary
 }
 
 static CamelMessageInfo *
-message_info_load (CamelFolderSummary *summary, FILE *in)
+message_info_load (CamelFolderSummary *summary)
 {
 	CamelMessageInfo *info;
 	CamelExchangeMessageInfo *einfo;
 	char *thread_index;
 
-	info = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_load (summary, in);
+	info = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_load (summary);
 	if (info) {
+		unsigned char *ptrchr;
 		einfo = (CamelExchangeMessageInfo *)info;
 
-		if (camel_file_util_decode_string (in, &thread_index) == -1)
-			goto error;
+		ptrchr = s->filepos;
+		ptrchr = camel_file_util_mmap_decode_uint32 (ptrchr, &len, TRUE);
+		if (len) 
+			thread_index = ptrchr;
+		ptrchr += len;		
+		s->filepos = ptrchr;
 
 		if (thread_index && *thread_index)
 			einfo->thread_index = thread_index;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]