[Dovecot] Allowing tilde at start of mailbox names

pod pod at herald.ox.ac.uk
Wed Jul 25 16:35:56 EEST 2007


In lib-storage/index/maildir/maildir-storage.c
maildir_is_valid_create_name() and maildir_is_valid_existing_name() the
following sequence of tests appear but I don't really understand why

	if ((storage->flags & MAIL_STORAGE_FLAG_FULL_FS_ACCESS) != 0)
		return TRUE;

	if (*name == '~' || strchr(name, '/') != NULL)
		return FALSE;

If MAIL_STORAGE_FLAG_FULL_FS_ACCESS is set then the validator funcs return
TRUE immediately and code elsewhere will do appropriate home_exapand for
mailbox names.  However if MAIL_STORAGE_FLAG_FULL_FS_ACCESS is not set the
(*name == '~') test prevents mailbox names that begin with '~'.

Why is it not possible to have mailbox names that begin with '~' but
without '~' carrying any special meaning?

I have been working on a patch (appended but incomplete; the option only
works against maildir atm) that adds a new option mail_allow_tilde and my
admittedly limited testing seems to indicate that it does the right thing
but maybe I am barking up the wrong tree.  Am I missing something here?

----------------------------------------
# HG changeset patch
# User <pod at sysdev.oucs.ox.ac.uk>
# Date 1185368923 -3600
# Node ID ab9cf3790ea9b5486afa6498f60c6bf6fb2e5f1e
# Parent  a23be695672737967a10613d7dca2a6f53b5d96d
create new option mail_allow_tilde

diff -r a23be6956727 -r ab9cf3790ea9 src/lib-storage/index/maildir/maildir-storage.c
--- a/src/lib-storage/index/maildir/maildir-storage.c	Tue Jul 24 05:48:03 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-storage.c	Wed Jul 25 14:08:43 2007 +0100
@@ -240,7 +240,9 @@ static bool maildir_is_valid_create_name
 	if ((storage->flags & MAIL_STORAGE_FLAG_FULL_FS_ACCESS) != 0)
 		return TRUE;
 
-	if (*name == '~' || strchr(name, '/') != NULL)
+	if ((*name == '~' &&
+	     (storage->flags & MAIL_STORAGE_FLAG_ALLOW_TILDE) == 0) ||
+	     strchr(name, '/') != NULL)
 		return FALSE;
 
 	if (name[0] == '.' && (name[1] == '\0' ||
@@ -264,7 +266,9 @@ static bool maildir_is_valid_existing_na
 	if ((storage->flags & MAIL_STORAGE_FLAG_FULL_FS_ACCESS) != 0)
 		return TRUE;
 
-	if (*name == '~' || strchr(name, '/') != NULL)
+	if ((*name == '~' &&
+	     (storage->flags & MAIL_STORAGE_FLAG_ALLOW_TILDE) == 0) ||
+	    strchr(name, '/') != NULL)
 		return FALSE;
 
 	if (name[0] == '.' && (name[1] == '\0' ||
diff -r a23be6956727 -r ab9cf3790ea9 src/lib-storage/mail-storage.c
--- a/src/lib-storage/mail-storage.c	Tue Jul 24 05:48:03 2007 +0300
+++ b/src/lib-storage/mail-storage.c	Wed Jul 25 14:08:43 2007 +0100
@@ -66,6 +66,8 @@ void mail_storage_parse_env(enum mail_st
 	*flags_r = 0;
 	if (getenv("FULL_FILESYSTEM_ACCESS") != NULL)
 		*flags_r |= MAIL_STORAGE_FLAG_FULL_FS_ACCESS;
+	if (getenv("ALLOW_TILDE") != NULL)
+		*flags_r |= MAIL_STORAGE_FLAG_ALLOW_TILDE;
 	if (getenv("DEBUG") != NULL)
 		*flags_r |= MAIL_STORAGE_FLAG_DEBUG;
 	if (getenv("MMAP_DISABLE") != NULL)
diff -r a23be6956727 -r ab9cf3790ea9 src/lib-storage/mail-storage.h
--- a/src/lib-storage/mail-storage.h	Tue Jul 24 05:48:03 2007 +0300
+++ b/src/lib-storage/mail-storage.h	Wed Jul 25 14:08:43 2007 +0100
@@ -34,7 +34,9 @@ enum mail_storage_flags {
 	   fail to create the storage. */
 	MAIL_STORAGE_FLAG_NO_AUTOCREATE		= 0x200,
 	/* Rely on O_EXCL when creating dotlocks */
-	MAIL_STORAGE_FLAG_DOTLOCK_USE_EXCL	= 0x400
+	MAIL_STORAGE_FLAG_DOTLOCK_USE_EXCL	= 0x400,
+	/* Allow folder names to begin with '~' TILDE */
+	MAIL_STORAGE_FLAG_ALLOW_TILDE		= 0x800
 };
 
 enum mail_storage_lock_method {
diff -r a23be6956727 -r ab9cf3790ea9 src/master/mail-process.c
--- a/src/master/mail-process.c	Tue Jul 24 05:48:03 2007 +0300
+++ b/src/master/mail-process.c	Wed Jul 25 14:08:43 2007 +0100
@@ -254,6 +254,8 @@ mail_process_set_environment(struct sett
 		env_put("DEBUG=1");
 	if (set->mail_full_filesystem_access)
 		env_put("FULL_FILESYSTEM_ACCESS=1");
+	if (set->mail_allow_tilde)
+		env_put("ALLOW_TILDE=1");
 	if (set->pop3_no_flag_updates)
 		env_put("POP3_NO_FLAG_UPDATES=1");
 	if (set->pop3_reuse_xuidl)
diff -r a23be6956727 -r ab9cf3790ea9 src/master/master-settings-defs.c
--- a/src/master/master-settings-defs.c	Tue Jul 24 05:48:03 2007 +0300
+++ b/src/master/master-settings-defs.c	Wed Jul 25 14:08:43 2007 +0100
@@ -67,6 +67,7 @@ static struct setting_def setting_defs[]
 	DEF(SET_INT, mailbox_idle_check_interval),
 	DEF(SET_BOOL, mail_debug),
 	DEF(SET_BOOL, mail_full_filesystem_access),
+	DEF(SET_BOOL, mail_allow_tilde),
 	DEF(SET_INT, mail_max_keyword_length),
 	DEF(SET_BOOL, mail_save_crlf),
 	DEF(SET_BOOL, mail_read_mmaped),
diff -r a23be6956727 -r ab9cf3790ea9 src/master/master-settings.c
--- a/src/master/master-settings.c	Tue Jul 24 05:48:03 2007 +0300
+++ b/src/master/master-settings.c	Wed Jul 25 14:08:43 2007 +0100
@@ -216,6 +216,7 @@ struct settings default_settings = {
 	MEMBER(mailbox_idle_check_interval) 30,
 	MEMBER(mail_debug) FALSE,
 	MEMBER(mail_full_filesystem_access) FALSE,
+	MEMBER(mail_allow_tilde) FALSE,
 	MEMBER(mail_max_keyword_length) 50,
 	MEMBER(mail_save_crlf) FALSE,
 	MEMBER(mail_read_mmaped) FALSE,
diff -r a23be6956727 -r ab9cf3790ea9 src/master/master-settings.h
--- a/src/master/master-settings.h	Tue Jul 24 05:48:03 2007 +0300
+++ b/src/master/master-settings.h	Wed Jul 25 14:08:43 2007 +0100
@@ -75,6 +75,7 @@ struct settings {
 	unsigned int mailbox_idle_check_interval;
 	bool mail_debug;
 	bool mail_full_filesystem_access;
+	bool mail_allow_tilde;
 	unsigned int mail_max_keyword_length;
 	bool mail_save_crlf;
 	bool mail_read_mmaped;



More information about the dovecot mailing list