dovecot-2.0: Maildir: If trying to open a directory as message, ...

dovecot at dovecot.org dovecot at dovecot.org
Thu Aug 12 18:30:04 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/651e51de34b7
changeset: 11987:651e51de34b7
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Aug 12 16:29:41 2010 +0100
description:
Maildir: If trying to open a directory as message, try to rmdir it.

diffstat:

 src/lib-storage/index/maildir/maildir-mail.c |  32 ++++++++++++++++++++++++++++++--
 1 files changed, 30 insertions(+), 2 deletions(-)

diffs (49 lines):

diff -r faac0d16d141 -r 651e51de34b7 src/lib-storage/index/maildir/maildir-mail.c
--- a/src/lib-storage/index/maildir/maildir-mail.c	Thu Aug 12 16:29:15 2010 +0100
+++ b/src/lib-storage/index/maildir/maildir-mail.c	Thu Aug 12 16:29:41 2010 +0100
@@ -58,6 +58,22 @@
 	return -1;
 }
 
+static int
+maildir_rmdir_unexpected_dir(struct mail_storage *storage, const char *path)
+{
+	if (rmdir(path) == 0) {
+		mail_storage_set_critical(storage,
+			"Maildir: rmdir()ed unwanted empty directory: %s",
+			path);
+		return 0;
+	} else {
+		mail_storage_set_critical(storage,
+			"Maildir: Found unwanted directory %s, "
+			"but rmdir() failed: %m", path);
+		return -1;
+	}
+}
+
 static struct istream *
 maildir_open_mail(struct maildir_mailbox *mbox, struct mail *mail,
 		  bool *deleted_r)
@@ -88,8 +104,20 @@
 	}
 
 	input = i_stream_create_fd(ctx.fd, 0, TRUE);
-	i_stream_set_name(input, ctx.path);
-	index_mail_set_read_buffer_size(mail, input);
+	if (input->stream_errno == EISDIR) {
+		/* there's a directory in maildir. many installations seem to
+		   have messed up something and causing "cur", "new" and "tmp"
+		   directories to be created under the "cur" directory.
+		   if the directory is empty, just get rid of it and log an
+		   error */
+		i_stream_destroy(&input);
+		if (maildir_rmdir_unexpected_dir(&mbox->storage->storage,
+						 ctx.path) == 0)
+			*deleted_r = TRUE;
+	} else {
+		i_stream_set_name(input, ctx.path);
+		index_mail_set_read_buffer_size(mail, input);
+	}
 	i_free(ctx.path);
 	return input;
 }


More information about the dovecot-cvs mailing list