From: Timo Sirainen Date: Thu, 12 Aug 2010 15:29:41 +0000 (+0100) Subject: Maildir: If trying to open a directory as message, try to rmdir it. X-Git-Tag: 2.0.rc6~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c60d1eda4df179d83d531647732d5e3e45064219;p=thirdparty%2Fdovecot%2Fcore.git Maildir: If trying to open a directory as message, try to rmdir it. --- diff --git a/src/lib-storage/index/maildir/maildir-mail.c b/src/lib-storage/index/maildir/maildir-mail.c index 2149dcfaad..4e1c1354f6 100644 --- a/src/lib-storage/index/maildir/maildir-mail.c +++ b/src/lib-storage/index/maildir/maildir-mail.c @@ -58,6 +58,22 @@ do_stat(struct maildir_mailbox *mbox, const char *path, struct stat *st) 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 @@ maildir_open_mail(struct maildir_mailbox *mbox, struct mail *mail, } 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; }