dovecot: Use charset_to_utf8_str() instead of doing it ourself.

dovecot at dovecot.org dovecot at dovecot.org
Mon Dec 3 14:23:50 EET 2007


details:   http://hg.dovecot.org/dovecot/rev/725a31acbe00
changeset: 6909:725a31acbe00
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Dec 03 14:22:27 2007 +0200
description:
Use charset_to_utf8_str() instead of doing it ourself.

diffstat:

1 file changed, 23 insertions(+), 25 deletions(-)
src/lib-mail/message-search.c |   48 +++++++++++++++++++----------------------

diffs (59 lines):

diff -r a340d3379b90 -r 725a31acbe00 src/lib-mail/message-search.c
--- a/src/lib-mail/message-search.c	Mon Dec 03 14:21:21 2007 +0200
+++ b/src/lib-mail/message-search.c	Mon Dec 03 14:22:27 2007 +0200
@@ -31,32 +31,30 @@ int message_search_init(pool_t pool, con
 			struct message_search_context **ctx_r)
 {
 	struct message_search_context *ctx;
-	struct charset_translation *t;
 	string_t *key_utf8;
-	size_t key_len;
-
-	if (charset_to_utf8_begin(charset, TRUE, &t) < 0)
-		return 0;
-
-	t_push();
-	key_len = strlen(key);
-	key_utf8 = t_str_new(I_MAX(128, key_len*2));
-	if (charset_to_utf8(t, (const unsigned char *)key, &key_len,
-			    key_utf8) != CHARSET_RET_OK) {
-		t_pop();
-		return -1;
-	}
-
-	ctx = *ctx_r = p_new(pool, struct message_search_context, 1);
-	ctx->pool = pool;
-	ctx->key = p_strdup(pool, str_c(key_utf8));
-	ctx->key_len = str_len(key_utf8);
-	ctx->key_charset = p_strdup(pool, charset);
-	ctx->flags = flags;
-	ctx->decoder = message_decoder_init(TRUE);
-	ctx->str_find_ctx = str_find_init(pool, ctx->key);
-	t_pop();
-	return 1;
+	enum charset_result result;
+	int ret;
+
+	t_push();
+	key_utf8 = t_str_new(128);
+	if (charset_to_utf8_str(charset, CHARSET_FLAG_DECOMP_TITLECASE,
+				key, key_utf8, &result) < 0)
+		ret = 0;
+	else if (result != CHARSET_RET_OK)
+		ret = -1;
+	else {
+		ctx = *ctx_r = p_new(pool, struct message_search_context, 1);
+		ctx->pool = pool;
+		ctx->key = p_strdup(pool, str_c(key_utf8));
+		ctx->key_len = str_len(key_utf8);
+		ctx->key_charset = p_strdup(pool, charset);
+		ctx->flags = flags;
+		ctx->decoder = message_decoder_init(TRUE);
+		ctx->str_find_ctx = str_find_init(pool, ctx->key);
+		ret = 1;
+	}
+	t_pop();
+	return ret;
 }
 
 void message_search_deinit(struct message_search_context **_ctx)


More information about the dovecot-cvs mailing list