dovecot-2.1: imapc: Use mUTF-7 for mailbox names.

dovecot at dovecot.org dovecot at dovecot.org
Fri Sep 9 12:57:55 EEST 2011


details:   http://hg.dovecot.org/dovecot-2.1/rev/92ab9fa4ec36
changeset: 13438:92ab9fa4ec36
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Sep 09 12:57:36 2011 +0300
description:
imapc: Use mUTF-7 for mailbox names.

diffstat:

 src/lib-storage/index/imapc/imapc-list.c    |  20 ++++++++++++++++----
 src/lib-storage/index/imapc/imapc-save.c    |   3 ++-
 src/lib-storage/index/imapc/imapc-storage.c |  19 +++++++++++++++----
 src/lib-storage/index/imapc/imapc-storage.h |   1 +
 4 files changed, 34 insertions(+), 9 deletions(-)

diffs (120 lines):

diff -r ec947cc9c9c7 -r 92ab9fa4ec36 src/lib-storage/index/imapc/imapc-list.c
--- a/src/lib-storage/index/imapc/imapc-list.c	Thu Sep 08 16:52:32 2011 +0300
+++ b/src/lib-storage/index/imapc/imapc-list.c	Fri Sep 09 12:57:36 2011 +0300
@@ -1,8 +1,10 @@
 /* Copyright (c) 2011 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
+#include "str.h"
 #include "imap-arg.h"
 #include "imap-match.h"
+#include "imap-utf7.h"
 #include "mailbox-tree.h"
 #include "mailbox-list-subscriptions.h"
 #include "imapc-client.h"
@@ -82,10 +84,20 @@
 		flags++;
 	}
 
-	if ((info_flags & MAILBOX_NONEXISTENT) != 0)
-		node = mailbox_tree_lookup(tree, name);
-	else
-		node = mailbox_tree_get(tree, name, &created);
+	T_BEGIN {
+		string_t *utf8_name = t_str_new(64);
+
+		if (imap_utf7_to_utf8(name, utf8_name)) {
+			str_truncate(utf8_name, 0);
+			str_append(utf8_name, name);
+		}
+		if ((info_flags & MAILBOX_NONEXISTENT) != 0)
+			node = mailbox_tree_lookup(tree, str_c(utf8_name));
+		else {
+			node = mailbox_tree_get(tree, str_c(utf8_name),
+						&created);
+		}
+	} T_END;
 	if (node != NULL)
 		node->flags = info_flags;
 	return node;
diff -r ec947cc9c9c7 -r 92ab9fa4ec36 src/lib-storage/index/imapc/imapc-save.c
--- a/src/lib-storage/index/imapc/imapc-save.c	Thu Sep 08 16:52:32 2011 +0300
+++ b/src/lib-storage/index/imapc/imapc-save.c	Fri Sep 09 12:57:36 2011 +0300
@@ -335,7 +335,8 @@
 		imapc_client_mailbox_cmdf(src_mbox->client_box,
 					  imapc_copy_callback, &sctx,
 					  "UID COPY %u %s",
-					  mail->uid, _t->box->name);
+					  mail->uid,
+					  imapc_mutf7_mailbox_name(_t->box));
 		while (sctx.ret == -2)
 			imapc_storage_run(src_mbox->storage);
 		ctx->finished = TRUE;
diff -r ec947cc9c9c7 -r 92ab9fa4ec36 src/lib-storage/index/imapc/imapc-storage.c
--- a/src/lib-storage/index/imapc/imapc-storage.c	Thu Sep 08 16:52:32 2011 +0300
+++ b/src/lib-storage/index/imapc/imapc-storage.c	Fri Sep 09 12:57:36 2011 +0300
@@ -5,6 +5,7 @@
 #include "str.h"
 #include "imap-arg.h"
 #include "imap-resp-code.h"
+#include "imap-utf7.h"
 #include "imapc-mail.h"
 #include "imapc-client-private.h"
 #include "imapc-connection.h"
@@ -362,6 +363,15 @@
 	imapc_client_stop(ctx->mbox->storage->client);
 }
 
+const char *imapc_mutf7_mailbox_name(struct mailbox *box)
+{
+	const char *mutf7_name;
+
+	if (t_imap_utf8_to_utf7(box->name, &mutf7_name) < 0)
+		i_unreached();
+	return mutf7_name;
+}
+
 static int imapc_mailbox_open(struct mailbox *box)
 {
 	struct imapc_mailbox *mbox = (struct imapc_mailbox *)box;
@@ -383,8 +393,8 @@
 	ctx.ret = -2;
 	mbox->client_box =
 		imapc_client_mailbox_open(mbox->storage->client,
-					  box->name, examine,
-					  imapc_mailbox_open_callback,
+					  imapc_mutf7_mailbox_name(box),
+					  examine, imapc_mailbox_open_callback,
 					  &ctx, mbox);
 	while (ctx.ret == -2)
 		imapc_storage_run(mbox->storage);
@@ -424,7 +434,7 @@
 {
 	struct imapc_mailbox *mbox = (struct imapc_mailbox *)box;
 	struct imapc_simple_context sctx;
-	const char *name = box->name;
+	const char *name = imapc_mutf7_mailbox_name(box);
 
 	if (directory) {
 		name = t_strdup_printf("%s%c", name,
@@ -544,7 +554,8 @@
 	mbox->storage->cur_status = status_r;
 	imapc_client_cmdf(mbox->storage->client,
 			  imapc_simple_callback, &sctx,
-			  "STATUS %s (%1s)", box->name, str_c(str)+1);
+			  "STATUS %s (%1s)", imapc_mutf7_mailbox_name(box),
+			  str_c(str)+1);
 	imapc_simple_run(&sctx);
 	mbox->storage->cur_status_box = NULL;
 	mbox->storage->cur_status = NULL;
diff -r ec947cc9c9c7 -r 92ab9fa4ec36 src/lib-storage/index/imapc/imapc-storage.h
--- a/src/lib-storage/index/imapc/imapc-storage.h	Thu Sep 08 16:52:32 2011 +0300
+++ b/src/lib-storage/index/imapc/imapc-storage.h	Fri Sep 09 12:57:36 2011 +0300
@@ -90,6 +90,7 @@
 
 void imapc_storage_run(struct imapc_storage *storage);
 
+const char *imapc_mutf7_mailbox_name(struct mailbox *box);
 void imapc_copy_error_from_reply(struct imapc_storage *storage,
 				 enum mail_error default_error,
 				 const struct imapc_command_reply *reply);


More information about the dovecot-cvs mailing list