[dovecot-cvs] dovecot/src/imap commands-util.c, 1.52, 1.53 commands-util.h, 1.26, 1.27

tss at dovecot.org tss at dovecot.org
Tue Mar 13 19:17:13 EET 2007


Update of /var/lib/cvs/dovecot/src/imap
In directory talvi:/tmp/cvs-serv27638

Modified Files:
	commands-util.c commands-util.h 
Log Message:
Added client_find_namespace(). Handle virtual != real hierarchy separators
better. Give an error if real separator is tried to be used in the mailbox
name.



Index: commands-util.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/commands-util.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- commands-util.c	16 Nov 2006 00:16:32 -0000	1.52
+++ commands-util.c	13 Mar 2007 17:17:09 -0000	1.53
@@ -18,43 +18,66 @@
    to them, mbox/maildir currently allow paths only up to PATH_MAX. */
 #define MAILBOX_MAX_NAME_LEN 512
 
-struct mail_storage *
-client_find_storage(struct client_command_context *cmd, const char **mailbox)
+struct namespace *
+client_find_namespace(struct client_command_context *cmd, const char **mailbox)
 {
 	struct namespace *ns;
 
 	ns = namespace_find(cmd->client->namespaces, mailbox);
 	if (ns != NULL)
-		return ns->storage;
+		return ns;
 
 	client_send_tagline(cmd, "NO Unknown namespace.");
 	return NULL;
 }
 
+struct mail_storage *
+client_find_storage(struct client_command_context *cmd, const char **mailbox)
+{
+	struct namespace *ns;
+
+	ns = client_find_namespace(cmd, mailbox);
+	return ns == NULL ? NULL : ns->storage;
+}
+
 bool client_verify_mailbox_name(struct client_command_context *cmd,
 				const char *mailbox,
 				bool should_exist, bool should_not_exist)
 {
-	struct mail_storage *storage;
+	struct namespace *ns;
 	struct mailbox_list *list;
 	enum mailbox_name_status mailbox_status;
-	const char *p;
-	char sep;
+	const char *orig_mailbox, *p;
 
-	storage = client_find_storage(cmd, &mailbox);
-	if (storage == NULL)
+	orig_mailbox = mailbox;
+	ns = client_find_namespace(cmd, &mailbox);
+	if (ns == NULL)
 		return FALSE;
 
 	/* make sure it even looks valid */
-	sep = mail_storage_get_hierarchy_sep(storage);
 	if (*mailbox == '\0') {
 		client_send_tagline(cmd, "NO Empty mailbox name.");
 		return FALSE;
 	}
 
+	if (ns->real_sep != ns->sep && ns->prefix_len < strlen(orig_mailbox)) {
+		/* make sure there are no real separators used in the mailbox
+		   name. */
+		orig_mailbox += ns->prefix_len;
+		for (p = orig_mailbox; *p != '\0'; p++) {
+			if (*p == ns->real_sep) {
+				client_send_tagline(cmd, t_strdup_printf(
+					"NO Character not allowed "
+					"in mailbox name: '%c'",
+					ns->real_sep));
+				return FALSE;
+			}
+		}
+	}
+
 	/* make sure two hierarchy separators aren't next to each others */
 	for (p = mailbox+1; *p != '\0'; p++) {
-		if (p[0] == sep && p[-1] == sep) {
+		if (p[0] == ns->real_sep && p[-1] == ns->real_sep) {
 			client_send_tagline(cmd, "NO Invalid mailbox name.");
 			return FALSE;
 		}
@@ -66,10 +89,10 @@
 	}
 
 	/* check what our storage thinks of it */
-	list = mail_storage_get_list(storage);
+	list = mail_storage_get_list(ns->storage);
 	if (mailbox_list_get_mailbox_name_status(list, mailbox,
 						 &mailbox_status) < 0) {
-		client_send_storage_error(cmd, storage);
+		client_send_storage_error(cmd, ns->storage);
 		return FALSE;
 	}
 
@@ -87,13 +110,15 @@
 
 		client_send_tagline(cmd, t_strconcat(
 			"NO [TRYCREATE] Mailbox doesn't exist: ",
-			str_sanitize(mailbox, MAILBOX_MAX_NAME_LEN), NULL));
+			str_sanitize(orig_mailbox, MAILBOX_MAX_NAME_LEN),
+			NULL));
 		break;
 
 	case MAILBOX_NAME_INVALID:
 		client_send_tagline(cmd, t_strconcat(
 			"NO Invalid mailbox name: ",
-			str_sanitize(mailbox, MAILBOX_MAX_NAME_LEN), NULL));
+			str_sanitize(orig_mailbox, MAILBOX_MAX_NAME_LEN),
+			NULL));
 		break;
 
 	case MAILBOX_NAME_NOINFERIORS:

Index: commands-util.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/commands-util.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- commands-util.h	28 Jun 2006 13:10:32 -0000	1.26
+++ commands-util.h	13 Mar 2007 17:17:09 -0000	1.27
@@ -9,6 +9,10 @@
 struct mail_full_flags;
 struct mailbox_keywords;
 
+/* Finds namespace for given mailbox from namespaces. If not found,
+   sends "Unknown namespace" error message to client. */
+struct namespace *
+client_find_namespace(struct client_command_context *cmd, const char **mailbox);
 /* Finds mail storage for given mailbox from namespaces. If not found,
    sends "Unknown namespace" error message to client. */
 struct mail_storage *



More information about the dovecot-cvs mailing list