dovecot-2.1: Don't assert-crash on mail search if decomposed tit...

dovecot at dovecot.org dovecot at dovecot.org
Tue Jan 10 23:28:26 EET 2012


details:   http://hg.dovecot.org/dovecot-2.1/rev/bc3b343b1999
changeset: 13927:bc3b343b1999
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Jan 10 23:28:03 2012 +0200
description:
Don't assert-crash on mail search if decomposed titlecase of search key is empty.

diffstat:

 src/lib-mail/message-search.c        |  19 ++++++++-----------
 src/lib-mail/message-search.h        |   5 ++++-
 src/lib-storage/index/index-search.c |  24 ++++++++++++++++++------
 3 files changed, 30 insertions(+), 18 deletions(-)

diffs (97 lines):

diff -r 0cd33404a201 -r bc3b343b1999 src/lib-mail/message-search.c
--- a/src/lib-mail/message-search.c	Tue Jan 10 23:14:18 2012 +0200
+++ b/src/lib-mail/message-search.c	Tue Jan 10 23:28:03 2012 +0200
@@ -5,7 +5,6 @@
 #include "istream.h"
 #include "str.h"
 #include "str-find.h"
-#include "unichar.h"
 #include "rfc822-parser.h"
 #include "message-decoder.h"
 #include "message-parser.h"
@@ -24,20 +23,18 @@
 message_search_init(const char *key_utf8,
 		    enum message_search_flags flags)
 {
+	enum message_decoder_flags decoder_flags = 0;
 	struct message_search_context *ctx;
 
+	i_assert(*key_utf8 != '\0');
+
+	if ((flags & MESSAGE_SEARCH_FLAG_DTCASE) != 0)
+		decoder_flags |= MESSAGE_DECODER_FLAG_DTCASE;
+
 	ctx = i_new(struct message_search_context, 1);
 	ctx->flags = flags;
-	ctx->decoder = message_decoder_init(MESSAGE_DECODER_FLAG_DTCASE);
-
-	T_BEGIN {
-		string_t *dtc = t_str_new(128);
-
-		if (uni_utf8_to_decomposed_titlecase(key_utf8, strlen(key_utf8),
-						     dtc) < 0)
-			i_panic("message_search_init(): key not utf8");
-		ctx->str_find_ctx = str_find_init(default_pool, str_c(dtc));
-	} T_END;
+	ctx->decoder = message_decoder_init(decoder_flags);
+	ctx->str_find_ctx = str_find_init(default_pool, key_utf8);
 	return ctx;
 }
 
diff -r 0cd33404a201 -r bc3b343b1999 src/lib-mail/message-search.h
--- a/src/lib-mail/message-search.h	Tue Jan 10 23:14:18 2012 +0200
+++ b/src/lib-mail/message-search.h	Tue Jan 10 23:28:03 2012 +0200
@@ -7,7 +7,10 @@
 
 enum message_search_flags {
 	/* Skip the main header and all the MIME headers. */
-	MESSAGE_SEARCH_FLAG_SKIP_HEADERS	= 0x01
+	MESSAGE_SEARCH_FLAG_SKIP_HEADERS	= 0x01,
+	/* Search with decomposed titlecase (instead of exact case matching).
+	   The search key must be given with dtcase also. */
+	MESSAGE_SEARCH_FLAG_DTCASE		= 0x02
 };
 
 /* The key must be given in UTF-8 charset */
diff -r 0cd33404a201 -r bc3b343b1999 src/lib-storage/index/index-search.c
--- a/src/lib-storage/index/index-search.c	Tue Jan 10 23:14:18 2012 +0200
+++ b/src/lib-storage/index/index-search.c	Tue Jan 10 23:28:03 2012 +0200
@@ -7,6 +7,7 @@
 #include "utc-offset.h"
 #include "str.h"
 #include "time-util.h"
+#include "unichar.h"
 #include "imap-match.h"
 #include "message-address.h"
 #include "message-date.h"
@@ -373,13 +374,24 @@
 static struct message_search_context *
 msg_search_arg_context(struct mail_search_arg *arg)
 {
-	enum message_search_flags flags;
+	enum message_search_flags flags = MESSAGE_SEARCH_FLAG_DTCASE;
 
-	if (arg->context == NULL) {
-		flags = arg->type == SEARCH_BODY ?
-			MESSAGE_SEARCH_FLAG_SKIP_HEADERS : 0;
-		arg->context = message_search_init(arg->value.str, flags);
-	}
+	if (arg->context == NULL) T_BEGIN {
+		string_t *dtc = t_str_new(128);
+
+		if (uni_utf8_to_decomposed_titlecase(arg->value.str,
+						     strlen(arg->value.str),
+						     dtc) < 0)
+			i_panic("search key not utf8: %s", arg->value.str);
+
+		if (arg->type == SEARCH_BODY)
+			flags |= MESSAGE_SEARCH_FLAG_SKIP_HEADERS;
+		/* we don't get here if arg is "", but dtc can be "" if it
+		   only contains characters that we need to ignore. handle
+		   those searches by returning them as non-matched. */
+		if (str_len(dtc) > 0)
+			arg->context = message_search_init(str_c(dtc), flags);
+	} T_END;
 	return arg->context;
 }
 


More information about the dovecot-cvs mailing list