[dovecot-cvs] dovecot/src/lib-storage mail-search.c,1.10,1.11 mail-search.h,1.8,1.9

cras at procontrol.fi cras at procontrol.fi
Sat Feb 1 13:24:19 EET 2003


Update of /home/cvs/dovecot/src/lib-storage
In directory danu:/tmp/cvs-serv21475/lib-storage

Modified Files:
	mail-search.c mail-search.h 
Log Message:
Several search fixes, mostly related to matching multiple conditions.



Index: mail-search.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/mail-search.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- mail-search.c	20 Jan 2003 14:52:51 -0000	1.10
+++ mail-search.c	1 Feb 2003 11:24:17 -0000	1.11
@@ -8,7 +8,7 @@
 	while (args != NULL) {
 		if (args->type == SEARCH_OR || args->type == SEARCH_SUB)
 			mail_search_args_reset(args->value.subargs);
-		args->result = 0;
+		args->result = -1;
 
 		args = args->next;
 	}
@@ -20,7 +20,7 @@
 {
 	struct mail_search_arg *subarg;
 
-	if (arg->result != 0)
+	if (arg->result != -1)
 		return;
 
 	if (arg->type == SEARCH_SUB) {
@@ -30,18 +30,17 @@
 		arg->result = 1;
 		subarg = arg->value.subargs;
 		while (subarg != NULL) {
-			if (subarg->result == 0)
+			if (subarg->result == -1)
 				search_arg_foreach(subarg, callback, context);
 
-			if (subarg->result == -1) {
-				/* failed */
+			if (subarg->result == -1)
 				arg->result = -1;
+			else if (subarg->result == arg->not) {
+				/* didn't match */
+				arg->result = 0;
 				break;
 			}
 
-			if (subarg->result == 0)
-				arg->result = 0;
-
 			subarg = subarg->next;
 		}
 	} else if (arg->type == SEARCH_OR) {
@@ -51,17 +50,18 @@
 		subarg = arg->value.subargs;
 		arg->result = -1;
 		while (subarg != NULL) {
-			if (subarg->result == 0)
+			if (subarg->result == -1)
 				search_arg_foreach(subarg, callback, context);
 
-			if (subarg->result == 1) {
-				/* matched */
-				arg->result = 1;
-				break;
-			}
+			if (subarg->result != -1) {
+				if (subarg->result == !arg->not) {
+					/* matched */
+					arg->result = 1;
+					break;
+				}
 
-			if (subarg->result == 0)
 				arg->result = 0;
+			}
 
 			subarg = subarg->next;
 		}
@@ -81,13 +81,13 @@
 	for (; args != NULL; args = args->next) {
 		search_arg_foreach(args, callback, context);
 
-		if (args->result == -1) {
-			/* failed, abort */
-			return -1;
+		if (args->result == 0) {
+			/* didn't match */
+			return 0;
 		}
 
-		if (args->result == 0)
-			result = 0;
+		if (args->result == -1)
+			result = -1;
 	}
 
 	return result;
@@ -98,7 +98,7 @@
 {
 	struct mail_search_arg *subarg;
 
-	if (arg->result != 0)
+	if (arg->result != -1)
 		return;
 
 	switch (arg->type) {
@@ -106,7 +106,7 @@
 	case SEARCH_SUB:
 		subarg = arg->value.subargs;
 		while (subarg != NULL) {
-			if (subarg->result == 0) {
+			if (subarg->result == -1) {
 				search_arg_analyze(subarg, have_headers,
 						   have_body, have_text);
 			}

Index: mail-search.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/mail-search.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- mail-search.h	20 Jan 2003 14:52:51 -0000	1.8
+++ mail-search.h	1 Feb 2003 11:24:17 -0000	1.9
@@ -61,9 +61,15 @@
 	const char *hdr_field_name; /* for SEARCH_HEADER */
 	unsigned int not:1;
 
-	int result;
+	int result; /* -1 = unknown, 0 = unmatched, 1 = matched */
 };
 
+#define ARG_SET_RESULT(arg, res) \
+	STMT_START { \
+		(arg)->result = !(arg)->not ? (res) : \
+			(res) == -1 ? -1 : !(res); \
+	} STMT_END
+
 typedef void (*mail_search_foreach_callback_t)(struct mail_search_arg *arg,
 					       void *context);
 
@@ -71,7 +77,7 @@
 void mail_search_args_reset(struct mail_search_arg *args);
 
 /* goes through arguments in list that don't have a result yet.
-   Returns 1 = search matched, -1 = search unmatched, 0 = don't know yet */
+   Returns 1 = search matched, 0 = search unmatched, -1 = don't know yet */
 int mail_search_args_foreach(struct mail_search_arg *args,
 			     mail_search_foreach_callback_t callback,
 			     void *context);




More information about the dovecot-cvs mailing list