First attempt at POP3 with LOGIN-DELAY



Here's a patch that makes the POP3 code accept LOGIN-DELAY. If
LOGIN-DELAY is not available in the CAPA, 300 is used as a default
value.

This will make the disconnects happen only per LOGIN-DELAY seconds.

Please review carefully yet extensively. This is a high risk patch, but
a necessity with some POP3 servers, like GMail's.


-- 
Philip Van Hoof, freelance software developer
home: me at pvanhoof dot be 
gnome: pvanhoof at gnome dot org 
http://pvanhoof.be/blog
http://codeminded.be



Index: libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-store.h
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-store.h	(revision 2991)
+++ libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-store.h	(working copy)
@@ -49,10 +49,15 @@
 	guint delete_after;
 	gboolean immediate_delete_after;
 	gchar *storage_path, *base_url;
-	gboolean connected, is_refreshing;
+	gboolean connected, logged_in, is_refreshing;
 	GStaticRecMutex *eng_lock;
 	gpointer book;
+	guint login_delay;
 
+	GPtrArray *uids;
+	GHashTable *uids_uid;	/* messageinfo by uid */
+	GHashTable *uids_id;	/* messageinfo by id */
+
 } CamelPOP3Store;
 
 
@@ -72,6 +77,8 @@
 /* Standard Camel function */
 CamelType camel_pop3_store_get_type (void);
 
+void camel_pop3_store_destroy_lists (CamelPOP3Store *pop3_store);
+
 G_END_DECLS
 
 #endif /* CAMEL_POP3_STORE_H */
Index: libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-engine.c
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-engine.c	(revision 2991)
+++ libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-engine.c	(working copy)
@@ -60,6 +60,7 @@
 static void
 camel_pop3_engine_init(CamelPOP3Engine *pe, CamelPOP3EngineClass *peclass)
 {
+	pe->login_delay = 300;
 	pe->lock = g_new0 (GStaticRecMutex, 1);
 	g_static_rec_mutex_init (pe->lock);
 
@@ -208,6 +209,7 @@
 	{ "UIDL", CAMEL_POP3_CAP_UIDL },
 	{ "PIPELINING", CAMEL_POP3_CAP_PIPE },
 	{ "STLS", CAMEL_POP3_CAP_STLS },  /* STARTTLS */
+	{ "LOGIN-DELAY", CAMEL_POP3_CAP_LOGIN_DELAY } 
 };
 
 static int
@@ -242,6 +244,17 @@
 					}
 					tok = next;
 				}
+			} if (strncmp((char *) line, "LOGIN-DELAY", 11) == 0) {
+				char *delay;
+				pe->capa |= CAMEL_POP3_CAP_LOGIN_DELAY;
+				delay = strchr (line, ' ');
+				if (delay) {
+					delay++;
+					pe->login_delay = strtoul (delay, &delay, 10);
+
+					/* printf ("SET DELAY: %s (%d) OVERW 5\n", delay, pe->login_delay);
+					pe->login_delay = 5; */
+				}
 			} else {
 				for (i=0;i<sizeof(capa)/sizeof(capa[0]);i++) {
 					if (strcmp((char *) capa[i].cap, (char *) line) == 0)
Index: libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-engine.h
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-engine.h	(revision 2991)
+++ libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-engine.h	(working copy)
@@ -67,7 +67,8 @@
 	CAMEL_POP3_CAP_SASL = 1<<2,
 	CAMEL_POP3_CAP_TOP  = 1<<3,
 	CAMEL_POP3_CAP_PIPE = 1<<4,
-	CAMEL_POP3_CAP_STLS = 1<<5
+	CAMEL_POP3_CAP_STLS = 1<<5,
+	CAMEL_POP3_CAP_LOGIN_DELAY = 1<<5
 };
 
 /* enable/disable flags for the engine itself */
@@ -117,6 +118,7 @@
 	CamelPOP3Command *current; /* currently busy (downloading) response */
 	void *store; gboolean partial_happening;
 	gint type; gint param;
+	guint login_delay;
 
 	GStaticRecMutex *lock;
 };
Index: libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-folder.c
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-folder.c	(revision 2997)
+++ libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-folder.c	(working copy)
@@ -83,55 +83,9 @@
 
 
 static void
-destroy_lists (CamelPOP3Folder *pop3_folder)
-{
-	CamelPOP3Store *pop3_store = (CamelPOP3Store *)((CamelFolder *)pop3_folder)->parent_store;
-
-	g_static_rec_mutex_lock (pop3_store->eng_lock);
-
-	if (pop3_folder->uids != NULL)
-	{
-		CamelPOP3FolderInfo **fi = (CamelPOP3FolderInfo **)pop3_folder->uids->pdata;
-		int i;
-
-		for (i=0;i<pop3_folder->uids->len;i++,fi++) {
-			if (fi[0]->cmd) {
-
-				if (pop3_store->engine == NULL) {
-					g_ptr_array_free(pop3_folder->uids, TRUE);
-					g_hash_table_destroy(pop3_folder->uids_uid);
-					g_free(fi[0]->uid);
-					g_free(fi[0]);
-					g_static_rec_mutex_unlock (pop3_store->eng_lock);
-					return;
-				}
-
-				while (camel_pop3_engine_iterate(pop3_store->engine, fi[0]->cmd) > 0)
-					;
-				camel_pop3_engine_command_free(pop3_store->engine, fi[0]->cmd);
-
-			}
-
-			g_free(fi[0]->uid);
-			g_free(fi[0]);
-		}
-
-		g_ptr_array_free(pop3_folder->uids, TRUE);
-		pop3_folder->uids = NULL;
-		g_hash_table_destroy(pop3_folder->uids_uid);
-	}
-
-	g_static_rec_mutex_unlock (pop3_store->eng_lock);
-
-}
-
-static void
 pop3_finalize (CamelObject *object)
 {
-	CamelPOP3Folder *pop3_folder = CAMEL_POP3_FOLDER (object);
-
-	destroy_lists (pop3_folder);
-
+	return;
 }
 
 static void
@@ -153,8 +107,8 @@
 
 	folder = CAMEL_FOLDER (camel_object_new (CAMEL_POP3_FOLDER_TYPE));
 	pop3_folder = CAMEL_POP3_FOLDER (folder);
-	pop3_folder->uids = NULL;
 
+
 	camel_folder_construct (folder, parent, "inbox", "inbox");
 
 	summary_file = g_strdup_printf ("%s/summary.mmap", p3store->storage_path);
@@ -263,11 +217,11 @@
 				fi = g_malloc0 (sizeof(*fi));
 				fi->size = size;
 				fi->id = id;
-				fi->index = ((CamelPOP3Folder *)folder)->uids->len;
+				fi->index = pop3_store->uids->len;
 				if ((pop3_store->engine && pop3_store->engine->capa & CAMEL_POP3_CAP_UIDL) == 0)
 					fi->cmd = camel_pop3_engine_command_new(pe, CAMEL_POP3_COMMAND_MULTI, cmd_builduid, fi, "TOP %u 0\r\n", id);
-				g_ptr_array_add(((CamelPOP3Folder *)folder)->uids, fi);
-				g_hash_table_insert(((CamelPOP3Folder *)folder)->uids_id, GINT_TO_POINTER(id), fi);
+				g_ptr_array_add(pop3_store->uids, fi);
+				g_hash_table_insert(pop3_store->uids_id, GINT_TO_POINTER(id), fi);
 			}
 		}
 	} while (ret>0);
@@ -285,6 +239,7 @@
 	unsigned int id;
 	CamelPOP3FolderInfo *fi;
 	CamelPOP3Folder *folder = data;
+	CamelPOP3Store *pop3_store = (CamelPOP3Store*) ((CamelFolder *)folder)->parent_store;
 
 	do {
 		ret = camel_pop3_stream_line(stream, &line, &len);
@@ -292,12 +247,12 @@
 			if (strlen((char*) line) > 1024)
 				line[1024] = 0;
 			if (sscanf((char *) line, "%u %s", &id, uid) == 2) {
-				fi = g_hash_table_lookup(folder->uids_id, GINT_TO_POINTER(id));
+				fi = g_hash_table_lookup(pop3_store->uids_id, GINT_TO_POINTER(id));
 				if (fi) {
-					camel_operation_progress(NULL, (fi->index+1) , folder->uids->len);
+					camel_operation_progress(NULL, (fi->index+1) , pop3_store->uids->len);
 					fi->uid = g_strdup(uid);
 					pop3_debug ("%s added\n", fi->uid);
-					g_hash_table_insert(folder->uids_uid, fi->uid, fi);
+					g_hash_table_insert(pop3_store->uids_uid, fi->uid, fi);
 				} else {
 					g_warning("ID %u (uid: %s) not in previous LIST output", id, uid);
 				}
@@ -333,16 +288,8 @@
 		}
 	}
 
-	destroy_lists (pop3_folder);
-
-	pop3_folder->uids = g_ptr_array_new ();
-	pop3_folder->uids_uid = g_hash_table_new(g_str_hash, g_str_equal);
-	/* only used during setup */
-	pop3_folder->uids_id = g_hash_table_new(NULL, NULL);
-
 	camel_operation_start (NULL, _("Fetching summary information for new messages in folder"));
 
-
 	if (pop3_store->engine == NULL) {
 		pop3_store->is_refreshing = FALSE;
 		g_static_rec_mutex_unlock (pop3_store->eng_lock);
@@ -386,8 +333,8 @@
 
 	camel_pop3_logbook_open (pop3_store->book);
 
-	for (i=0;i<pop3_folder->uids->len;i++) {
-		CamelPOP3FolderInfo *fi = pop3_folder->uids->pdata[i];
+	for (i=0;i<pop3_store->uids->len;i++) {
+		CamelPOP3FolderInfo *fi = pop3_store->uids->pdata[i];
 		CamelMessageInfoBase *mi = NULL;
 
 		mi = (CamelMessageInfoBase*) camel_folder_summary_uid (folder->summary, fi->uid);
@@ -443,13 +390,7 @@
 				{
 					/* Periodically save the summary (this reduces
 					   memory usage too) */
-
-					if (camel_folder_summary_save (folder->summary, ex) == -1)
-					{
-						camel_service_disconnect (CAMEL_SERVICE (pop3_store), FALSE, NULL);
-						break;
-					}
-
+					camel_folder_summary_save (folder->summary, ex);
 					hcnt = 0;
 				}
 
@@ -462,7 +403,7 @@
 		} else if (mi)
 			camel_message_info_free (mi);
 
-		camel_operation_progress (NULL, i , pop3_folder->uids->len);
+		camel_operation_progress (NULL, i , pop3_store->uids->len);
 
 	}
 
@@ -491,15 +432,15 @@
 		if (pop3_store->engine->capa & CAMEL_POP3_CAP_UIDL) {
 			camel_pop3_engine_command_free(pop3_store->engine, pcu);
 		} else {
-			for (i=0;i<pop3_folder->uids->len;i++) {
-				CamelPOP3FolderInfo *fi = pop3_folder->uids->pdata[i];
+			for (i=0;i<pop3_store->uids->len;i++) {
+				CamelPOP3FolderInfo *fi = pop3_store->uids->pdata[i];
 
 				if (fi->cmd) {
 					camel_pop3_engine_command_free(pop3_store->engine, fi->cmd);
 					fi->cmd = NULL;
 				}
 				if (fi->uid)
-					g_hash_table_insert(pop3_folder->uids_uid, fi->uid, fi);
+					g_hash_table_insert(pop3_store->uids_uid, fi->uid, fi);
 			}
 		}
 	}
@@ -512,12 +453,8 @@
 	pop3_store->is_refreshing = FALSE;
 
 	/* dont need this anymore */
-	g_hash_table_destroy(pop3_folder->uids_id);
-
 	camel_operation_end (NULL);
 
-	camel_service_disconnect (CAMEL_SERVICE (pop3_store), TRUE, &dex);
-
 	return;
 }
 
@@ -559,7 +496,6 @@
 	}
 
 	if (!expunge) {
-		camel_service_disconnect (CAMEL_SERVICE (pop3_store), TRUE, &dex);
 		g_static_rec_mutex_unlock (pop3_store->eng_lock);
 		return;
 	}
@@ -607,9 +543,9 @@
 		} else {
 			gboolean found = FALSE;
 			gint t=0;
-			for (t=0; t < pop3_folder->uids->len; t++)
+			for (t=0; t < pop3_store->uids->len; t++)
 			{
-				CamelPOP3FolderInfo *fi2 = pop3_folder->uids->pdata[t];
+				CamelPOP3FolderInfo *fi2 = pop3_store->uids->pdata[t];
 				if (fi2 && fi2->uid && !strcmp (fi2->uid, info->uid)) {
 					found = TRUE;
 					break;
@@ -654,8 +590,6 @@
 
 	camel_folder_summary_save (folder->summary, ex);
 
-	camel_service_disconnect (CAMEL_SERVICE (pop3_store), TRUE, &dex);
-
 	return;
 }
 
@@ -686,10 +620,10 @@
 		}
 	}
 
-	for (i = 0; i < pop3_folder->uids->len; i++) {
+	for (i = 0; i < pop3_store->uids->len; i++) {
 		CamelMimeMessage *message = NULL;
 
-		fi = pop3_folder->uids->pdata[i];
+		fi = pop3_store->uids->pdata[i];
 
 		if (pop3_store->cache && fi->uid && !camel_data_cache_is_partial(pop3_store->cache, "cache", fi->uid))
 			message = pop3_get_message (folder, fi->uid, CAMEL_FOLDER_RECEIVE_FULL, -1, ex);
@@ -722,8 +656,8 @@
 
 	}
 
-	for (i = 0; i < pop3_folder->uids->len; i++) {
-		fi = pop3_folder->uids->pdata[i];
+	for (i = 0; i < pop3_store->uids->len; i++) {
+		fi = pop3_store->uids->pdata[i];
 		/* wait for delete commands to finish */
 		if (fi->cmd) {
 			while (camel_pop3_engine_iterate(pop3_store->engine, fi->cmd) > 0)
@@ -731,7 +665,7 @@
 			camel_pop3_engine_command_free(pop3_store->engine, fi->cmd);
 			fi->cmd = NULL;
 		}
-		camel_operation_progress(NULL, (i+1) , pop3_folder->uids->len);
+		camel_operation_progress(NULL, (i+1) , pop3_store->uids->len);
 	}
 
 	camel_operation_end(NULL);
@@ -968,8 +902,8 @@
 		return NULL;
 	}
 
-	if (pop3_store->is_refreshing && pop3_folder->uids_uid)
-		fi = g_hash_table_lookup(pop3_folder->uids_uid, uid);
+	if (pop3_store->uids_uid)
+		fi = g_hash_table_lookup(pop3_store->uids_uid, uid);
 	else 
 		fi = NULL;
 
@@ -978,11 +912,9 @@
 	{
 		CamelPOP3Command *pcl, *pcu = NULL;
 
+		g_static_rec_mutex_lock (pop3_store->eng_lock);
 		if (!pop3_store->is_refreshing) 
 		{
-
-			g_static_rec_mutex_lock (pop3_store->eng_lock);
-
 			if (pop3_store->engine == NULL)
 			{
 				camel_service_connect (CAMEL_SERVICE (pop3_store), ex);
@@ -992,31 +924,35 @@
 				}
 			}
 
-			destroy_lists (pop3_folder);
-			pop3_folder->uids = g_ptr_array_new ();
-			pop3_folder->uids_uid = g_hash_table_new(g_str_hash, g_str_equal);
-			/* only used during setup */
-			pop3_folder->uids_id = g_hash_table_new(NULL, NULL);
-			pop3_store->is_refreshing = TRUE;
+			camel_pop3_store_destroy_lists (pop3_store);
 			pcl = camel_pop3_engine_command_new(pop3_store->engine, CAMEL_POP3_COMMAND_MULTI, cmd_list, folder, "LIST\r\n");
 			if (pop3_store->engine->capa & CAMEL_POP3_CAP_UIDL)
 				pcu = camel_pop3_engine_command_new(pop3_store->engine, CAMEL_POP3_COMMAND_MULTI, cmd_uidl, folder, "UIDL\r\n");
 			while ((i = camel_pop3_engine_iterate(pop3_store->engine, NULL)) > 0)
 				;
-			pop3_store->is_refreshing = FALSE;
-
-			fi = g_hash_table_lookup(pop3_folder->uids_uid, uid);
-
-			g_static_rec_mutex_unlock (pop3_store->eng_lock);
+			fi = g_hash_table_lookup(pop3_store->uids_uid, uid);
 		}
+		g_static_rec_mutex_unlock (pop3_store->eng_lock);
 
 rfail:
 		if (fi == NULL) {
+
+			/* This means that we have a UIDL locally, that we no longer
+			 * have remotely (POP servers sometimes do this kind of
+			 * funny things, especially if they have web access and
+			 * the user has a delete-mail finger  ... ) */
+
 			CamelFolder *folder = (CamelFolder *) pop3_folder;
 			CamelMessageInfo *mi = camel_folder_summary_uid (folder->summary, uid);
 			if (mi) {
+				CamelFolderChangeInfo *changes = camel_folder_change_info_new ();
 				((CamelMessageInfoBase*)mi)->flags |= CAMEL_MESSAGE_EXPUNGED;
+				if (mi->uid) {
+					camel_folder_change_info_remove_uid (changes, mi->uid);
+					camel_object_trigger_event (CAMEL_OBJECT (folder), "folder_changed", changes);
+				}
 				camel_folder_summary_remove (folder->summary, mi);
+				camel_folder_change_info_free (changes);
 				camel_message_info_free (mi);
 			}
 
@@ -1253,11 +1189,6 @@
 fail:
 	camel_operation_end(NULL);
 
-	g_static_rec_mutex_lock (pop3_store->eng_lock);
-	if (pop3_store->is_refreshing == FALSE)
-		camel_service_disconnect (CAMEL_SERVICE (pop3_store), TRUE, &dex);
-	g_static_rec_mutex_unlock (pop3_store->eng_lock);
-
     retry++;
   }
 
@@ -1297,7 +1228,7 @@
 		}
 	}
 
-	fi = g_hash_table_lookup(pop3_folder->uids_uid, uid);
+	fi = g_hash_table_lookup(pop3_store->uids_uid, uid);
 
 	if (fi == NULL) {
 		camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID,
@@ -1468,8 +1399,9 @@
 	CamelPOP3FolderInfo *fi;
 	gboolean res = FALSE;
 	CamelMessageInfo *info;
+	CamelPOP3Store *pop3_store = (CamelPOP3Store*) ((CamelFolder *)folder)->parent_store;
 
-	fi = g_hash_table_lookup(pop3_folder->uids_uid, uid);
+	fi = g_hash_table_lookup(pop3_store->uids_uid, uid);
 	if (fi) {
 		guint32 new = (fi->flags & ~flags) | (set & flags);
 
@@ -1494,11 +1426,12 @@
 pop3_get_uids (CamelFolder *folder)
 {
 	CamelPOP3Folder *pop3_folder = CAMEL_POP3_FOLDER (folder);
+	CamelPOP3Store *pop3_store = (CamelPOP3Store*) ((CamelFolder *) pop3_folder)->parent_store;
 	GPtrArray *uids = g_ptr_array_new();
-	CamelPOP3FolderInfo **fi = (CamelPOP3FolderInfo **)pop3_folder->uids->pdata;
+	CamelPOP3FolderInfo **fi = (CamelPOP3FolderInfo **)pop3_store->uids->pdata;
 	int i;
 
-	for (i=0;i<pop3_folder->uids->len;i++,fi++) {
+	for (i=0;i<pop3_store->uids->len;i++,fi++) {
 		if (fi[0]->uid)
 			g_ptr_array_add(uids, fi[0]->uid);
 	}
Index: libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-folder.h
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-folder.h	(revision 2991)
+++ libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-folder.h	(working copy)
@@ -50,10 +50,6 @@
 
 typedef struct {
 	CamelDiscoFolder parent_object;
-
-	GPtrArray *uids;
-	GHashTable *uids_uid;	/* messageinfo by uid */
-	GHashTable *uids_id;	/* messageinfo by id */
 } CamelPOP3Folder;
 
 typedef struct {
Index: libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-store.c
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-store.c	(revision 2991)
+++ libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-store.c	(working copy)
@@ -288,6 +288,90 @@
 #define STARTTLS_FLAGS (CAMEL_TCP_STREAM_SSL_ENABLE_TLS)
 #endif
 
+static void 
+kill_lists (CamelPOP3Store *pop3_store)
+{
+	if (pop3_store->uids)
+		g_ptr_array_free(pop3_store->uids, TRUE);
+	pop3_store->uids = NULL;
+	if (pop3_store->uids_uid)
+		g_hash_table_destroy(pop3_store->uids_uid);
+	if (pop3_store->uids_id)
+		g_hash_table_destroy(pop3_store->uids_id);
+}
+
+void
+camel_pop3_store_destroy_lists (CamelPOP3Store *pop3_store)
+{
+	g_static_rec_mutex_lock (pop3_store->eng_lock);
+
+	if (pop3_store->uids != NULL)
+	{
+		CamelPOP3FolderInfo **fi = (CamelPOP3FolderInfo **) pop3_store->uids->pdata;
+		int i;
+
+		for (i=0;i<pop3_store->uids->len;i++,fi++) {
+			if (fi[0]->cmd) {
+
+				if (pop3_store->engine == NULL) {
+					g_ptr_array_free(pop3_store->uids, TRUE);
+					g_hash_table_destroy(pop3_store->uids_uid);
+					g_free(fi[0]->uid);
+					g_free(fi[0]);
+					g_static_rec_mutex_unlock (pop3_store->eng_lock);
+					return;
+				}
+
+				while (camel_pop3_engine_iterate(pop3_store->engine, fi[0]->cmd) > 0)
+					;
+				camel_pop3_engine_command_free(pop3_store->engine, fi[0]->cmd);
+			}
+
+			g_free(fi[0]->uid);
+			g_free(fi[0]);
+		}
+
+		kill_lists (pop3_store);
+
+		pop3_store->uids = g_ptr_array_new ();
+		pop3_store->uids_uid = g_hash_table_new(g_str_hash, g_str_equal);
+		pop3_store->uids_id = g_hash_table_new(NULL, NULL);
+
+	}
+
+	g_static_rec_mutex_unlock (pop3_store->eng_lock);
+
+}
+
+static gpointer
+wait_for_login_delay (gpointer user_data)
+{
+	CamelPOP3Store *store = CAMEL_POP3_STORE (user_data);
+	gboolean killed = FALSE;
+	guint login_delay = 300;
+
+	g_static_rec_mutex_lock (store->eng_lock);
+	login_delay = store->engine->login_delay;
+	g_static_rec_mutex_unlock (store->eng_lock);
+
+	while (!killed) {
+
+		sleep (login_delay);
+
+		g_static_rec_mutex_lock (store->eng_lock);
+		if (!store->is_refreshing) {
+			CamelException dex = CAMEL_EXCEPTION_INITIALISER;
+			camel_pop3_store_destroy_lists (store);
+			camel_service_disconnect (CAMEL_SERVICE (store), TRUE, &dex);
+			killed = TRUE;
+		}
+		g_static_rec_mutex_unlock (store->eng_lock);
+	}
+
+	camel_object_unref (store);
+	return NULL;
+}
+
 static gboolean
 connect_to_server (CamelService *service, struct addrinfo *ai, int ssl_mode, int must_tls, CamelException *ex)
 {
@@ -336,12 +420,6 @@
 		return FALSE;
 	}
 
-	/* parent class connect initialization */
-	/*if (CAMEL_SERVICE_CLASS (parent_class)->connect (service, ex) == FALSE) {
-		camel_object_unref (tcp_stream);
-		return FALSE;
-	}*/
-
 	if (camel_url_get_param (service->url, "disable_extensions"))
 		flags |= CAMEL_POP3_ENGINE_DISABLE_EXTENSIONS;
 
@@ -431,6 +509,8 @@
 	camel_pop3_engine_reget_capabilities (store->engine);
 	store->connected = TRUE;
 
+	camel_object_ref (store);
+
 	g_static_rec_mutex_unlock (store->eng_lock); /* ! */
 
 	return TRUE;
@@ -787,6 +867,9 @@
 	char *errbuf = NULL;
 	int status;
 
+	if (store->logged_in)
+		return TRUE;
+
 	session = camel_service_get_session (service);
 
 	if (!connect_to_server_wrapper (service, ex))
@@ -828,6 +911,8 @@
 	store->engine->state = CAMEL_POP3_ENGINE_TRANSACTION;
 	camel_pop3_engine_reget_capabilities (store->engine);
 
+	g_thread_create (wait_for_login_delay, store, FALSE, NULL);
+
 	g_static_rec_mutex_unlock (store->eng_lock);
 
 	return TRUE;
@@ -839,6 +924,8 @@
 	CamelPOP3Store *store = CAMEL_POP3_STORE (service);
 
 	g_static_rec_mutex_lock (store->eng_lock);
+	store->logged_in = FALSE;
+
 	if (store->engine == NULL) {
 		g_static_rec_mutex_unlock (store->eng_lock);
 		return TRUE;
@@ -901,6 +988,8 @@
 	g_free (pop3_store->eng_lock);
 	pop3_store->eng_lock = NULL;
 
+	kill_lists (pop3_store);
+
 	camel_object_unref (pop3_store->book);
 	pop3_store->book = NULL;
 	return;
@@ -1072,6 +1161,10 @@
 {
 	CamelPOP3Store *store = (CamelPOP3Store *) object;
 
+	store->uids = g_ptr_array_new ();
+	store->uids_uid = g_hash_table_new(g_str_hash, g_str_equal);
+	store->uids_id = g_hash_table_new(NULL, NULL);
+
 	store->is_refreshing = FALSE;
 	store->immediate_delete_after = FALSE;
 	store->book = camel_pop3_logbook_new (store);


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