int index_storage_mailbox_exists(struct mailbox *box,
enum mailbox_existence *existence_r)
+{
+ return index_storage_mailbox_exists_full(box, NULL, existence_r);
+}
+
+int index_storage_mailbox_exists_full(struct mailbox *box, const char *subdir,
+ enum mailbox_existence *existence_r)
{
struct stat st;
const char *path, *path2;
/* see if it's selectable */
path = mailbox_list_get_path(box->list, box->name,
MAILBOX_LIST_PATH_TYPE_MAILBOX);
+ if (subdir != NULL)
+ path = t_strconcat(path, "/", subdir, NULL);
if (stat(path, &st) == 0) {
*existence_r = MAILBOX_EXISTENCE_SELECT;
return 0;
const char *index_prefix);
int index_storage_mailbox_exists(struct mailbox *box,
enum mailbox_existence *existence_r);
+int index_storage_mailbox_exists_full(struct mailbox *box, const char *subdir,
+ enum mailbox_existence *existence_r);
int index_storage_mailbox_open(struct mailbox *box, bool move_to_memory);
int index_storage_mailbox_enable(struct mailbox *box,
enum mailbox_feature feature);
return FALSE;
}
+static int maildir_mailbox_exists(struct mailbox *box,
+ enum mailbox_existence *existence_r)
+{
+ return index_storage_mailbox_exists_full(box, "cur", existence_r);
+}
+
static int maildir_mailbox_open(struct mailbox *box)
{
const char *box_path = mailbox_get_path(box);
strcmp(name, "tmp") == 0;
}
-static int
-maildir_list_get_mailbox_flags(struct mailbox_list *list,
- const char *dir, const char *fname,
- enum mailbox_list_file_type type,
- struct stat *st_r,
- enum mailbox_info_flags *flags)
-{
- struct maildir_mailbox_list_context *mlist = MAILDIR_LIST_CONTEXT(list);
- struct stat st2;
- const char *cur_path;
- int ret;
-
- ret = mlist->module_ctx.super.
- get_mailbox_flags(list, dir, fname, type, st_r, flags);
- if (ret <= 0 || MAILBOX_INFO_FLAGS_FINISHED(*flags))
- return ret;
-
- /* see if it's a selectable mailbox. after that we can figure out based
- on the link count if we have child mailboxes or not. for a
- selectable mailbox we have 3 more links (cur/, new/ and tmp/)
- than non-selectable. */
- cur_path = t_strconcat(dir, "/", fname, "/cur", NULL);
- 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
- *flags |= MAILBOX_NOCHILDREN;
- } else {
- if (st_r->st_nlink > 5)
- *flags |= MAILBOX_CHILDREN;
- else
- *flags |= MAILBOX_NOCHILDREN;
- }
- return 1;
-}
-
static void maildir_storage_add_list(struct mail_storage *storage,
struct mailbox_list *list)
{
mlist->set = mail_storage_get_driver_settings(storage);
list->v.is_internal_name = maildir_is_internal_name;
- list->v.get_mailbox_flags = maildir_list_get_mailbox_flags;
MODULE_CONTEXT_SET(list, maildir_mailbox_list_module, mlist);
}
maildir_storage_is_readonly,
index_storage_allow_new_keywords,
index_storage_mailbox_enable,
- index_storage_mailbox_exists,
+ maildir_mailbox_exists,
maildir_mailbox_open,
maildir_mailbox_close,
index_storage_mailbox_free,
#include "lib.h"
#include "array.h"
#include "imap-match.h"
+#include "mail-storage.h"
#include "mailbox-tree.h"
#include "mailbox-list-subscriptions.h"
#include "mailbox-list-fs.h"
if (ret <= 0)
return ret;
+ if (!MAILBOX_INFO_FLAGS_FINISHED(ctx->info.flags)) {
+ struct mailbox *box;
+ enum mailbox_existence existence;
+
+ box = mailbox_alloc(ctx->ctx.list, list_path,
+ MAILBOX_FLAG_KEEP_RECENT);
+ ret = mailbox_exists(box, &existence);
+ mailbox_free(&box);
+
+ if (ret < 0)
+ return -1;
+ switch (existence) {
+ case MAILBOX_EXISTENCE_NONE:
+ ctx->info.flags |= MAILBOX_NONEXISTENT;
+ break;
+ case MAILBOX_EXISTENCE_NOSELECT:
+ ctx->info.flags |= MAILBOX_NOSELECT;
+ break;
+ case MAILBOX_EXISTENCE_SELECT:
+ break;
+ }
+ }
+
if (ctx->dir->delayed_send) {
/* send the parent directory first, then handle this
file again if needed */
#include <dirent.h>
#include <sys/stat.h>
-#define VIRTUAL_LIST_CONTEXT(obj) \
- MODULE_CONTEXT(obj, virtual_mailbox_list_module)
-
-struct virtual_mailbox_list {
- union mailbox_list_module_context module_ctx;
-};
-
extern struct mail_storage virtual_storage;
extern struct mailbox virtual_mailbox;
extern struct virtual_mailbox_vfuncs virtual_mailbox_vfuncs;
struct virtual_storage_module virtual_storage_module =
MODULE_CONTEXT_INIT(&mail_storage_module_register);
-static MODULE_CONTEXT_DEFINE_INIT(virtual_mailbox_list_module,
- &mailbox_list_module_register);
static bool ns_is_visible(struct mail_namespace *ns)
{
i_free_and_null(mbox->vseq_lookup_prev_mailbox);
}
+static int virtual_mailbox_exists(struct mailbox *box,
+ enum mailbox_existence *existence_r)
+{
+ return index_storage_mailbox_exists_full(box, VIRTUAL_CONFIG_FNAME,
+ existence_r);
+}
+
static int virtual_mailbox_open(struct mailbox *box)
{
struct virtual_mailbox *mbox = (struct virtual_mailbox *)box;
}
}
-static int
-virtual_list_get_mailbox_flags(struct mailbox_list *list,
- const char *dir, const char *fname,
- enum mailbox_list_file_type type,
- struct stat *st_r,
- enum mailbox_info_flags *flags)
-{
- struct virtual_mailbox_list *mlist = VIRTUAL_LIST_CONTEXT(list);
- struct stat st2;
- const char *virtual_path;
- int ret;
-
- ret = mlist->module_ctx.super.
- get_mailbox_flags(list, dir, fname, type, st_r, flags);
- if (ret <= 0 || MAILBOX_INFO_FLAGS_FINISHED(*flags))
- return ret;
-
- /* see if it's a selectable mailbox */
- virtual_path = t_strconcat(dir, "/", fname, "/"VIRTUAL_CONFIG_FNAME,
- NULL);
- if (stat(virtual_path, &st2) < 0)
- *flags |= MAILBOX_NOSELECT;
- return ret;
-}
-
-static void virtual_storage_add_list(struct mail_storage *storage ATTR_UNUSED,
- struct mailbox_list *list)
-{
- struct mailbox_list_vfuncs *v = list->vlast;
- struct virtual_mailbox_list *mlist;
-
- mlist = p_new(list->pool, struct virtual_mailbox_list, 1);
- mlist->module_ctx.super = *v;
- list->vlast = &mlist->module_ctx.super;
-
- v->get_mailbox_flags = virtual_list_get_mailbox_flags;
-
- MODULE_CONTEXT_SET(list, virtual_mailbox_list_module, mlist);
-}
-
static int virtual_backend_uidmap_cmp(const uint32_t *uid,
const struct virtual_backend_uidmap *map)
{
virtual_storage_alloc,
NULL,
NULL,
- virtual_storage_add_list,
+ NULL,
virtual_storage_get_list_settings,
NULL,
virtual_mailbox_alloc,
index_storage_is_readonly,
index_storage_allow_new_keywords,
index_storage_mailbox_enable,
- index_storage_mailbox_exists,
+ virtual_mailbox_exists,
virtual_mailbox_open,
virtual_mailbox_close,
virtual_mailbox_free,