From: Timo Sirainen Date: Tue, 10 Jan 2012 21:28:03 +0000 (+0200) Subject: Don't assert-crash on mail search if decomposed titlecase of search key is empty. X-Git-Tag: 2.1.rc4~62 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6a1ecaf2ffe6142f0c583c07314b1bdb97a3cdbb;p=thirdparty%2Fdovecot%2Fcore.git Don't assert-crash on mail search if decomposed titlecase of search key is empty. --- diff --git a/src/lib-mail/message-search.c b/src/lib-mail/message-search.c index f024c322ba..2cd44b8468 100644 --- a/src/lib-mail/message-search.c +++ b/src/lib-mail/message-search.c @@ -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 @@ struct message_search_context * message_search_init(const char *key_utf8, enum message_search_flags flags) { + enum message_decoder_flags decoder_flags = 0; struct message_search_context *ctx; - ctx = i_new(struct message_search_context, 1); - ctx->flags = flags; - ctx->decoder = message_decoder_init(MESSAGE_DECODER_FLAG_DTCASE); + i_assert(*key_utf8 != '\0'); - T_BEGIN { - string_t *dtc = t_str_new(128); + if ((flags & MESSAGE_SEARCH_FLAG_DTCASE) != 0) + decoder_flags |= MESSAGE_DECODER_FLAG_DTCASE; - 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 = i_new(struct message_search_context, 1); + ctx->flags = flags; + ctx->decoder = message_decoder_init(decoder_flags); + ctx->str_find_ctx = str_find_init(default_pool, key_utf8); return ctx; } diff --git a/src/lib-mail/message-search.h b/src/lib-mail/message-search.h index 1cdba694be..207756dd0c 100644 --- a/src/lib-mail/message-search.h +++ b/src/lib-mail/message-search.h @@ -7,7 +7,10 @@ struct message_search_context; 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 --git a/src/lib-storage/index/index-search.c b/src/lib-storage/index/index-search.c index d66683277a..2fee36b2a6 100644 --- a/src/lib-storage/index/index-search.c +++ b/src/lib-storage/index/index-search.c @@ -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 int search_sent(enum mail_search_arg_type type, time_t search_time, static struct message_search_context * msg_search_arg_context(struct mail_search_arg *arg) { - enum message_search_flags flags; - - if (arg->context == NULL) { - flags = arg->type == SEARCH_BODY ? - MESSAGE_SEARCH_FLAG_SKIP_HEADERS : 0; - arg->context = message_search_init(arg->value.str, flags); - } + enum message_search_flags flags = MESSAGE_SEARCH_FLAG_DTCASE; + + 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; }