evolution-data-server r9099 - branches/camel-db-summary/camel



Author: psankar
Date: Tue Jul  8 16:11:22 2008
New Revision: 9099
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=9099&view=rev

Log:
Search on flags initial commit.

Quick show works beautifully. 

Ask psankar for evolution side patch as there is no svn branch for evo.



Modified:
   branches/camel-db-summary/camel/camel-db.c
   branches/camel-db-summary/camel/camel-folder-search.c

Modified: branches/camel-db-summary/camel/camel-db.c
==============================================================================
--- branches/camel-db-summary/camel/camel-db.c	(original)
+++ branches/camel-db-summary/camel/camel-db.c	Tue Jul  8 16:11:22 2008
@@ -1,4 +1,28 @@
-/* Srinivasa Ragavan - <sragavan novell com> - GPL v2 or later */
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* camel-imap-folder.c: class for an imap folder */
+
+/* 
+ * Authors:
+ *   Sankar P <psankar novell com>
+ *   Srinivasa Ragavan <sragavan novell com> 
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ * This program is free software; you can redistribute it and/or 
+ * modify it under the terms of version 2 of the GNU Lesser General Public 
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
 
 #include "camel-db.h"
 #include "camel-string-utils.h"
@@ -11,7 +35,7 @@
 #include <glib.h>
 #include <glib/gi18n-lib.h>
 
-#define d(x)
+#define d(x) 
 
 #define CAMEL_DB_SLEEP_INTERVAL 1*10*10
 #define CAMEL_DB_RELEASE_SQLITE_MEMORY if(!g_getenv("CAMEL_SQLITE_PRESERVE_CACHE")) sqlite3_release_memory(CAMEL_DB_FREE_CACHE_SIZE);
@@ -360,6 +384,8 @@
 	if (!cdb)
 		return TRUE;
 	
+	d(g_print ("\n%s:\n%s \n", __FUNCTION__, stmt));
+
 	ret = sqlite3_exec(cdb->db, stmt, callback, data, &errmsg);
 	while (ret == SQLITE_BUSY || ret == SQLITE_LOCKED) {
 		ret = sqlite3_exec (cdb->db, stmt, callback, data, &errmsg);
@@ -667,8 +693,6 @@
 	char *query;
 	int ret;
 
-	d(g_print ("\ncamel_db_read_folder_info_record called \n"));
-
 	query = sqlite3_mprintf ("SELECT * FROM folders WHERE folder_name = %Q", folder_name);
 	ret = camel_db_select (cdb, query, read_fir_callback, record, ex);
 
@@ -813,14 +837,20 @@
 
 char * camel_db_get_column_name (const char *raw_name)
 {
+	d(g_print ("\n\aRAW name is : [%s] \n\a", raw_name));
 	if (!g_ascii_strcasecmp (raw_name, "Subject"))
 		return g_strdup ("subject");
 	else if (!g_ascii_strcasecmp (raw_name, "from"))
 		return g_strdup ("mail_from");
+	else if (!g_ascii_strcasecmp (raw_name, "Cc"))
+		return g_strdup ("mail_cc");
+	else if (!g_ascii_strcasecmp (raw_name, "To"))
+		return g_strdup ("mail_to");
 	else {
 		/* Let it crash for all unknown columns for now. 
 		We need to load the messages into memory and search etc. */
-		return NULL;
+
+		return g_strdup ("");
 	}
 
 }

Modified: branches/camel-db-summary/camel/camel-folder-search.c
==============================================================================
--- branches/camel-db-summary/camel/camel-folder-search.c	(original)
+++ branches/camel-db-summary/camel/camel-folder-search.c	Tue Jul  8 16:11:22 2008
@@ -404,7 +404,7 @@
 				char *uid = g_ptr_array_index(search->summary, i);
 				if (g_hash_table_lookup(results, uid)) {
 //					g_ptr_array_add(matches, e_mempool_strdup(pool, uid));
-					g_ptr_array_add(matches, camel_pstring_strdup(uid));
+					g_ptr_array_add(matches, (char *) camel_pstring_strdup(uid));
 				}
 			}
 			g_hash_table_destroy(results);
@@ -412,7 +412,7 @@
 			for (i=0;i<r->value.ptrarray->len;i++) {
 				d(printf("adding match: %s\n", (char *)g_ptr_array_index(r->value.ptrarray, i)));
 //				g_ptr_array_add(matches, e_mempool_strdup(pool, g_ptr_array_index(r->value.ptrarray, i)));
-				g_ptr_array_add(matches, camel_pstring_strdup(g_ptr_array_index(r->value.ptrarray, i)));
+				g_ptr_array_add(matches, (char *) camel_pstring_strdup(g_ptr_array_index(r->value.ptrarray, i)));
 			}
 		}
 		/* instead of putting the mempool_hash in the structure, we keep the api clean by
@@ -501,8 +501,8 @@
 		goto fail;
 	}
 
-	d(printf ("\nsexp is : [%s]\n", expr));
-	printf ("Something is returned in the top-level caller : [%s]\n", search->query->str);
+	r(printf ("\nsexp is : [%s]\n", expr));
+	r(printf ("Something is returned in the top-level caller : [%s]\n", search->query->str));
 
 	matches = g_ptr_array_new();
 	cdb = (CamelDB *) (search->folder->cdb);
@@ -532,10 +532,10 @@
 
 void camel_folder_search_free_result(CamelFolderSearch *search, GPtrArray *result)
 {
+#if 0
 	int i;
 	struct _CamelFolderSearchPrivate *p = _PRIVATE(search);
 	EMemPool *pool;
-#if 0
 	pool = g_hash_table_lookup(p->mempool_hash, result);
 	if (pool) {
 		e_mempool_destroy(pool);
@@ -545,7 +545,7 @@
 			g_free(g_ptr_array_index(result, i));
 	}
 #endif
-	g_ptr_array_foreach (result, camel_pstring_free, NULL);
+	g_ptr_array_foreach (result, (GFunc) camel_pstring_free, NULL);
 	g_ptr_array_free(result, TRUE);
 }
 
@@ -953,6 +953,7 @@
 				temp = g_strdup_printf ("%s", argv [1]->value.string);
 				break;
 			case CAMEL_SEARCH_MATCH_CONTAINS:
+			case CAMEL_SEARCH_MATCH_SOUNDEX:
 				temp = g_strdup_printf ("%%%s%%", argv [1]->value.string);
 				break;
 			case CAMEL_SEARCH_MATCH_STARTS:
@@ -1313,30 +1314,42 @@
 static ESExpResult *
 search_user_flag(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *search)
 {
-	ESExpResult *r;
-	int i;
+		char *value = NULL;
+		ESExpResult *r;
+		char * tmp;
 
-	r(printf("executing user-flag\n"));
+		r(printf("\nexecuting user-flag with init str: [%s]\n", search->query->str));
+
+		if (argc == 1) {
+
+				if (search->current) {
+						/* FIXME: I am not sure if this will ever be executed */
+						abort ();
+				} else {
+						tmp = g_strdup_printf ("%%%s%%", argv[0]->value.string);
+						value = camel_db_sqlize_string (tmp);
+						g_free (tmp);
+
+						if (g_str_has_suffix (search->query->str, " ")) {
+								g_string_append_printf (search->query, "WHERE labels LIKE %s", value);
+						} else {
+								if (f->operators) {
+										g_string_append_printf (search->query, " %s labels LIKE %s", (char *) (g_slist_nth_data (f->operators, 0)), value);
+								} else {
+										g_string_append_printf (search->query, " OR labels LIKE %s", value);
+								}
+						}
+
+						r(printf ("user-flag search value is : [%s] Appended str is : [%s]\n\n", value, search->query->str));
+						camel_db_free_sqlized_string (value);
+				}
+		} else
+				g_warning ("Makes no sense to search for multiple things in user flag. A flag is either set or not that's all");
 
-	/* are we inside a match-all? */
-	if (search->current) {
-		int truth = FALSE;
-		/* performs an OR of all words */
-		for (i=0;i<argc && !truth;i++) {
-			if (argv[i]->type == ESEXP_RES_STRING
-			    && camel_message_info_user_flag(search->current, argv[i]->value.string)) {
-				truth = TRUE;
-				break;
-			}
-		}
 		r = e_sexp_result_new(f, ESEXP_RES_BOOL);
-		r->value.bool = truth;
-	} else {
-		r = e_sexp_result_new(f, ESEXP_RES_ARRAY_PTR);
-		r->value.ptrarray = g_ptr_array_new();
-	}
+		r->value.bool = FALSE;
 
-	return r;
+		return r;
 }
 
 static ESExpResult *
@@ -1365,18 +1378,42 @@
 static ESExpResult *
 search_user_tag(struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFolderSearch *search)
 {
-	const char *value = NULL;
-	ESExpResult *r;
-	
-	r(printf("executing user-tag\n"));
-	
-	if (argc == 1)
-		value = camel_message_info_user_tag(search->current, argv[0]->value.string);
-	
-	r = e_sexp_result_new(f, ESEXP_RES_STRING);
-	r->value.string = g_strdup (value ? value : "");
-	
-	return r;
+		char *value = NULL;
+		ESExpResult *r;
+		char * tmp;
+
+		r(printf("executing user-tag\n"));
+
+		if (argc == 2) {
+
+				if (search->current) {
+						/* FIXME: I am not sure if this will ever be executed */
+						abort ();
+				} else {
+
+						tmp = g_strdup_printf ("%s%s", argv[0]->value.string, argv[1]->value.string);
+						value = camel_db_sqlize_string (tmp);
+						g_free (tmp);
+
+						if (g_str_has_suffix (search->query->str, " "))
+								g_string_append_printf (search->query, "WHERE usertags = %s", value);
+						else {
+								if (f->operators)
+										g_string_append_printf (search->query, " %s usertags = %s", (char *) (g_slist_nth_data (f->operators, 0)), value);
+								else
+										g_string_append_printf (search->query, " OR usertags = %s", value);
+						}
+
+						camel_db_free_sqlized_string (value);
+
+				}
+		} else
+				g_warning ("Makes no sense to search for multiple things in user tag as it can hold only one string data");
+
+		r = e_sexp_result_new(f, ESEXP_RES_BOOL);
+		r->value.bool = FALSE;
+
+		return r;
 }
 
 static ESExpResult *
@@ -1500,7 +1537,7 @@
 			g_ptr_array_add (matches, g_strdup (cols [i]));
 	}
 #else
-	g_ptr_array_add (matches, camel_pstring_strdup (cols [0]));
+	g_ptr_array_add (matches, (GFunc) camel_pstring_strdup (cols [0]));
 #endif
 	return 0;
 }



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