evolution-data-server r8963 - in branches/camel-db-summary/camel: . providers/imap providers/local



Author: psankar
Date: Tue Jun 10 12:16:07 2008
New Revision: 8963
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=8963&view=rev

Log:
IMAP initial support. Save and Load summaries.
Expect some crashers.



Modified:
   branches/camel-db-summary/camel/camel-folder-summary.c
   branches/camel-db-summary/camel/camel-folder-summary.h
   branches/camel-db-summary/camel/camel-folder.c
   branches/camel-db-summary/camel/camel-store.c
   branches/camel-db-summary/camel/providers/imap/camel-imap-folder.c
   branches/camel-db-summary/camel/providers/imap/camel-imap-message-cache.c
   branches/camel-db-summary/camel/providers/imap/camel-imap-summary.c
   branches/camel-db-summary/camel/providers/local/camel-local-summary.c

Modified: branches/camel-db-summary/camel/camel-folder-summary.c
==============================================================================
--- branches/camel-db-summary/camel/camel-folder-summary.c	(original)
+++ branches/camel-db-summary/camel/camel-folder-summary.c	Tue Jun 10 12:16:07 2008
@@ -71,7 +71,7 @@
 /* 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)
 
@@ -662,18 +662,16 @@
 }
 
 int
-camel_folder_summary_load_from_db (CamelFolderSummary *s)
+camel_folder_summary_load_from_db (CamelFolderSummary *s, CamelException *ex)
 {
 	CamelDB *cdb;
-	CamelException ex;// May be this should come from the caller 
 	char *folder_name;
 	int ret = 0;
 
 	d(printf ("\ncamel_folder_summary_load_from_db called \n"));
-	camel_exception_init (&ex);
 	s->flags &= ~CAMEL_SUMMARY_DIRTY;
 
-	ret = camel_folder_summary_header_load_from_db (s, s->folder->parent_store, s->folder->full_name, &ex);
+	ret = camel_folder_summary_header_load_from_db (s, s->folder->parent_store, s->folder->full_name, ex);
 
 	if (ret)
 		return ret;
@@ -682,7 +680,7 @@
 	cdb = s->folder->parent_store->cdb;
 
 	/* FIXME FOR SANKAR: No need to pass the address of summary here. */
-	ret = camel_db_read_message_info_records (cdb, folder_name, (gpointer**) &s, camel_read_mir_callback, &ex);
+	ret = camel_db_read_message_info_records (cdb, folder_name, (gpointer**) &s, camel_read_mir_callback, ex);
 
 	#warning "LRU please and not timeouts"
 	//g_timeout_add_seconds (10, remove_cache, s);
@@ -757,12 +755,15 @@
 	if (info) {
 
 		if (s->build_content) {
+			char *tmp;
+			tmp = mir->cinfo;
 			/* FIXME: this should be done differently, how i don't know */
 			((CamelMessageInfoBase *)info)->content = perform_content_info_load_from_db (s, mir);
 			if (((CamelMessageInfoBase *)info)->content == NULL) {
 				camel_message_info_free(info);
 				info = NULL;
 			} 
+			mir->cinfo = tmp;
 		}
 
 		/* Just now we are reading from the DB, it can't be dirty. */
@@ -770,7 +771,6 @@
 //		((CamelMessageInfoBase *)info)->flags &= ~CAMEL_MESSAGE_DB_DIRTY;
 		camel_folder_summary_add (s, info);
 
-		d(g_print ("\nAdding messageinfo to db from db \n"));
 	} else
 		g_warning ("Loading messageinfo from db failed");
 

Modified: branches/camel-db-summary/camel/camel-folder-summary.h
==============================================================================
--- branches/camel-db-summary/camel/camel-folder-summary.h	(original)
+++ branches/camel-db-summary/camel/camel-folder-summary.h	Tue Jun 10 12:16:07 2008
@@ -314,7 +314,10 @@
 CamelType			 camel_folder_summary_get_type	(void);
 CamelFolderSummary      *camel_folder_summary_new	(struct _CamelFolder *folder);
 
+/* Deprecated */
 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);
 
@@ -328,7 +331,7 @@
 
 /* load/save the full summary from/to the db */
 int camel_folder_summary_save_to_db (CamelFolderSummary *s, CamelException *ex);
-int camel_folder_summary_load_from_db (CamelFolderSummary *s);
+int camel_folder_summary_load_from_db (CamelFolderSummary *s, CamelException *ex);
 
 /* only load the header */
 int camel_folder_summary_header_load(CamelFolderSummary *summary);

Modified: branches/camel-db-summary/camel/camel-folder.c
==============================================================================
--- branches/camel-db-summary/camel/camel-folder.c	(original)
+++ branches/camel-db-summary/camel/camel-folder.c	Tue Jun 10 12:16:07 2008
@@ -1362,30 +1362,30 @@
 {
 	CamelMimeMessage *msg;
 	CamelMessageInfo *minfo, *info;
-	
+
 	/* Default implementation. */
-	
+
 	msg = camel_folder_get_message(source, uid, ex);
 	if (!msg)
 		return;
 
 	/* if its deleted we poke the flags, so we need to copy the messageinfo */
 	if ((source->folder_flags & CAMEL_FOLDER_HAS_SUMMARY_CAPABILITY)
-	    && (minfo = camel_folder_get_message_info(source, uid))) {
+			&& (minfo = camel_folder_get_message_info(source, uid))) {
 		info = camel_message_info_clone(minfo);
 		camel_folder_free_message_info(source, minfo);
 	} else
 		info = camel_message_info_new_from_header(NULL, ((CamelMimePart *)msg)->headers);
-	
+
 	/* we don't want to retain the deleted flag */
 	camel_message_info_set_flags(info, CAMEL_MESSAGE_DELETED, 0);
-	
+
 	camel_folder_append_message (dest, msg, info, transferred_uid, ex);
 	camel_object_unref (msg);
-	
+
 	if (delete_original && !camel_exception_is_set (ex))
 		camel_folder_set_message_flags (source, uid, CAMEL_MESSAGE_DELETED|CAMEL_MESSAGE_SEEN, ~0);
-	
+
 	camel_message_info_free (info);
 }
 

Modified: branches/camel-db-summary/camel/camel-store.c
==============================================================================
--- branches/camel-db-summary/camel/camel-store.c	(original)
+++ branches/camel-db-summary/camel/camel-store.c	Tue Jun 10 12:16:07 2008
@@ -213,10 +213,19 @@
 		return;
 
 	store_db_path = g_build_filename (service->url->path, CAMEL_DB_FILE, NULL);
+
+	if (strlen (store_db_path) < 2) {
+		g_free (store_db_path);
+		store_db_path = g_build_filename ( camel_session_get_storage_path (session, service, ex), CAMEL_DB_FILE, NULL);		
+	}
+
 	store->cdb = camel_db_open (store_db_path, ex);
+	printf("store_db_path %s\n", store_db_path);
 	g_free (store_db_path);
-	if (camel_exception_is_set (ex))
+	if (camel_exception_is_set (ex)) {
+		g_print ("Exiting without success for stire_db_path : [%s]\n", store_db_path);
 		return;
+	}
 
 	if (camel_db_create_folders_table (store->cdb, ex))
 		printf ("something went wrong terribly\n");

Modified: branches/camel-db-summary/camel/providers/imap/camel-imap-folder.c
==============================================================================
--- branches/camel-db-summary/camel/providers/imap/camel-imap-folder.c	(original)
+++ branches/camel-db-summary/camel/providers/imap/camel-imap-folder.c	Tue Jun 10 12:16:07 2008
@@ -306,11 +306,10 @@
 	CamelImapFolder *imap_folder = CAMEL_IMAP_FOLDER (folder);
 	CamelImapSummary *imap_summary = CAMEL_IMAP_SUMMARY (folder->summary);
 	unsigned long exists = 0, validity = 0, val, uid;
-	CamelMessageInfo *info;
 	guint32 perm_flags = 0;
 	GData *fetch_data;
 	int i, count;
-	char *resp;
+	char *resp, *old_uid;
 	
 	count = camel_folder_summary_count (folder->summary);
 	
@@ -408,11 +407,13 @@
 		}
 		camel_imap_response_free_without_processing (store, response);
 		
-		info = camel_folder_summary_index (folder->summary, count - 1);
-		val = strtoul (camel_message_info_uid (info), NULL, 10);
-		camel_message_info_free(info);
-		if (uid == 0 || uid != val)
-			imap_folder->need_rescan = TRUE;
+		old_uid = camel_folder_summary_uid_from_index (folder->summary, count - 1);
+		if (old_uid) { 
+			val = strtoul (old_uid, NULL, 10);
+			g_free (old_uid);
+			if (uid == 0 || uid != val)
+				imap_folder->need_rescan = TRUE;
+		}
 	}
 	
 	/* Now rescan if we need to */
@@ -725,7 +726,7 @@
 done:
 	CAMEL_SERVICE_REC_UNLOCK (imap_store, connect_lock);
 
-	camel_folder_summary_save(folder->summary);
+	camel_folder_summary_save_to_db (folder->summary, ex);
 	camel_store_summary_save((CamelStoreSummary *)((CamelImapStore *)folder->parent_store)->summary);
 }
 
@@ -814,7 +815,7 @@
 		guint32 flags;
 		char *custom_flags;
 	} *new;
-	char *resp;
+	char *resp, *uid;
 	CamelImapResponseType type;
 	int i, seq, summary_len, summary_got;
 	CamelMessageInfo *info;
@@ -837,11 +838,17 @@
 	
 	/* Check UIDs and flags of all messages we already know of. */
 	camel_operation_start (NULL, _("Scanning for changed messages in %s"), folder->name);
-	info = camel_folder_summary_index (folder->summary, summary_len - 1);
+	uid = camel_folder_summary_uid_from_index (folder->summary, summary_len - 1);
+
+	if (!uid) {
+		camel_operation_end (NULL);
+		return;
+	}
+
 	ok = camel_imap_command_start (store, folder, ex,
 				       "UID FETCH 1:%s (FLAGS)",
-				       camel_message_info_uid (info));
-	camel_message_info_free(info);
+				       uid);
+	g_free (uid);
 	if (!ok) {
 		camel_operation_end (NULL);
 		return;
@@ -903,11 +910,16 @@
 	for (i = 0; i < summary_len && new[i].uid; i++) {
 		gboolean changed = FALSE;
 
-		info = camel_folder_summary_index (folder->summary, i);
+		uid = camel_folder_summary_uid_from_index (folder->summary, i);
+		
+		if (!uid) 
+			continue; 
+
+		info = camel_folder_summary_uid (folder->summary, uid);
 		iinfo = (CamelImapMessageInfo *)info;
 		
-		if (strcmp (camel_message_info_uid (info), new[i].uid) != 0) {
-			camel_message_info_free(info);
+		if (strcmp (uid, new[i].uid) != 0) {
+			g_free (uid);
 			seq = i + 1;
 			g_array_append_val (removed, seq);
 			i--;
@@ -915,6 +927,8 @@
 			continue;
 		}
 		
+		g_free (uid);
+
 		/* Update summary flags */
 		if (new[i].flags != iinfo->server_flags) {
 			guint32 server_set, server_cleared;
@@ -992,6 +1006,7 @@
 	GString *gset;
 	GSList *list1 = NULL;
 	int count1 = 0;
+	char *uid;
 
 	#define close_range()										\
 		if (range != -1) {									\
@@ -1007,7 +1022,14 @@
 	max = camel_folder_summary_count (folder->summary);
 	range = -1;
 	for (i = 0; i < max && !UID_SET_FULL (gset->len, UID_SET_LIMIT); i++) {
-		info = (CamelImapMessageInfo *)camel_folder_summary_index (folder->summary, i);
+		uid = camel_folder_summary_uid_from_index (folder->summary, i);
+
+		if (uid) {
+			info = (CamelImapMessageInfo *) camel_folder_summary_uid (folder->summary, uid);
+			g_free (uid);
+		} else
+			continue;
+		
 		if (!info)
 			continue;
 		if ((info->info.flags & mask) != flags) {
@@ -1116,7 +1138,7 @@
 		}
 	}
 
-	camel_folder_summary_save (folder->summary);
+	camel_folder_summary_save_to_db (folder->summary, ex);
 	camel_store_summary_save((CamelStoreSummary *)((CamelImapStore *)folder->parent_store)->summary);
 }
 
@@ -1127,7 +1149,7 @@
 	CamelImapMessageInfo *info;
 	CamelException local_ex;
 	GPtrArray *matches;
-	char *set, *flaglist;
+	char *set, *flaglist, *uid;
 	int i, j, max;
 	
 	if (folder->permanent_flags == 0) {
@@ -1147,8 +1169,17 @@
 		gboolean unset = FALSE;
 		CamelImapResponse *response = NULL;
 
-		if (!(info = (CamelImapMessageInfo *)camel_folder_summary_index (folder->summary, i)))
+		uid = camel_folder_summary_uid_from_index (folder->summary, i);
+
+		if (!uid)
+			continue;
+
+		if (!(info = (CamelImapMessageInfo *) camel_folder_summary_uid (folder->summary, uid))) {
+			g_free (uid);
 			continue;
+		}
+
+		g_free (uid);
 		
 		if (!(info->info.flags & CAMEL_MESSAGE_FOLDER_FLAGGED)) {
 			camel_message_info_free((CamelMessageInfo *)info);
@@ -1271,7 +1302,7 @@
 		 * the cached data may be useful in replaying a COPY later.
 		 */
 	}
-	camel_folder_summary_save (folder->summary);
+	camel_folder_summary_save_to_db (folder->summary, ex);
 
 	camel_disco_diary_log (CAMEL_DISCO_STORE (folder->parent_store)->diary,
 			       CAMEL_DISCO_DIARY_FOLDER_EXPUNGE, folder, uids);
@@ -2819,7 +2850,7 @@
 	GString *header_spec = NULL;
 	CamelImapMessageInfo *mi, *info;
 	CamelStream *stream;
-	char *uid, *resp;
+	char *uid, *resp, *tempuid;
 	GData *data;
 	extern int camel_application_is_exiting;
 
@@ -2854,9 +2885,13 @@
 	seq = camel_folder_summary_count (folder->summary);
 	first = seq + 1;
 	if (seq > 0) {
-		mi = (CamelImapMessageInfo *)camel_folder_summary_index (folder->summary, seq - 1);
-		uidval = strtoul(camel_message_info_uid (mi), NULL, 10);
-		camel_message_info_free(&mi->info);
+		tempuid = camel_folder_summary_uid_from_index (folder->summary, seq -1 );
+
+		if (tempuid) {
+			uidval = strtoul(tempuid, NULL, 10);
+			g_free (tempuid);
+		} else
+			uidval = 0;
 	} else
 		uidval = 0;
 	
@@ -3147,6 +3182,7 @@
 	CamelFolderChangeInfo *changes;
 	CamelMessageInfo *info;
 	int len;
+	char *uid;
 	
 	changes = camel_folder_change_info_new ();
 	if (expunged) {
@@ -3154,19 +3190,19 @@
 		
 		for (i = 0; i < expunged->len; i++) {
 			id = g_array_index (expunged, int, i);
-			info = camel_folder_summary_index (folder->summary, id - 1);
-			if (info == NULL) {
+			uid = camel_folder_summary_uid_from_index (folder->summary, id - 1);
+			if (uid == NULL) {
 				/* FIXME: danw: does this mean that the summary is corrupt? */
 				/* I guess a message that we never retrieved got expunged? */
 				continue;
 			}
 			
-			camel_folder_change_info_remove_uid (changes, camel_message_info_uid (info));
+			camel_folder_change_info_remove_uid (changes, uid);
 			CAMEL_IMAP_FOLDER_REC_LOCK (imap_folder, cache_lock);
-			camel_imap_message_cache_remove (imap_folder->cache, camel_message_info_uid (info));
+			camel_imap_message_cache_remove (imap_folder->cache, uid);
 			CAMEL_IMAP_FOLDER_REC_UNLOCK (imap_folder, cache_lock);
-			camel_folder_summary_remove (folder->summary, info);
-			camel_message_info_free(info);
+			camel_folder_summary_remove_uid (folder->summary, uid);
+			g_free (uid);
 		}
 	}
 
@@ -3178,7 +3214,7 @@
 		camel_object_trigger_event (CAMEL_OBJECT (folder), "folder_changed", changes);
 
 	camel_folder_change_info_free (changes);
-	camel_folder_summary_save (folder->summary);
+	camel_folder_summary_save_to_db (folder->summary, ex);
 }
 
 static void

Modified: branches/camel-db-summary/camel/providers/imap/camel-imap-message-cache.c
==============================================================================
--- branches/camel-db-summary/camel/providers/imap/camel-imap-message-cache.c	(original)
+++ branches/camel-db-summary/camel/providers/imap/camel-imap-message-cache.c	Tue Jun 10 12:16:07 2008
@@ -179,12 +179,16 @@
 		else
 			uid = g_strdup (dname);
 
+		if (g_hash_table_lookup (summary->uids, uid))
+			cache_put (cache, uid, dname, NULL);
+
+		/*
 		info = camel_folder_summary_uid (summary, uid);
 		if (info) {
 			camel_message_info_free(info);
 			cache_put (cache, uid, dname, NULL);
 		} else
-			g_ptr_array_add (deletes, g_strdup_printf ("%s/%s", cache->path, dname));
+			g_ptr_array_add (deletes, g_strdup_printf ("%s/%s", cache->path, dname)); */
 		g_free (uid);
 	}
 	g_dir_close (dir);

Modified: branches/camel-db-summary/camel/providers/imap/camel-imap-summary.c
==============================================================================
--- branches/camel-db-summary/camel/providers/imap/camel-imap-summary.c	(original)
+++ branches/camel-db-summary/camel/providers/imap/camel-imap-summary.c	Tue Jun 10 12:16:07 2008
@@ -149,15 +149,18 @@
 camel_imap_summary_new (struct _CamelFolder *folder, const char *filename)
 {
 	CamelFolderSummary *summary = CAMEL_FOLDER_SUMMARY (camel_object_new (camel_imap_summary_get_type ()));
+	CamelException ex;
+	camel_exception_init (&ex);
 
 	summary->folder = folder;
 
 	camel_folder_summary_set_build_content (summary, TRUE);
-	camel_folder_summary_set_filename (summary, filename);
 
-	if (camel_folder_summary_load (summary) == -1) {
-		camel_folder_summary_clear (summary);
-		camel_folder_summary_touch (summary);
+	if (camel_folder_summary_load_from_db (summary, &ex) == -1) {
+		/* FIXME: Isn't this dangerous ? We clear the summary
+		if it cannot be loaded, for some random reason.
+		We need to pass the ex and find out why it is not loaded etc. ? */
+		camel_folder_summary_clear_db (summary);
 	}
 
 	return summary;
@@ -262,7 +265,7 @@
 
 	info = camel_imap_summary_parent->message_info_from_db (s, mir);
 	if (info) {
-		char *part = mir->bdata;
+		char *part = g_strdup (mir->bdata);
 		iinfo = (CamelImapMessageInfo *)info;
 		EXTRACT_FIRST_DIGIT (iinfo->server_flags)
 	}
@@ -337,6 +340,7 @@
 	if (part) {
 		EXTRACT_FIRST_DIGIT (type);
 	}
+
 	if (type)
 		return camel_imap_summary_parent->content_info_from_db (s, mir);
 	else

Modified: branches/camel-db-summary/camel/providers/local/camel-local-summary.c
==============================================================================
--- branches/camel-db-summary/camel/providers/local/camel-local-summary.c	(original)
+++ branches/camel-db-summary/camel/providers/local/camel-local-summary.c	Tue Jun 10 12:16:07 2008
@@ -149,7 +149,7 @@
 local_summary_load(CamelLocalSummary *cls, int forceindex, CamelException *ex)
 {
 	d(g_print ("\nlocal_summary_load called \n"));
-	return camel_folder_summary_load_from_db ((CamelFolderSummary *)cls);
+	return camel_folder_summary_load_from_db ((CamelFolderSummary *)cls, ex);
 }
 
 /* load/check the summary */



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