Index: camel-pop3-folder.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/pop3/camel-pop3-folder.c,v
retrieving revision 1.72
diff -u -p -w -r1.72 camel-pop3-folder.c
--- camel-pop3-folder.c	12 Apr 2006 19:14:16 -0000	1.72
+++ camel-pop3-folder.c	8 Jun 2006 19:27:39 -0000
@@ -300,12 +300,19 @@ pop3_sync (CamelFolder *folder, gboolean
 	int i;
 	CamelPOP3FolderInfo *fi;
 
-	if (!expunge)
-		return;
-
 	pop3_folder = CAMEL_POP3_FOLDER (folder);
 	pop3_store = CAMEL_POP3_STORE (folder->parent_store);
 
+	if(pop3_store->delete_after)
+	{	
+		camel_operation_start(NULL, _("Expunging old messages"));
+		camel_pop3_delete_old(folder, pop3_store->delete_after,ex);	
+	}	
+
+	if (!expunge) {
+		return;
+	}	
+	
 	camel_operation_start(NULL, _("Expunging deleted messages"));
 	
 	for (i = 0; i < pop3_folder->uids->len; i++) {
@@ -342,6 +349,65 @@ pop3_sync (CamelFolder *folder, gboolean
 	camel_operation_end(NULL);
 
 	camel_pop3_store_expunge (pop3_store, ex);
+}
+
+int
+camel_pop3_delete_old(CamelFolder *folder, int days_to_delete,	CamelException *ex)
+{
+	CamelPOP3Folder *pop3_folder;
+	CamelPOP3FolderInfo *fi;
+	int i;
+	CamelPOP3Store *pop3_store;
+	time_t temp;
+
+	pop3_folder = CAMEL_POP3_FOLDER (folder);
+	pop3_store = CAMEL_POP3_STORE (CAMEL_FOLDER(pop3_folder)->parent_store);	
+	temp = time(&temp);
+
+	for (i = 0; i < pop3_folder->uids->len; i++) {
+	fi = pop3_folder->uids->pdata[i];
+
+	CamelMimeMessage *message = pop3_get_message (folder, fi->uid, ex);	
+	time_t message_time = message->date + message->date_offset;
+	if(message) {
+		double time_diff = difftime(temp,message_time);
+		int day_lag = time_diff/(60*60*24);
+		if( day_lag > days_to_delete)
+		{
+			if (fi->cmd) {
+			while (camel_pop3_engine_iterate(pop3_store->engine, fi->cmd) > 0)
+				;
+			camel_pop3_engine_command_free(pop3_store->engine, fi->cmd);
+			fi->cmd = NULL;
+		}
+
+		fi->cmd = camel_pop3_engine_command_new(pop3_store->engine, 0, NULL, NULL, "DELE %u\r\n", fi->id);
+			/* also remove from cache */
+		if (pop3_store->cache && fi->uid)
+			camel_data_cache_remove(pop3_store->cache, "cache", fi->uid, NULL);
+		}
+	     }
+
+	}
+
+	for (i = 0; i < pop3_folder->uids->len; i++) {
+		fi = pop3_folder->uids->pdata[i];
+		/* wait for delete commands to finish */
+		if (fi->cmd) {
+			while (camel_pop3_engine_iterate(pop3_store->engine, fi->cmd) > 0)
+				;
+			camel_pop3_engine_command_free(pop3_store->engine, fi->cmd);
+			fi->cmd = NULL;
+		}
+		camel_operation_progress(NULL, (i+1) * 100 / pop3_folder->uids->len);
+	}
+
+	camel_operation_end(NULL);
+
+	camel_pop3_store_expunge (pop3_store, ex);
+
+	return 0;
+	
 }
 
 static void
Index: camel-pop3-folder.h
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/pop3/camel-pop3-folder.h,v
retrieving revision 1.14
diff -u -p -w -r1.14 camel-pop3-folder.h
--- camel-pop3-folder.h	31 Aug 2005 04:26:04 -0000	1.14
+++ camel-pop3-folder.h	8 Jun 2006 19:27:45 -0000
@@ -70,6 +70,8 @@ CamelFolder *camel_pop3_folder_new (Came
 /* Standard Camel function */
 CamelType camel_pop3_folder_get_type (void);
 
+int camel_pop3_delete_old(CamelFolder *folder, int days_to_delete, CamelException *ex);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
Index: camel-pop3-provider.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/pop3/camel-pop3-provider.c,v
retrieving revision 1.36
diff -u -p -w -r1.36 camel-pop3-provider.c
--- camel-pop3-provider.c	20 Apr 2006 20:24:33 -0000	1.36
+++ camel-pop3-provider.c	8 Jun 2006 19:27:47 -0000
@@ -40,10 +40,8 @@ static CamelProviderConfEntry pop3_conf_
 	  N_("Message storage") },
 	{ CAMEL_PROVIDER_CONF_CHECKBOX, "keep_on_server", NULL,
 	  N_("Leave messages on server"), "0" },
-#ifdef NOT_FOR_1_0
-	{ CAMEL_PROVIDER_CONF_CHECKSPIN, "delete_after", "UNIMPLEMENTED",
+	{ CAMEL_PROVIDER_CONF_CHECKSPIN, "delete_after", NULL,
 	  N_("Delete after %s day(s)"), "0:1:7:365" },
-#endif
 	{ CAMEL_PROVIDER_CONF_CHECKBOX, "disable_extensions", NULL,
 	  N_("Disable support for all POP3 extensions"), "0" },
 	{ CAMEL_PROVIDER_CONF_SECTION_END },
Index: camel-pop3-store.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/pop3/camel-pop3-store.c,v
retrieving revision 1.126
diff -u -p -w -r1.126 camel-pop3-store.c
--- camel-pop3-store.c	31 May 2006 18:55:23 -0000	1.126
+++ camel-pop3-store.c	8 Jun 2006 19:27:52 -0000
@@ -154,6 +154,7 @@ connect_to_server (CamelService *service
 	guint32 flags = 0;
 	int clean_quit = TRUE;
 	int ret;
+	gchar *delete_days;
 	
 	if (ssl_mode != MODE_CLEAR) {
 #ifdef HAVE_SSL
@@ -196,6 +197,9 @@ connect_to_server (CamelService *service
 	
 	if (camel_url_get_param (service->url, "disable_extensions"))
 		flags |= CAMEL_POP3_ENGINE_DISABLE_EXTENSIONS;
+	
+	if ((delete_days = camel_url_get_param(service->url,"delete_after"))) 
+		store->delete_after =  atoi(delete_days);
 	
 	if (!(store->engine = camel_pop3_engine_new (tcp_stream, flags))) {
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
Index: camel-pop3-store.h
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/pop3/camel-pop3-store.h,v
retrieving revision 1.18
diff -u -p -w -r1.18 camel-pop3-store.h
--- camel-pop3-store.h	31 Aug 2005 04:26:04 -0000	1.18
+++ camel-pop3-store.h	8 Jun 2006 19:27:55 -0000
@@ -49,6 +49,8 @@ typedef struct {
 	CamelPOP3Engine *engine; /* pop processing engine */
 
 	struct _CamelDataCache *cache;
+	
+	guint delete_after;
 } CamelPOP3Store;
 
 
