From 1a20246d00da488b28ff34a7fbd08518e29253f8 Mon Sep 17 00:00:00 2001 From: Markus Valentin Date: Fri, 20 Jan 2023 16:41:47 +0100 Subject: [PATCH] maildir: maildir_mailbox_open() - Split off maildir_is_selectable() --- .../index/maildir/maildir-storage.c | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/lib-storage/index/maildir/maildir-storage.c b/src/lib-storage/index/maildir/maildir-storage.c index 28c6f3ec30..6cb058bd4c 100644 --- a/src/lib-storage/index/maildir/maildir-storage.c +++ b/src/lib-storage/index/maildir/maildir-storage.c @@ -367,11 +367,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 @@ -407,10 +419,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; -- 2.47.3