]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
maildir: maildir_mailbox_open() - Split off maildir_is_selectable()
authorMarkus Valentin <markus.valentin@open-xchange.com>
Fri, 20 Jan 2023 15:41:47 +0000 (16:41 +0100)
committerMarkus Valentin <markus.valentin@open-xchange.com>
Thu, 2 Feb 2023 07:20:11 +0000 (08:20 +0100)
src/lib-storage/index/maildir/maildir-storage.c

index df02869f369e661b7ba22a9acb99cc6115d4047b..f6537d88a2e5cbcae7b44cfa39ba87fc54d65bd1 100644 (file)
@@ -371,11 +371,23 @@ static bool maildir_has_any_subdir(const char *box_path,
        return FALSE;
 }
 
+static bool maildir_is_selectable(const char *box_path,
+                                 const char *root_dir,
+                                 const char **error_path_r)
+{
+       struct stat st;
+
+       *error_path_r = box_path;
+       if (strcmp(box_path, root_dir) == 0)
+               return maildir_has_any_subdir(box_path, error_path_r);
+       else
+               return stat(box_path, &st) == 0;
+}
+
 static int maildir_mailbox_open(struct mailbox *box)
 {
        const char *box_path = mailbox_get_path(box);
        const char *root_dir;
-       struct stat st;
        int ret;
 
        /* begin by checking if tmp/ directory exists and if it should be
@@ -411,10 +423,8 @@ static int maildir_mailbox_open(struct mailbox *box)
           exists. Instead, we return that mailbox doesn't exist, so the
           caller goes to the INBOX autocreation code path similarly as with
           other mailboxes. This is needed e.g. for welcome plugin to work. */
-       const char *error_path = box_path;
-       if ((strcmp(box_path, root_dir) == 0 &&
-            maildir_has_any_subdir(box_path, &error_path)) ||
-           (stat(box_path, &st) == 0)) {
+       const char *error_path;
+       if (maildir_is_selectable(box_path, root_dir, &error_path)) {
                /* yes, we'll need to create the missing dirs */
                if (create_maildir_subdirs(box, TRUE) < 0)
                        return -1;