[dovecot-cvs] dovecot/src/imap commands-util.c, 1.47.2.1, 1.47.2.2 commands-util.h, 1.25, 1.25.2.1

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


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

Modified Files:
      Tag: branch_1_0
	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.47.2.1
retrieving revision 1.47.2.2
diff -u -d -r1.47.2.1 -r1.47.2.2
--- commands-util.c	17 Jun 2006 14:02:43 -0000	1.47.2.1
+++ commands-util.c	13 Mar 2007 17:17:05 -0000	1.47.2.2
@@ -18,42 +18,65 @@
    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;
 	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;
 		}
@@ -65,9 +88,9 @@
 	}
 
 	/* check what our storage thinks of it */
-	if (mail_storage_get_mailbox_name_status(storage, mailbox,
+	if (mail_storage_get_mailbox_name_status(ns->storage, mailbox,
 						 &mailbox_status) < 0) {
-		client_send_storage_error(cmd, storage);
+		client_send_storage_error(cmd, ns->storage);
 		return FALSE;
 	}
 
@@ -85,13 +108,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.25
retrieving revision 1.25.2.1
diff -u -d -r1.25 -r1.25.2.1
--- commands-util.h	13 Jan 2006 20:25:59 -0000	1.25
+++ commands-util.h	13 Mar 2007 17:17:06 -0000	1.25.2.1
@@ -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