dovecot-2.2: lib-mail: message_header_decode_utf8() API changed ...

dovecot at dovecot.org dovecot at dovecot.org
Sun Jun 24 20:48:58 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/45952eee7ad4
changeset: 14635:45952eee7ad4
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Jun 24 19:51:40 2012 +0300
description:
lib-mail: message_header_decode_utf8() API changed to not give return value.
It's a rather unnecessary optimization and it wasn't even correct when the
input wasn't valid UTF8.

diffstat:

 src/lib-mail/message-header-decode.c       |  10 +---------
 src/lib-mail/message-header-decode.h       |   5 ++---
 src/lib-mail/test-message-decoder.c        |   3 +--
 src/lib-mail/test-message-header-decode.c  |   5 ++---
 src/lib-storage/index/index-mail-headers.c |   5 +++--
 5 files changed, 9 insertions(+), 19 deletions(-)

diffs (100 lines):

diff -r a65006d95d53 -r 45952eee7ad4 src/lib-mail/message-header-decode.c
--- a/src/lib-mail/message-header-decode.c	Sun Jun 24 19:35:11 2012 +0300
+++ b/src/lib-mail/message-header-decode.c	Sun Jun 24 19:51:40 2012 +0300
@@ -136,7 +136,6 @@
 struct decode_utf8_context {
 	buffer_t *dest;
 	unsigned int changed:1;
-	unsigned int called:1;
 	unsigned int dtcase:1;
 };
 
@@ -148,12 +147,6 @@
 	struct charset_translation *t;
 	enum charset_flags flags;
 
-	/* one call with charset=NULL means nothing changed */
-	if (!ctx->called && charset == NULL)
-		ctx->called = TRUE;
-	else
-		ctx->changed = TRUE;
-
 	if (charset == NULL || charset_is_utf8(charset)) {
 		/* ASCII / UTF-8 */
 		if (ctx->dtcase) {
@@ -181,7 +174,7 @@
 	return TRUE;
 }
 
-bool message_header_decode_utf8(const unsigned char *data, size_t size,
+void message_header_decode_utf8(const unsigned char *data, size_t size,
 				buffer_t *dest, bool dtcase)
 {
 	struct decode_utf8_context ctx;
@@ -191,5 +184,4 @@
 	ctx.dest = dest;
 	ctx.dtcase = dtcase;
 	message_header_decode(data, size, decode_utf8_callback, &ctx);
-	return ctx.changed || (dest->used - used != size);
 }
diff -r a65006d95d53 -r 45952eee7ad4 src/lib-mail/message-header-decode.h
--- a/src/lib-mail/message-header-decode.h	Sun Jun 24 19:35:11 2012 +0300
+++ b/src/lib-mail/message-header-decode.h	Sun Jun 24 19:51:40 2012 +0300
@@ -14,9 +14,8 @@
 			   void *context);
 
 /* Append decoded RFC2047 header as UTF-8 to given buffer. If dtcase=TRUE,
-   the header is appended through uni_utf8_to_decomposed_titlecase().
-   Returns TRUE if output changed in any way from input. */
-bool message_header_decode_utf8(const unsigned char *data, size_t size,
+   the header is appended through uni_utf8_to_decomposed_titlecase(). */
+void message_header_decode_utf8(const unsigned char *data, size_t size,
 				buffer_t *dest, bool dtcase);
 
 #endif
diff -r a65006d95d53 -r 45952eee7ad4 src/lib-mail/test-message-decoder.c
--- a/src/lib-mail/test-message-decoder.c	Sun Jun 24 19:35:11 2012 +0300
+++ b/src/lib-mail/test-message-decoder.c	Sun Jun 24 19:51:40 2012 +0300
@@ -9,11 +9,10 @@
 #include "message-decoder.h"
 #include "test-common.h"
 
-bool message_header_decode_utf8(const unsigned char *data, size_t size,
+void message_header_decode_utf8(const unsigned char *data, size_t size,
 				buffer_t *dest, bool dtcase ATTR_UNUSED)
 {
 	buffer_append(dest, data, size);
-	return FALSE;
 }
 
 void quoted_printable_decode(const unsigned char *src, size_t src_size,
diff -r a65006d95d53 -r 45952eee7ad4 src/lib-mail/test-message-header-decode.c
--- a/src/lib-mail/test-message-header-decode.c	Sun Jun 24 19:35:11 2012 +0300
+++ b/src/lib-mail/test-message-header-decode.c	Sun Jun 24 19:51:40 2012 +0300
@@ -40,9 +40,8 @@
 	dest = t_str_new(256);
 	for (i = 0; i < N_ELEMENTS(data); i += 2) {
 		str_truncate(dest, 0);
-		test_assert(message_header_decode_utf8((const unsigned char *)data[i],
-						       strlen(data[i]),
-						       dest, FALSE));
+		message_header_decode_utf8((const unsigned char *)data[i],
+					   strlen(data[i]), dest, FALSE);
 		test_assert(strcmp(str_c(dest), data[i+1]) == 0);
 	}
 	test_end();
diff -r a65006d95d53 -r 45952eee7ad4 src/lib-storage/index/index-mail-headers.c
--- a/src/lib-storage/index/index-mail-headers.c	Sun Jun 24 19:35:11 2012 +0300
+++ b/src/lib-storage/index/index-mail-headers.c	Sun Jun 24 19:51:40 2012 +0300
@@ -715,8 +715,9 @@
 			return -1;
 
 		/* decode MIME encoded-words. decoding may also add new LFs. */
-		if (message_header_decode_utf8((const unsigned char *)input,
-					       strlen(input), str, FALSE))
+		message_header_decode_utf8((const unsigned char *)input,
+					   strlen(input), str, FALSE);
+		if (strcmp(str_c(str), input) != 0)
 			input = p_strdup(mail->data_pool, str_c(str));
 		decoded_list[i] = input;
 	}


More information about the dovecot-cvs mailing list