Index: camel/ChangeLog
===================================================================
--- camel/ChangeLog	(revision 9191)
+++ camel/ChangeLog	(working copy)
@@ -1,3 +1,16 @@
+2008-07-25  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #544651
+
+	* camel-folder-summary.c: (EXTRACT_FIRST_STRING), (EXTRACT_STRING):
+	Properly update string position after read (thanks to srag).
+	* camel-folder-summary.c: (EXTRACT_DIGIT):
+	Prevent moving beyond string limit.
+	* camel-folder-summary.c: (camel_read_mir_callback):
+	Do not access NULL.
+	* camel-folder-summary.c: (my_list_append):
+	Interpret and update given list pointer properly.
+
 2008-07-25  Milan Crha  <mcrha@redhat.com>
 
 	** Fix for bug #544031
Index: camel/camel-folder-summary.c
===================================================================
--- camel/camel-folder-summary.c	(revision 9191)
+++ camel/camel-folder-summary.c	(working copy)
@@ -88,10 +88,10 @@ extern int strdup_count, malloc_count, f
 
 #define META_SUMMARY_SUFFIX_LEN 5 /* strlen("-meta") */
 
-#define EXTRACT_FIRST_STRING(val) len=strtoul (part, &part, 10); part++; val=g_strndup (part, len);
-#define EXTRACT_STRING(val) part++; len=strtoul (part, &part, 10); part++; val=g_strndup (part, len);
+#define EXTRACT_FIRST_STRING(val) len=strtoul (part, &part, 10); if (*part) part++; val=g_strndup (part, len); part+=len;
+#define EXTRACT_STRING(val) if (*part) part++; len=strtoul (part, &part, 10); if (*part) part++; val=g_strndup (part, len); part+=len;
 #define EXTRACT_FIRST_DIGIT(val) val=strtoul (part, &part, 10);
-#define EXTRACT_DIGIT(val) part++; val=strtoul (part, &part, 10);
+#define EXTRACT_DIGIT(val) if (*part) part++; val=strtoul (part, &part, 10);
 
 /* trivial lists, just because ... */
 struct _node {
@@ -937,6 +937,11 @@ camel_read_mir_callback (void * ref, int
 				info = NULL;
 			} 
 			mir->cinfo = tmp;
+
+			if (!info) {
+				camel_db_camel_mir_free (mir);
+				return -1;
+			}
 		}
 
 		if (data->double_ref)
@@ -2265,10 +2270,16 @@ camel_folder_summary_decode_token(FILE *
 static struct _node *
 my_list_append(struct _node **list, struct _node *n)
 {
-	struct _node *ln = (struct _node *)list;
+	struct _node *ln = *list;
+	n->next = NULL;
+
+	if (!ln) {
+		*list = n;
+		return n;
+	}
+
 	while (ln->next)
 		ln = ln->next;
-	n->next = NULL;
 	ln->next = n;
 	return n;
 }
