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)
}
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;
}