dovecot: Changed message_decoder_init_ucase() to message_decoder...

dovecot at dovecot.org dovecot at dovecot.org
Fri Jul 20 06:15:23 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/adbfce5bf7d9
changeset: 6113:adbfce5bf7d9
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jul 20 06:11:03 2007 +0300
description:
Changed message_decoder_init_ucase() to message_decoder_init(bool ucase)

diffstat:

4 files changed, 34 insertions(+), 18 deletions(-)
src/lib-mail/message-decoder.c |   44 +++++++++++++++++++++++++++-------------
src/lib-mail/message-decoder.h |    4 +--
src/lib-mail/message-search.c  |    2 -
src/plugins/fts/fts-storage.c  |    2 -

diffs (135 lines):

diff -r e5451501ff2f -r adbfce5bf7d9 src/lib-mail/message-decoder.c
--- a/src/lib-mail/message-decoder.c	Fri Jul 20 06:03:45 2007 +0300
+++ b/src/lib-mail/message-decoder.c	Fri Jul 20 06:11:03 2007 +0300
@@ -41,14 +41,16 @@ struct message_decoder_context {
 	char *content_charset;
 	enum content_type content_type;
 
+	unsigned int ucase:1;
 	unsigned int charset_utf8:1;
 };
 
-struct message_decoder_context *message_decoder_init_ucase(void)
+struct message_decoder_context *message_decoder_init(bool ucase)
 {
 	struct message_decoder_context *ctx;
 
 	ctx = i_new(struct message_decoder_context, 1);
+	ctx->ucase = ucase;
 	ctx->buf = buffer_create_dynamic(default_pool, 8192);
 	ctx->buf2 = buffer_create_dynamic(default_pool, 8192);
 	return ctx;
@@ -79,11 +81,16 @@ message_decode_header_callback(const uns
 
 	if (charset == NULL || charset_is_utf8(charset)) {
 		/* ASCII / UTF-8 */
-		_charset_utf8_ucase(data, size, ctx->buf, ctx->buf->used);
+		if (ctx->ucase) {
+			_charset_utf8_ucase(data, size, ctx->buf,
+					    ctx->buf->used);
+		} else {
+			buffer_append(ctx->buf, data, size);
+		}
 		return TRUE;
 	}
 
-	t = charset_to_utf8_begin(charset, TRUE, &unknown_charset);
+	t = charset_to_utf8_begin(charset, ctx->ucase, &unknown_charset);
 	if (unknown_charset) {
 		/* let's just ignore this part */
 		return TRUE;
@@ -169,17 +176,21 @@ static bool message_decode_header(struct
 			      message_decode_header_callback, ctx);
 	value_len = ctx->buf->used;
 
-	_charset_utf8_ucase((const unsigned char *)hdr->name, hdr->name_len,
-			    ctx->buf, ctx->buf->used);
-	buffer_append_c(ctx->buf, '\0');
+	if (ctx->ucase) {
+		_charset_utf8_ucase((const unsigned char *)hdr->name,
+				    hdr->name_len, ctx->buf, ctx->buf->used);
+		buffer_append_c(ctx->buf, '\0');
+	}
 
 	ctx->hdr = *hdr;
 	ctx->hdr.full_value = ctx->buf->data;
 	ctx->hdr.full_value_len = value_len;
 	ctx->hdr.value_len = 0;
-	ctx->hdr.name = CONST_PTR_OFFSET(ctx->buf->data,
-					 ctx->hdr.full_value_len);
-	ctx->hdr.name_len = ctx->buf->used - 1 - value_len;
+	if (ctx->ucase) {
+		ctx->hdr.name = CONST_PTR_OFFSET(ctx->buf->data,
+						 ctx->hdr.full_value_len);
+		ctx->hdr.name_len = ctx->buf->used - 1 - value_len;
+	}
 
 	output->hdr = &ctx->hdr;
 	return TRUE;
@@ -226,7 +237,7 @@ static bool message_decode_body(struct m
 		ctx->charset_trans =
 			charset_to_utf8_begin(ctx->content_charset != NULL ?
 					      ctx->content_charset : "UTF-8",
-					      TRUE,
+					      ctx->ucase,
 					      &unknown_charset);
 	}
 
@@ -305,10 +316,15 @@ static bool message_decode_body(struct m
 	}
 
 	if (ctx->charset_utf8) {
-		buffer_set_used_size(ctx->buf2, 0);
-		_charset_utf8_ucase(data, size, ctx->buf2, ctx->buf2->used);
-		output->data = ctx->buf2->data;
-		output->size = ctx->buf2->used;
+		if (ctx->ucase) {
+			buffer_set_used_size(ctx->buf2, 0);
+			_charset_utf8_ucase(data, size, ctx->buf2, 0);
+			output->data = ctx->buf2->data;
+			output->size = ctx->buf2->used;
+		} else {
+			output->data = data;
+			output->size = size;
+		}
 	} else if (ctx->charset_trans == NULL) {
 		output->data = data;
 		output->size = size;
diff -r e5451501ff2f -r adbfce5bf7d9 src/lib-mail/message-decoder.h
--- a/src/lib-mail/message-decoder.h	Fri Jul 20 06:03:45 2007 +0300
+++ b/src/lib-mail/message-decoder.h	Fri Jul 20 06:11:03 2007 +0300
@@ -5,8 +5,8 @@ struct message_block;
 
 /* Decode message's contents as UTF-8, both the headers and the MIME bodies.
    The bodies are decoded from quoted-printable and base64 formats if needed.
-   The data is returned uppercased. */
-struct message_decoder_context *message_decoder_init_ucase(void);
+   If ucase=TRUE, the data is returned uppercased. */
+struct message_decoder_context *message_decoder_init(bool ucase);
 void message_decoder_deinit(struct message_decoder_context **ctx);
 
 /* Decode input and return decoded output. Headers are returned only in their
diff -r e5451501ff2f -r adbfce5bf7d9 src/lib-mail/message-search.c
--- a/src/lib-mail/message-search.c	Fri Jul 20 06:03:45 2007 +0300
+++ b/src/lib-mail/message-search.c	Fri Jul 20 06:11:03 2007 +0300
@@ -63,7 +63,7 @@ int message_search_init(pool_t pool, con
 	ctx->key_len = key_len;
 	ctx->key_charset = p_strdup(pool, charset);
 	ctx->flags = flags;
-	ctx->decoder = message_decoder_init_ucase();
+	ctx->decoder = message_decoder_init(TRUE);
 	ctx->str_find_ctx = str_find_init(pool, ctx->key);
 	t_pop();
 	return 1;
diff -r e5451501ff2f -r adbfce5bf7d9 src/plugins/fts/fts-storage.c
--- a/src/plugins/fts/fts-storage.c	Fri Jul 20 06:03:45 2007 +0300
+++ b/src/plugins/fts/fts-storage.c	Fri Jul 20 06:11:03 2007 +0300
@@ -176,7 +176,7 @@ static int fts_build_mail(struct fts_sto
 	parser = message_parser_init(pool_datastack_create(), input,
 				     MESSAGE_HEADER_PARSER_FLAG_CLEAN_ONELINE,
 				     0);
-	decoder = message_decoder_init_ucase();
+	decoder = message_decoder_init(TRUE);
 	for (;;) {
 		ret = message_parser_parse_next_block(parser, &raw_block);
 		i_assert(ret != 0);


More information about the dovecot-cvs mailing list