dovecot-1.2: listescape: Don't escape characters in namespace pr...

dovecot at dovecot.org dovecot at dovecot.org
Fri Aug 14 03:21:45 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/0463fc241aae
changeset: 9320:0463fc241aae
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Aug 13 20:21:21 2009 -0400
description:
listescape: Don't escape characters in namespace prefixes.

diffstat:

1 file changed, 31 insertions(+), 16 deletions(-)
src/plugins/listescape/listescape-plugin.c |   47 ++++++++++++++++++----------

diffs (145 lines):

diff -r 22b45d08cd4e -r 0463fc241aae src/plugins/listescape/listescape-plugin.c
--- a/src/plugins/listescape/listescape-plugin.c	Thu Aug 13 18:32:49 2009 -0400
+++ b/src/plugins/listescape/listescape-plugin.c	Thu Aug 13 20:21:21 2009 -0400
@@ -44,10 +44,23 @@ static MODULE_CONTEXT_DEFINE_INIT(listes
 static MODULE_CONTEXT_DEFINE_INIT(listescape_list_module,
 				  &mailbox_list_module_register);
 
-static const char *list_escape(struct mail_namespace *ns,
-			       const char *str, bool change_sep)
+static const char *
+list_escape(struct mail_namespace *ns, const char *str, bool vname)
 {
 	string_t *esc = t_str_new(64);
+	unsigned int i;
+
+	for (i = 0; str[i] != '\0'; i++) {
+		if (str[i] == '*' || str[i] == '%')
+			break;
+	}
+	if (i > ns->prefix_len)
+		i = ns->prefix_len;
+
+	if (vname && i > 0 && strncmp(ns->prefix, str, i) == 0) {
+		str_append_n(esc, str, i);
+		str += i;
+	}
 
 	if (*str == '~') {
 		str_printfa(esc, "%c%02x", escape_char, *str);
@@ -55,7 +68,7 @@ static const char *list_escape(struct ma
 	}
 	for (; *str != '\0'; str++) {
 		if (*str == ns->sep) {
-			if (change_sep)
+			if (!vname)
 				str_append_c(esc, ns->list->hierarchy_sep);
 			else
 				str_append_c(esc, *str);
@@ -104,18 +117,18 @@ listescape_mailbox_list_iter_init(struct
 	struct mailbox_list_iterate_context *ctx;
 	const char **escaped_patterns;
 	unsigned int i;
-	bool change_sep;
+	bool vname;
 
 	/* this is kind of kludgy. In ACL code we want to convert patterns,
 	   in maildir renaming code we don't. so for now just use the _RAW_LIST
 	   flag.. */
 	if ((flags & MAILBOX_LIST_ITER_RAW_LIST) == 0) {
-		change_sep = (flags & MAILBOX_LIST_ITER_VIRTUAL_NAMES) == 0;
+		vname = (flags & MAILBOX_LIST_ITER_VIRTUAL_NAMES) != 0;
 		escaped_patterns = t_new(const char *,
 					 str_array_length(patterns) + 1);
 		for (i = 0; patterns[i] != NULL; i++) {
 			escaped_patterns[i] =
-				list_escape(list->ns, patterns[i], change_sep);
+				list_escape(list->ns, patterns[i], vname);
 		}
 		patterns = escaped_patterns;
 	}
@@ -144,7 +157,9 @@ listescape_mailbox_list_iter_next(struct
 		return info;
 
 	str_truncate(mlist->list_name, 0);
-	list_unescape_str(ctx->list->ns, info->name, mlist->list_name);
+	str_append(mlist->list_name, ctx->list->ns->prefix);
+	list_unescape_str(ctx->list->ns, info->name + ctx->list->ns->prefix_len,
+			  mlist->list_name);
 	mlist->info = *info;
 	mlist->info.name = str_c(mlist->list_name);
 	return &mlist->info;
@@ -174,7 +189,7 @@ listescape_mailbox_open(struct mail_stor
 		LIST_ESCAPE_LIST_CONTEXT(storage->list);
 
 	if (!mlist->name_escaped)
-		name = list_escape(storage->ns, name, TRUE);
+		name = list_escape(storage->ns, name, FALSE);
 	return mstorage->module_ctx.super.
 		mailbox_open(storage, name, input, flags);
 }
@@ -186,7 +201,7 @@ listescape_mailbox_create(struct mail_st
 	struct listescape_mail_storage *mstorage =
 		LIST_ESCAPE_CONTEXT(storage);
 
-	name = list_escape(storage->ns, name, TRUE);
+	name = list_escape(storage->ns, name, FALSE);
 	return mstorage->module_ctx.super.
 		mailbox_create(storage, name, directory);
 }
@@ -198,7 +213,7 @@ listescape_delete_mailbox(struct mailbox
 	int ret;
 
 	/* at least quota plugin opens the mailbox when deleting it */
-	name = list_escape(list->ns, name, TRUE);
+	name = list_escape(list->ns, name, FALSE);
 	mlist->name_escaped = TRUE;
 	ret = mlist->module_ctx.super.delete_mailbox(list, name);
 	mlist->name_escaped = FALSE;
@@ -211,8 +226,8 @@ listescape_rename_mailbox(struct mailbox
 {
 	struct listescape_mailbox_list *mlist = LIST_ESCAPE_LIST_CONTEXT(list);
 
-	oldname = list_escape(list->ns, oldname, TRUE);
-	newname = list_escape(list->ns, newname, TRUE);
+	oldname = list_escape(list->ns, oldname, FALSE);
+	newname = list_escape(list->ns, newname, FALSE);
 	return mlist->module_ctx.super.rename_mailbox(list, oldname, newname);
 }
 
@@ -221,7 +236,7 @@ static int listescape_set_subscribed(str
 {
 	struct listescape_mailbox_list *mlist = LIST_ESCAPE_LIST_CONTEXT(list);
 
-	name = list_escape(list->ns, name, TRUE);
+	name = list_escape(list->ns, name, FALSE);
 	return mlist->module_ctx.super.set_subscribed(list, name, set);
 }
 
@@ -231,7 +246,7 @@ static int listescape_get_mailbox_name_s
 {
 	struct listescape_mailbox_list *mlist = LIST_ESCAPE_LIST_CONTEXT(list);
 
-	name = list_escape(list->ns, name, TRUE);
+	name = list_escape(list->ns, name, FALSE);
 	return mlist->module_ctx.super.
 		get_mailbox_name_status(list, name, status);
 }
@@ -241,7 +256,7 @@ static bool listescape_is_valid_existing
 {
 	struct listescape_mailbox_list *mlist = LIST_ESCAPE_LIST_CONTEXT(list);
 
-	name = list_escape(list->ns, name, TRUE);
+	name = list_escape(list->ns, name, FALSE);
 	return mlist->module_ctx.super.is_valid_existing_name(list, name);
 }
 
@@ -250,7 +265,7 @@ static bool listescape_is_valid_create_n
 {
 	struct listescape_mailbox_list *mlist = LIST_ESCAPE_LIST_CONTEXT(list);
 
-	name = list_escape(list->ns, name, TRUE);
+	name = list_escape(list->ns, name, FALSE);
 	return mlist->module_ctx.super.is_valid_create_name(list, name);
 }
 


More information about the dovecot-cvs mailing list