]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Maildir: If trying to open a directory as message, try to rmdir it.
authorTimo Sirainen <tss@iki.fi>
Thu, 12 Aug 2010 15:29:41 +0000 (16:29 +0100)
committerTimo Sirainen <tss@iki.fi>
Thu, 12 Aug 2010 15:29:41 +0000 (16:29 +0100)
src/lib-storage/index/maildir/maildir-mail.c

index 2149dcfaadd3b7a6b88e064cecd7846453be3b56..4e1c1354f698d7fbf13b2b1e90b6984a625bcef9 100644 (file)
@@ -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;
 }