dovecot-2.1: maildir++: If listing finds non-mUTF7/UTF8 mailbox ...

dovecot at dovecot.org dovecot at dovecot.org
Wed Nov 9 22:48:34 EET 2011


details:   http://hg.dovecot.org/dovecot-2.1/rev/4d49122ba42a
changeset: 13691:4d49122ba42a
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Nov 09 22:58:38 2011 +0200
description:
maildir++: If listing finds non-mUTF7/UTF8 mailbox dir, rename it instead of assert-crashing later.

diffstat:

 src/lib-storage/list/mailbox-list-maildir-iter.c |  25 ++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

diffs (48 lines):

diff -r eace12589314 -r 4d49122ba42a src/lib-storage/list/mailbox-list-maildir-iter.c
--- a/src/lib-storage/list/mailbox-list-maildir-iter.c	Wed Nov 09 18:33:59 2011 +0200
+++ b/src/lib-storage/list/mailbox-list-maildir-iter.c	Wed Nov 09 22:58:38 2011 +0200
@@ -5,12 +5,15 @@
 #include "str.h"
 #include "ioloop.h"
 #include "unlink-directory.h"
+#include "unichar.h"
 #include "imap-match.h"
+#include "imap-utf7.h"
 #include "mailbox-tree.h"
 #include "mailbox-list-delete.h"
 #include "mailbox-list-subscriptions.h"
 #include "mailbox-list-maildir.h"
 
+#include <stdio.h>
 #include <dirent.h>
 #include <sys/stat.h>
 
@@ -285,6 +288,28 @@
 		return 0;
 
 	vname = mailbox_list_get_vname(list, storage_name);
+	if (!uni_utf8_str_is_valid(vname)) {
+		/* the storage_name is completely invalid, rename it to
+		   something more sensible. we could do this for all names that
+		   aren't valid mUTF-7, but that might lead to accidents in
+		   future when UTF-8 storage names are used */
+		const char *src = t_strdup_printf("%s/%s", ctx->dir, fname);
+		string_t *destvname = t_str_new(128);
+		string_t *dest = t_str_new(128);
+
+		(void)uni_utf8_get_valid_data((const void *)fname,
+					      strlen(fname), destvname);
+
+		str_append(dest, ctx->dir);
+		str_append_c(dest, '/');
+		(void)imap_utf8_to_utf7(str_c(destvname), dest);
+
+		if (rename(src, str_c(dest)) < 0 && errno != ENOENT)
+			i_error("rename(%s, %s) failed: %m", src, str_c(dest));
+		/* just skip this in this iteration, we'll see it on the
+		   next list */
+		return 0;
+	}
 
 	/* make sure the pattern matches */
 	match = imap_match(glob, vname);


More information about the dovecot-cvs mailing list