[dovecot-cvs] dovecot/src/lib-storage/index index-search.c,1.52,1.53 index-sort.c,1.4,1.5

cras at procontrol.fi cras at procontrol.fi
Thu Jan 2 11:06:35 EET 2003


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

Modified Files:
	index-search.c index-sort.c 
Log Message:
SEARCHing headers with "" value should always match if the header is found.
Changed imap_envelope_parse() so that it's possible to differentiate NIL
from "".



Index: index-search.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-search.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- index-search.c	21 Dec 2002 13:08:50 -0000	1.52
+++ index-search.c	2 Jan 2003 09:06:33 -0000	1.53
@@ -278,13 +278,16 @@
 	}
 }
 
-static int search_sent(MailSearchArgType type, const char *value,
+static int search_sent(MailSearchArgType type, const char *search_value,
 		       const char *sent_value)
 {
 	time_t search_time, sent_time;
 	int timezone_offset;
 
-	if (!imap_parse_date(value, &search_time))
+	if (sent_value == NULL)
+		return 0;
+
+	if (!imap_parse_date(search_value, &search_time))
 		return 0;
 
 	/* NOTE: RFC2060 doesn't specify if timezones should affect
@@ -380,22 +383,29 @@
 	/* get field from hopefully cached envelope */
 	envelope = index->lookup_field(index, ctx->rec, DATA_FIELD_ENVELOPE);
 	if (envelope != NULL) {
-		field = imap_envelope_parse(envelope, env_field,
-					    IMAP_ENVELOPE_RESULT_STRING);
+		ret = imap_envelope_parse(envelope, env_field,
+					  IMAP_ENVELOPE_RESULT_STRING,
+					  &field) ? 1 : -1;
 	} else {
 		index->cache_fields_later(index, DATA_FIELD_ENVELOPE);
 		field = NULL;
+		ret = -1;
 	}
 
-	if (field == NULL)
-		ret = -1;
-	else {
+	if (ret != -1) {
 		switch (arg->type) {
 		case SEARCH_SENTBEFORE:
 		case SEARCH_SENTON:
 		case SEARCH_SENTSINCE:
 			ret = search_sent(arg->type, arg->value.str, field);
 		default:
+			if (arg->value.str[0] == '\0') {
+				/* we're just testing existence of the field.
+				   assume it matches with non-NIL values. */
+				ret = field != NULL ? 1 : 0;
+				break;
+			}
+
 			hdr_search_ctx = search_header_context(ctx, arg);
 			if (hdr_search_ctx == NULL) {
 				ret = 0;
@@ -488,18 +498,23 @@
 		return;
 	}
 
-	t_push();
+	if (arg->value.str[0] == '\0') {
+		/* we're just testing existence of the field. always matches. */
+		ret = 1;
+	} else {
+		t_push();
 
-	/* then check if the value matches */
-	hdr_search_ctx = search_header_context(ctx->index_context, arg);
-	if (hdr_search_ctx == NULL)
-		ret = 0;
-	else {
-		len = ctx->value_len;
-		ret = message_header_search(ctx->value, len,
-					    hdr_search_ctx) ? 1 : 0;
+		/* then check if the value matches */
+		hdr_search_ctx = search_header_context(ctx->index_context, arg);
+		if (hdr_search_ctx == NULL)
+			ret = 0;
+		else {
+			len = ctx->value_len;
+			ret = message_header_search(ctx->value, len,
+						    hdr_search_ctx) ? 1 : 0;
+		}
+		t_pop();
 	}
-	t_pop();
 
         ARG_SET_RESULT(arg, ret);
 }

Index: index-sort.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-sort.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- index-sort.c	19 Dec 2002 01:02:35 -0000	1.4
+++ index-sort.c	2 Jan 2003 09:06:33 -0000	1.5
@@ -52,7 +52,7 @@
 {
 	IndexSortContext *ctx = context;
 	ImapEnvelopeField env_field;
-	const char *envelope;
+	const char *envelope, *str;
 
 	switch (type) {
 	case MAIL_SORT_CC:
@@ -72,16 +72,21 @@
 	/* get field from hopefully cached envelope */
 	envelope = imap_msgcache_get(search_open_cache(ctx, id),
 				     IMAP_CACHE_ENVELOPE);
-	return envelope == NULL ? NULL :
-		imap_envelope_parse(envelope, env_field,
-				    IMAP_ENVELOPE_RESULT_FIRST_MAILBOX);
+	if (envelope == NULL)
+		return NULL;
+
+	if (!imap_envelope_parse(envelope, env_field,
+				 IMAP_ENVELOPE_RESULT_FIRST_MAILBOX, &str))
+		return NULL;
+
+	return str;
 }
 
 static const char *_input_str(MailSortType type, unsigned int id, void *context)
 {
 	IndexSortContext *ctx = context;
 	ImapEnvelopeField env_field;
-	const char *envelope;
+	const char *envelope, *str;
 
 	switch (type) {
 	case MAIL_SORT_DATE:
@@ -98,9 +103,14 @@
 	/* get field from hopefully cached envelope */
 	envelope = imap_msgcache_get(search_open_cache(ctx, id),
 				     IMAP_CACHE_ENVELOPE);
-	return envelope == NULL ? NULL :
-		imap_envelope_parse(envelope, env_field,
-				    IMAP_ENVELOPE_RESULT_STRING);
+	if (envelope == NULL)
+		return NULL;
+
+	if (!imap_envelope_parse(envelope, env_field,
+				 IMAP_ENVELOPE_RESULT_STRING, &str))
+		return NULL;
+
+	return str;
 }
 
 static time_t _input_time(MailSortType type, unsigned int id, void *context)




More information about the dovecot-cvs mailing list