changeset 12872:b131b89f5e20

lib-storage: Fail mail_search_build() if charset is unknown, even if it's not used. For example this causes "SEARCH CHARSET foo ALL" command to fail.
author Timo Sirainen <tss@iki.fi>
date Thu, 31 Mar 2011 09:23:22 +0300
parents d399d5c65aca
children b47f17b173f5
files src/lib-storage/mail-search-build.c src/lib-storage/mail-search-build.h
diffstat 2 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/mail-search-build.c	Thu Mar 31 09:19:10 2011 +0300
+++ b/src/lib-storage/mail-search-build.c	Thu Mar 31 09:23:22 2011 +0300
@@ -136,6 +136,8 @@
         struct mail_search_build_context ctx;
 	struct mail_search_args *args;
 	struct mail_search_arg *root;
+	const char *str;
+	int ret;
 
 	*args_r = NULL;
 	*error_r = NULL;
@@ -148,7 +150,12 @@
 	ctx.parser = parser;
 	ctx.charset = p_strdup(ctx.pool, *charset);
 
-	if (mail_search_build_list(&ctx, &root) < 0) {
+	ret = mail_search_build_list(&ctx, &root);
+	if (!ctx.charset_checked && ret == 0) {
+		/* make sure we give an error message if charset is invalid */
+		ret = mail_search_build_get_utf8_dtc(&ctx, "", &str);
+	}
+	if (ret < 0) {
 		*error_r = ctx._error != NULL ? t_strdup(ctx._error) :
 			t_strdup(mail_search_parser_get_error(parser));
 		if (ctx.unknown_charset)
@@ -235,5 +242,7 @@
 			ret = 0;
 		}
 	} T_END;
+
+	ctx->charset_checked = TRUE;
 	return ret;
 }
--- a/src/lib-storage/mail-search-build.h	Thu Mar 31 09:19:10 2011 +0300
+++ b/src/lib-storage/mail-search-build.h	Thu Mar 31 09:23:22 2011 +0300
@@ -15,6 +15,7 @@
 	struct mail_search_arg *parent;
 	/* error is either here or in parser */
 	const char *_error;
+	bool charset_checked;
 	bool unknown_charset;
 };