evolution-data-server r8410 - in trunk/camel: . providers/imap



Author: sragavan
Date: Thu Jan 24 03:01:16 2008
New Revision: 8410
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=8410&view=rev

Log:
2008-01-24  Srinivasa Ragavan  <sragavan novell com>

	** Fix for bug #510779 

	* camel-filter-search.c: (junk_test): Add contact lookup and header
	based filtering.
	* camel-folder-summary.c: (message_info_free): Add/Free headers
	fetched into message info.
	* camel-folder-summary.h: Add a headers param into message info
	* camel-private.h: Add junk_headers into the session private which
	holds the junk headers to be extracted.
	* camel-session.c: (camel_session_init), (camel_session_finalise),
	(camel_session_lookup_addressbook),
	(camel_session_set_junk_headers), (camel_session_get_junk_headers):
	* camel-session.h:

2008-01-24  Srinivasa Ragavan  <sragavan novell com>


	* camel-imap-folder.c: (construct_junk_headers),
	(imap_update_summary): Extract the junk specific headers onto the
	headers portion of the message info for fast filtering.

2008-01-22  Srinivasa Ragavan  <sragavan novell com>

	** Fix for bug #481699

	* camel-imap-folder.c (handle_copyuid): Don't crash if the server
	returns you bad COPYUID.




Modified:
   trunk/camel/ChangeLog
   trunk/camel/camel-filter-search.c
   trunk/camel/camel-folder-summary.c
   trunk/camel/camel-folder-summary.h
   trunk/camel/camel-private.h
   trunk/camel/camel-session.c
   trunk/camel/camel-session.h
   trunk/camel/providers/imap/ChangeLog
   trunk/camel/providers/imap/camel-imap-folder.c

Modified: trunk/camel/camel-filter-search.c
==============================================================================
--- trunk/camel/camel-filter-search.c	(original)
+++ trunk/camel/camel-filter-search.c	Thu Jan 24 03:01:16 2008
@@ -58,6 +58,7 @@
 #include "camel-session.h"
 #include "camel-stream-fs.h"
 #include "camel-stream-mem.h"
+#include "camel-string-utils.h"
 #include "camel-url.h"
 
 #define d(x)
@@ -643,9 +644,35 @@
 {
 	ESExpResult *r;
 	gboolean retval = FALSE;
-
+	
+	d(printf("doing junk test for message from '%s'\n", camel_message_info_from (fms->info)));
 	if (fms->session->junk_plugin != NULL) {
-		retval = camel_junk_plugin_check_junk (fms->session->junk_plugin, camel_filter_search_get_message (fms, f));
+		CamelMessageInfo *info = fms->info;
+		const GHashTable *ht = camel_session_get_junk_headers (fms->session);
+		struct _camel_header_param *node = ((CamelMessageInfoBase *)info)->headers;
+
+		while (node && !retval) {
+			if (node->name) {
+				char *value = (char *) g_hash_table_lookup ((GHashTable *) ht, node->name);
+				d(printf("JunkCheckMatch: %s %s %s\n", node->name, node->value, value));
+				if (value)
+					retval = camel_strstrcase(node->value, value) != NULL;
+		
+			}
+			node = node->next;
+		}
+		if (camel_debug ("junk"))
+			printf("filtered based on junk header ? %d\n", retval);
+		if (!retval) {
+			retval = camel_session_lookup_addressbook (fms->session, camel_message_info_from (info)) != TRUE;
+			if (camel_debug ("junk"))
+				printf("Sender '%s' in book? %d\n", camel_message_info_from (info), !retval);
+			
+			if (retval) /* Not in book. Could be spam. So check for it*/ {
+				d(printf("filtering message\n"));
+				retval = camel_junk_plugin_check_junk (fms->session->junk_plugin, camel_filter_search_get_message (fms, f));
+			}
+		}
 
 		if (camel_debug ("junk"))
 			printf("junk filter => %s\n", retval ? "*JUNK*" : "clean");

Modified: trunk/camel/camel-folder-summary.c
==============================================================================
--- trunk/camel/camel-folder-summary.c	(original)
+++ trunk/camel/camel-folder-summary.c	Thu Jan 24 03:01:16 2008
@@ -1981,6 +1981,10 @@
 	g_free(mi->references);
 	camel_flag_list_free(&mi->user_flags);
 	camel_tag_list_free(&mi->user_tags);
+	if (mi->headers)
+		camel_header_param_list_free (mi->headers);
+	
+
 	if (s)
 		e_memchunk_free(s->message_info_chunks, mi);
 	else

Modified: trunk/camel/camel-folder-summary.h
==============================================================================
--- trunk/camel/camel-folder-summary.h	(original)
+++ trunk/camel/camel-folder-summary.h	Thu Jan 24 03:01:16 2008
@@ -179,6 +179,7 @@
 
 	/* tree of content description - NULL if it is not available */
 	CamelMessageContentInfo *content;
+	struct _camel_header_param *headers;
 };
 
 /* probably do this as well, removing CamelFolderChangeInfo and interfaces

Modified: trunk/camel/camel-private.h
==============================================================================
--- trunk/camel/camel-private.h	(original)
+++ trunk/camel/camel-private.h	Thu Jan 24 03:01:16 2008
@@ -99,6 +99,8 @@
 	GThreadPool *thread_pool;
 
 	GHashTable *thread_msg_op;
+	GHashTable *junk_headers;
+	
 };
 
 #define CAMEL_SESSION_LOCK(f, l) \

Modified: trunk/camel/camel-session.c
==============================================================================
--- trunk/camel/camel-session.c	(original)
+++ trunk/camel/camel-session.c	Thu Jan 24 03:01:16 2008
@@ -79,6 +79,7 @@
 	session->priv->thread_id = 1;
 	session->priv->thread_active = g_hash_table_new(NULL, NULL);
 	session->priv->thread_pool = NULL;
+	session->priv->junk_headers = NULL;
 }
 
 static void
@@ -99,7 +100,10 @@
 
 	g_mutex_free(session->priv->lock);
 	g_mutex_free(session->priv->thread_lock);
-
+	if (session->priv->junk_headers) {
+		g_hash_table_remove_all (session->priv->junk_headers);
+		g_hash_table_destroy (session->priv->junk_headers);
+	}
 	g_free(session->priv);
 }
 
@@ -428,6 +432,14 @@
 	return CS_CLASS (session)->alert_user (session, type, prompt, cancel);
 }
 
+gboolean
+camel_session_lookup_addressbook (CamelSession *session, const char *name)
+{
+	g_return_val_if_fail (CAMEL_IS_SESSION (session), FALSE);
+	g_return_val_if_fail (name != NULL, FALSE);
+	return CS_CLASS (session)->lookup_addressbook (session, name);
+}
+
 /**
  * camel_session_build_password_prompt:
  * @type: account type (e.g. "IMAP")
@@ -746,3 +758,26 @@
 
 	session->network_state = network_state;
 }
+
+void
+camel_session_set_junk_headers (CamelSession *session, const char **headers, const char **values, int len)
+{
+	int i;
+
+	if (session->priv->junk_headers) {
+		g_hash_table_remove_all (session->priv->junk_headers);
+		g_hash_table_destroy (session->priv->junk_headers);
+	}
+
+	session->priv->junk_headers = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+
+	for (i=0; i<len; i++) {
+		g_hash_table_insert (session->priv->junk_headers, g_strdup (headers[i]), g_strdup(values[i]));
+	}
+}
+
+const GHashTable *
+camel_session_get_junk_headers (CamelSession *session)
+{
+	return session->priv->junk_headers;
+}

Modified: trunk/camel/camel-session.h
==============================================================================
--- trunk/camel/camel-session.h	(original)
+++ trunk/camel/camel-session.h	Thu Jan 24 03:01:16 2008
@@ -108,6 +108,7 @@
 	int (*thread_queue)(CamelSession *session, CamelSessionThreadMsg *msg, int flags);
 	void (*thread_wait)(CamelSession *session, int id);
 	void (*thread_status)(CamelSession *session, CamelSessionThreadMsg *msg, const char *text, int pc);
+	gboolean (*lookup_addressbook) (CamelSession *session, const char *name);
 } CamelSessionClass;
 
 
@@ -197,6 +198,9 @@
 void camel_session_thread_wait(CamelSession *session, int id);
 gboolean camel_session_get_network_state (CamelSession *session);
 void camel_session_set_network_state (CamelSession *session, gboolean network_state);
+const GHashTable * camel_session_get_junk_headers (CamelSession *session);
+void camel_session_set_junk_headers (CamelSession *session, const char **headers, const char **values, int len);
+gboolean camel_session_lookup_addressbook (CamelSession *session, const char *name);
 
 G_END_DECLS
 

Modified: trunk/camel/providers/imap/camel-imap-folder.c
==============================================================================
--- trunk/camel/providers/imap/camel-imap-folder.c	(original)
+++ trunk/camel/providers/imap/camel-imap-folder.c	Thu Jan 24 03:01:16 2008
@@ -1607,8 +1607,10 @@
 		return;
 	}
 
-	imap_uid_array_free (src);
-	imap_uid_array_free (dest);
+	if (src)
+		imap_uid_array_free (src);
+	if (dest)
+		imap_uid_array_free (dest);
  lose:
 	g_warning ("Bad COPYUID response from server");
 }
@@ -2419,6 +2421,46 @@
 	messages->pdata[seq - first] = mi;
 }
 
+struct _junk_data {
+	GData *data;
+	CamelMessageInfoBase *mi;
+};
+
+static void
+construct_junk_headers (char *header, char *value, struct _junk_data *jdata)	
+{
+	char *bs, *es, *flag=NULL;
+	char *bdata = g_datalist_get_data (&(jdata->data), "BODY_PART_DATA");
+	struct _camel_header_param *node;
+
+	/* FIXME: This can be written in a much clever way.
+	 * We can create HEADERS file or carry all headers till filtering so 
+	 * that header based filtering can be much faster. But all that later. */
+	bs = camel_strstrcase (bdata ? bdata:"", header);
+	if (bs) {
+		bs += strlen(header);
+		bs = strchr (bs, ':');
+		if (bs) {
+			bs++;
+			while (*bs == ' ')
+				bs++;
+			es = strchr (bs, '\n');
+			if (es)
+				flag = g_strndup (bs, es-bs);
+			else
+				bs = NULL;
+		}
+
+	}
+	
+	if (bs) {
+		node = g_new (struct _camel_header_param, 1);
+		node->name = g_strdup (header);
+		node->value = flag;
+		node->next = jdata->mi->headers;
+		jdata->mi->headers = node;
+	}
+}
 
 #define CAMEL_MESSAGE_INFO_HEADERS "DATE FROM TO CC SUBJECT REFERENCES IN-REPLY-TO MESSAGE-ID MIME-VERSION CONTENT-TYPE "
 
@@ -2603,6 +2645,7 @@
 
 	/* Now finish up summary entries (fix UIDs, set flags and size) */
 	for (i = 0; i < fetch_data->len; i++) {
+		struct _junk_data jdata;
 		data = fetch_data->pdata[i];
 
 		seq = GPOINTER_TO_INT (g_datalist_get_data (&data, "SEQUENCE"));
@@ -2663,6 +2706,10 @@
 		if (size)
 			mi->info.size = size;
 
+		/* Just do this to build the junk required headers to be built*/
+		jdata.data = data;
+		jdata.mi = (CamelMessageInfoBase *) mi;
+		g_hash_table_foreach ((GHashTable *)camel_session_get_junk_headers(((CamelService *) store)->session), (GHFunc) construct_junk_headers, &jdata);
 		g_datalist_clear (&data);
 	}
 	g_ptr_array_free (fetch_data, TRUE);
@@ -2699,12 +2746,12 @@
 
 			camel_message_info_free(&info->info);
 			break;
-		}
+		} 
 
 		camel_folder_summary_add (folder->summary, (CamelMessageInfo *)mi);
 		camel_folder_change_info_add_uid (changes, camel_message_info_uid (mi));
 
-		if ((mi->info.flags & CAMEL_IMAP_MESSAGE_RECENT))
+		if ((mi->info.flags & CAMEL_IMAP_MESSAGE_RECENT)) 
 			camel_folder_change_info_recent_uid(changes, camel_message_info_uid (mi));
 	}
 



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