dovecot: message_header_decode_utf8() returns not TRUE if it act...

dovecot at dovecot.org dovecot at dovecot.org
Fri Jul 20 17:39:13 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/157e31742eeb
changeset: 6121:157e31742eeb
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jul 20 16:21:23 2007 +0300
description:
message_header_decode_utf8() returns not TRUE if it actually changed
something.

diffstat:

2 files changed, 16 insertions(+), 4 deletions(-)
src/lib-mail/message-header-decode.c |   15 +++++++++++++--
src/lib-mail/message-header-decode.h |    5 +++--

diffs (66 lines):

diff -r 00d1a94a94c6 -r 157e31742eeb src/lib-mail/message-header-decode.c
--- a/src/lib-mail/message-header-decode.c	Fri Jul 20 12:36:38 2007 +0300
+++ b/src/lib-mail/message-header-decode.c	Fri Jul 20 16:21:23 2007 +0300
@@ -117,7 +117,9 @@ void message_header_decode(const unsigne
 
 struct decode_utf8_context {
 	buffer_t *dest;
-	bool ucase;
+	unsigned int changed:1;
+	unsigned int called:1;
+	unsigned int ucase:1;
 };
 
 static bool
@@ -127,6 +129,12 @@ decode_utf8_callback(const unsigned char
 	struct decode_utf8_context *ctx = context;
 	struct charset_translation *t;
 	bool unknown_charset;
+
+	/* one call with charset=NULL means nothing changed */
+	if (!ctx->called)
+		ctx->called = TRUE;
+	else
+		ctx->changed = TRUE;
 
 	if (charset == NULL || charset_is_utf8(charset)) {
 		/* ASCII / UTF-8 */
@@ -138,6 +146,7 @@ decode_utf8_callback(const unsigned char
 		}
 		return TRUE;
 	}
+	ctx->changed = TRUE;
 
 	t = charset_to_utf8_begin(charset, ctx->ucase, &unknown_charset);
 	if (unknown_charset) {
@@ -151,12 +160,14 @@ decode_utf8_callback(const unsigned char
 	return TRUE;
 }
 
-void message_header_decode_utf8(const unsigned char *data, size_t size,
+bool message_header_decode_utf8(const unsigned char *data, size_t size,
 				buffer_t *dest, bool ucase)
 {
 	struct decode_utf8_context ctx;
 
+	memset(&ctx, 0, sizeof(ctx));
 	ctx.dest = dest;
 	ctx.ucase = ucase;
 	message_header_decode(data, size, decode_utf8_callback, &ctx);
+	return ctx.changed;
 }
diff -r 00d1a94a94c6 -r 157e31742eeb src/lib-mail/message-header-decode.h
--- a/src/lib-mail/message-header-decode.h	Fri Jul 20 12:36:38 2007 +0300
+++ b/src/lib-mail/message-header-decode.h	Fri Jul 20 16:21:23 2007 +0300
@@ -14,8 +14,9 @@ void message_header_decode(const unsigne
 			   void *context);
 
 /* Append decoded RFC2047 header as UTF-8 to given buffer. If ucase=TRUE,
-   the header is appended uppercased. */
-void message_header_decode_utf8(const unsigned char *data, size_t size,
+   the header is appended uppercased. Returns TRUE if output changed in any
+   way from input. */
+bool message_header_decode_utf8(const unsigned char *data, size_t size,
 				buffer_t *dest, bool ucase);
 
 #endif


More information about the dovecot-cvs mailing list