evolution-data-server r8374 - trunk/camel/providers/local



Author: psankar
Date: Wed Jan 16 08:28:47 2008
New Revision: 8374
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=8374&view=rev

Log:
2008-01-16  Sankar P  <psankar novell com>

	* camel-mbox-summary.c: (mbox_summary_sync_quick),
	(fix_summary_mismatch), (camel_mbox_summary_sync_mbox):
	Remove the error condition that inits and persists 
	the infamous "folder summary mismatch" bug.

	** Fix for bug #213072

	** Let there be light at the end of the tunnel :)




Modified:
   trunk/camel/providers/local/ChangeLog
   trunk/camel/providers/local/camel-mbox-summary.c

Modified: trunk/camel/providers/local/camel-mbox-summary.c
==============================================================================
--- trunk/camel/providers/local/camel-mbox-summary.c	(original)
+++ trunk/camel/providers/local/camel-mbox-summary.c	Wed Jan 16 08:28:47 2008
@@ -45,6 +45,7 @@
 
 #define io(x)
 #define d(x) /*(printf("%s(%d): ", __FILE__, __LINE__),(x))*/
+#define debug 0
 
 #define CAMEL_MBOX_SUMMARY_VERSION (1)
 
@@ -72,6 +73,8 @@
 static void camel_mbox_summary_class_init (CamelMboxSummaryClass *klass);
 static void camel_mbox_summary_init       (CamelMboxSummary *obj);
 static void camel_mbox_summary_finalise   (CamelObject *obj);
+static int fix_summary_mismatch (CamelFolderSummary *s, CamelException *ex);
+
 
 #ifdef STATUS_PINE
 /* Which status flags are stored in each separate header */
@@ -750,17 +753,34 @@
 
 		if (camel_mime_parser_step(mp, NULL, NULL) != CAMEL_MIME_PARSER_STATE_FROM) {
 			g_warning("Expected a From line here, didn't get it");
-			camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
-					     _("Summary and folder mismatch, even after a sync"));
-			goto error;
+			/*
+			   camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
+			   _("Summary and folder mismatch, even after a sync"));
+			   goto error;
+			 */
+			if (!fix_summary_mismatch (s, ex)) {
+				/* Now go back one level */
+				--i;
+			} else
+				goto error;
+			continue;
 		}
 
 		if (camel_mime_parser_tell_start_from(mp) != info->frompos) {
 			g_warning("Didn't get the next message where I expected (%d) got %d instead",
-				  (int)info->frompos, (int)camel_mime_parser_tell_start_from(mp));
-			camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
-					     _("Summary and folder mismatch, even after a sync"));
-			goto error;
+					(int)info->frompos, (int)camel_mime_parser_tell_start_from(mp));
+			/*
+			   camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
+			   _("Summary and folder mismatch, even after a sync"));
+			   goto error;
+			 */
+
+			if (!fix_summary_mismatch (s, ex)) {
+				/* Now go back one level */
+				--i;
+			} else
+				goto error;
+			continue;
 		}
 
 		if (camel_mime_parser_step(mp, NULL, NULL) == CAMEL_MIME_PARSER_STATE_FROM_END) {
@@ -898,6 +918,81 @@
 	return ((CamelLocalSummaryClass *)camel_mbox_summary_parent)->sync(cls, expunge, changeinfo, ex);
 }
 
+static int 
+fix_summary_mismatch (CamelFolderSummary *s, CamelException *ex)
+{
+	/* Read the .mbox file here and parse the From locations 
+	   Update the summary file with these From locations. */
+
+#if debug 
+	char *subject = NULL; 
+	int total = 0;
+#endif 
+
+	int mbox_fd;
+	int hits = 0; 
+	int state;
+
+	long frompos;
+
+	CamelMimeParser *parser;
+	CamelMboxMessageInfo *info = NULL;
+
+	mbox_fd = g_open(((CamelLocalSummary *)s)->folder_path, O_LARGEFILE | O_RDONLY | O_BINARY, 0);
+	if (mbox_fd == -1) {
+		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+				_("Folder %s cannot be opened\n  %s"),
+				((CamelLocalSummary *)s)->folder_path, g_strerror (errno));
+		return -1;
+	} 
+
+	d(printf ("\n\aFolder %s opened succesfully \n\a", ((CamelLocalSummary *)s)->folder_path));
+
+	parser = camel_mime_parser_new();
+	camel_mime_parser_init_with_fd(parser, mbox_fd);
+	camel_mime_parser_scan_from(parser, TRUE);
+
+	while ( (state = camel_mime_parser_step(parser, NULL, NULL) ) != CAMEL_MIME_PARSER_STATE_EOF) {
+
+		if (state == CAMEL_MIME_PARSER_STATE_FROM) {
+			frompos = camel_mime_parser_tell_start_from (parser);
+
+			/* This code need to be enabled only on debug builds. 
+			   Otherwise the subject parsing will take so much of time on BIIIG folders */
+
+# if debug
+			camel_mime_parser_step (parser, NULL, NULL);
+			subject = (char *)camel_mime_parser_header (parser, "subject", NULL);
+
+			/* Don't try printing subjects in a billion mails folder */
+			printf("Message @ %ld, Subject: %s\n", (long)frompos, subject);
+#endif
+
+			info = (CamelMboxMessageInfo *)camel_folder_summary_index(s, hits);
+			if (info) {
+				info->frompos = frompos;
+				camel_message_info_free((CamelMessageInfo *)info);
+			}
+			hits ++;
+		} 
+#if debug
+		total ++;
+#endif 
+	}
+
+#if debug
+	printf ("\n\aUpdated summary with the from addresses of %d items via %d parses\n\a", hits, total);
+#endif
+
+	camel_object_unref(parser);
+	close (mbox_fd);
+	camel_folder_summary_touch(s);
+	camel_folder_summary_save (s);
+
+	return 0;
+}
+
+
 int
 camel_mbox_summary_sync_mbox(CamelMboxSummary *cls, guint32 flags, CamelFolderChangeInfo *changeinfo, int fd, int fdout, CamelException *ex)
 {
@@ -949,18 +1044,26 @@
 		}
 
 		if (camel_mime_parser_step(mp, &buffer, &len) != CAMEL_MIME_PARSER_STATE_FROM) {
-			g_warning("Expected a From line here, didn't get it");
-			camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
-					     _("Summary and folder mismatch, even after a sync"));
-			goto error;
+			g_warning("Expected a From line here, didn't get it. SO recovering....\n");
+			/*camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
+			  _("Summary and folder mismatch, even after a sync"));*/
+			if (!fix_summary_mismatch (s, ex)) {
+				/* Now go back one level */
+				--i;
+			} else
+				goto error;
+			continue;
 		}
 
 		if (camel_mime_parser_tell_start_from(mp) != info->frompos) {
 			g_warning("Didn't get the next message where I expected (%d) got %d instead",
-				  (int)info->frompos, (int)camel_mime_parser_tell_start_from(mp));
-			camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
-					     _("Summary and folder mismatch, even after a sync"));
-			goto error;
+					(int)info->frompos, (int)camel_mime_parser_tell_start_from(mp));
+			if (!fix_summary_mismatch (s, ex)) {
+				/* Now go back one level */
+				--i;
+			} else
+				goto error;
+			continue;
 		}
 
 		lastdel = FALSE;



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