]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mailbox_list_mailbox(): Fixed INBOX and root dir lookups.
authorTimo Sirainen <tss@iki.fi>
Sun, 4 Apr 2010 23:56:11 +0000 (02:56 +0300)
committerTimo Sirainen <tss@iki.fi>
Sun, 4 Apr 2010 23:56:11 +0000 (02:56 +0300)
--HG--
branch : HEAD

src/lib-storage/index/maildir/maildir-storage.c
src/lib-storage/list/mailbox-list-maildir-iter.c
src/lib-storage/mailbox-list.c

index 9d02890a7d2ac67e61d5aec26e61c4a43dd26452..34fe49fdf1949fcc215e37dd89536e650b4663c2 100644 (file)
@@ -521,8 +521,11 @@ maildir_list_get_mailbox_flags(struct mailbox_list *list,
           selectable mailbox we have 3 more links (cur/, new/ and tmp/)
           than non-selectable. */
        cur_path = t_strconcat(dir, "/", fname, "/cur", NULL);
-       if (stat(cur_path, &st2) < 0 || !S_ISDIR(st2.st_mode)) {
-               *flags |= MAILBOX_NOSELECT;
+       if ((ret = stat(cur_path, &st2)) < 0 || !S_ISDIR(st2.st_mode)) {
+               if (ret < 0 && errno == ENOENT)
+                       *flags |= MAILBOX_NONEXISTENT;
+               else
+                       *flags |= MAILBOX_NOSELECT;
                if (st_r->st_nlink > 2)
                        *flags |= MAILBOX_CHILDREN;
                else
index fb5ed9771d44800e47004633319176c2fc43f3ab..f6fd393137d4ba655564596e6f394c351b952cab 100644 (file)
@@ -174,7 +174,8 @@ maildir_get_type(const char *dir, const char *fname,
        const char *path;
        struct stat st;
 
-       path = t_strdup_printf("%s/%s", dir, fname);
+       path = *fname == '\0' ? dir :
+               t_strdup_printf("%s/%s", dir, fname);
        if (stat(path, &st) < 0) {
                if (errno == ENOENT) {
                        /* just deleted? */
@@ -215,7 +216,7 @@ int maildir_list_get_mailbox_flags(struct mailbox_list *list,
        case MAILBOX_LIST_FILE_TYPE_UNKNOWN:
        case MAILBOX_LIST_FILE_TYPE_SYMLINK:
                /* need to check with stat() to be sure */
-               if (!list->mail_set->maildir_stat_dirs &&
+               if (!list->mail_set->maildir_stat_dirs && *fname != '\0' &&
                    strcmp(list->name, MAILBOX_LIST_NAME_MAILDIRPLUSPLUS) == 0 &&
                    strncmp(fname, ".nfs", 4) != 0) {
                        /* just assume it's a valid mailbox */
@@ -248,7 +249,12 @@ int maildir_list_get_mailbox_flags(struct mailbox_list *list,
        case MAILBOX_LIST_FILE_TYPE_SYMLINK:
                i_unreached();
        }
-       *flags_r |= MAILBOX_SELECT;
+       if (*fname != '\0') {
+               /* this tells maildir storage code that it doesn't need to
+                  see if cur/ exists, because just the existence of .dir/
+                  assumes that the mailbox exists. */
+               *flags_r |= MAILBOX_SELECT;
+       }
        return 1;
 }
 
index a113ee43666393f3d54fb23a31406aeceb18ee2c..2e304d69502b484f02b92bb8f554cb4717c2f329 100644 (file)
@@ -673,21 +673,32 @@ int mailbox_list_iter_deinit(struct mailbox_list_iterate_context **_ctx)
 int mailbox_list_mailbox(struct mailbox_list *list, const char *name,
                         enum mailbox_info_flags *flags_r)
 {
-       const char *path, *fname;
+       const char *path, *fname, *rootdir;
        struct stat st;
+       unsigned int len;
 
+       rootdir = mailbox_list_get_path(list, NULL,
+                                       MAILBOX_LIST_PATH_TYPE_MAILBOX);
        path = mailbox_list_get_path(list, name, MAILBOX_LIST_PATH_TYPE_DIR);
        if (path == NULL) {
                /* shouldn't happen with anything except shared mailboxes */
                return 0;
        }
-       fname = strrchr(path, '/');
-       if (fname == NULL) {
-               fname = path;
-               path = "/";
+
+       len = strlen(rootdir);
+       if (strncmp(path, rootdir, len) == 0 && path[len] == '/') {
+               fname = strrchr(path, '/');
+               if (fname == NULL) {
+                       fname = path;
+                       path = "/";
+               } else {
+                       path = t_strdup_until(path, fname);
+                       fname++;
+               }
        } else {
-               path = t_strdup_until(path, fname);
-               fname++;
+               /* a) looking up INBOX that's elsewhere
+                  b) looking up the root dir itself (as INBOX or "") */
+               fname = "";
        }
        return list->v.get_mailbox_flags(list, path, fname,
                                         MAILBOX_LIST_FILE_TYPE_UNKNOWN,