Index: addressbook/ChangeLog
===================================================================
--- addressbook/ChangeLog	(revision 7761)
+++ addressbook/ChangeLog	(working copy)
@@ -1,3 +1,13 @@
+2007-05-18  Milan Crha  <mcrha@redhat.com>
+
+	** Fix bug #304029
+	* backends/ldap/e-book-backend-ldap.c (extend_query_value),
+	(func_contains, func_is, func_beginswith, func_endswith):
+	added new function extend_query_value which replace first space between
+	words and for a star character '*' instead. This was added on a result of
+	rfc2254_escape call. Also removed two leaks from func_contains and
+	func_beginswith.
+
 2007-05-16  Jules Colding  <colding@omesc.com>
 
 	* backends/vcf/e-book-backend-vcf.c (load_file): Fix file descriptor leak.
Index: addressbook/backends/ldap/e-book-backend-ldap.c
===================================================================
--- addressbook/backends/ldap/e-book-backend-ldap.c	(revision 7761)
+++ addressbook/backends/ldap/e-book-backend-ldap.c	(working copy)
@@ -3329,6 +3329,42 @@
 	}
 }
 
+/** for each first space in a sequence of spaces in @param str it will exchange
+ * that first with a '*' character, but only if that space is
+ * not at the beginning or at the end of the str.
+ * Return value is changed @param str. (ie. this function is changeing
+ * str itself, didn't alocate new memory.)
+ */
+static char *
+extend_query_value(char *str)
+{
+	if(str && g_utf8_strlen(str,-1)>0){
+		char *next;
+		char *last_star = NULL;
+		gboolean have_nonspace = FALSE;
+
+		for (next = g_utf8_next_char(str); next && *next; next = g_utf8_next_char (next) ){
+			if (*next == ' '){
+				if (have_nonspace && !last_star){
+					/* exchange only first space after nonspace character */
+					*next = '*';
+					last_star = next;
+				}
+			}else{
+				have_nonspace = TRUE;
+				last_star = NULL;
+			}
+		}
+
+		if (last_star){
+			/* we placed a star at the end of str, so make it back a space */
+			*last_star = ' ';
+		}
+	}
+
+	return str;
+}
+
 static ESExpResult *
 func_and(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data)
 {
@@ -3432,7 +3468,7 @@
 	    && argv[0]->type == ESEXP_RES_STRING
 	    && argv[1]->type == ESEXP_RES_STRING) {
 		char *propname = argv[0]->value.string;
-		char *str = rfc2254_escape(argv[1]->value.string);
+		char *str = extend_query_value( rfc2254_escape (argv[1]->value.string));
 		gboolean one_star = FALSE;
 
 		if (strlen(str) == 0)
@@ -3444,6 +3480,8 @@
 			char *big_query;
 			char *match_str;
 			if (one_star) {
+				g_free (str);
+
 				/* ignore NULL query */
 				r = e_sexp_result_new (f, ESEXP_RES_BOOL);
 				r->value.bool = FALSE;
@@ -3501,7 +3539,7 @@
 	    && argv[0]->type == ESEXP_RES_STRING
 	    && argv[1]->type == ESEXP_RES_STRING) {
 		char *propname = argv[0]->value.string;
-		char *str = rfc2254_escape(argv[1]->value.string);
+		char *str = extend_query_value( rfc2254_escape (argv[1]->value.string));
 		char *ldap_attr = query_prop_to_ldap(propname);
 
 		if (ldap_attr)
@@ -3534,10 +3572,12 @@
 	    && argv[0]->type == ESEXP_RES_STRING
 	    && argv[1]->type == ESEXP_RES_STRING) {
 		char *propname = argv[0]->value.string;
-		char *str = rfc2254_escape(argv[1]->value.string);
+		char *str = extend_query_value( rfc2254_escape (argv[1]->value.string));
 		char *ldap_attr = query_prop_to_ldap(propname);
 
 		if (strlen (str) == 0) {
+			g_free (str);
+
 			r = e_sexp_result_new (f, ESEXP_RES_BOOL);
 			r->value.bool = FALSE;
 			return r;
@@ -3589,7 +3629,7 @@
 	    && argv[0]->type == ESEXP_RES_STRING
 	    && argv[1]->type == ESEXP_RES_STRING) {
 		char *propname = argv[0]->value.string;
-		char *str = rfc2254_escape(argv[1]->value.string);
+		char *str = extend_query_value( rfc2254_escape (argv[1]->value.string));
 		char *ldap_attr = query_prop_to_ldap(propname);
 
 		if (ldap_attr)
