}
static void
-index_list_try_delete(struct index_mailbox_list *list, const char *name,
+index_list_try_delete(struct mailbox_list *_list, const char *name,
enum mailbox_list_path_type type)
{
- struct mailbox_list *_list = &list->list;
const char *mailbox_path, *path;
if (mailbox_list_get_path(_list, name, MAILBOX_LIST_PATH_TYPE_MAILBOX,
}
static void
-index_list_delete_finish(struct index_mailbox_list *list, const char *name)
+index_list_delete_finish(struct mailbox_list *list, const char *name)
{
index_list_try_delete(list, name, MAILBOX_LIST_PATH_TYPE_INDEX);
index_list_try_delete(list, name, MAILBOX_LIST_PATH_TYPE_CONTROL);
index_list_try_delete(list, name, MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX);
}
-static int
-index_list_delete_entry(struct index_mailbox_list *list, const char *name,
- bool delete_selectable)
-{
- struct mailbox_list_index_sync_context *sync_ctx;
- struct mailbox_list_index_record rec;
- struct mailbox_list_index_node *node;
- const void *data;
- bool expunged;
- uint32_t seq;
-
- if (mailbox_list_index_sync_begin(&list->list, &sync_ctx) < 0)
- return -1;
-
- node = mailbox_list_index_lookup(&list->list, name);
- if (node == NULL) {
- (void)mailbox_list_index_sync_end(&sync_ctx, FALSE);
- mailbox_list_set_error(&list->list, MAIL_ERROR_NOTFOUND,
- T_MAIL_ERR_MAILBOX_NOT_FOUND(name));
- return -1;
- }
- if (!mail_index_lookup_seq(sync_ctx->view, node->uid, &seq))
- i_panic("mailbox list index: lost uid=%u", node->uid);
- if (delete_selectable) {
- /* make it at least non-selectable */
- node->flags = MAILBOX_LIST_INDEX_FLAG_NOSELECT;
- mail_index_update_flags(sync_ctx->trans, seq, MODIFY_REPLACE,
- (enum mail_flags)node->flags);
-
- mail_index_lookup_ext(sync_ctx->view, seq,
- sync_ctx->ilist->ext_id,
- &data, &expunged);
- i_assert(data != NULL && !expunged);
- memcpy(&rec, data, sizeof(rec));
- rec.uid_validity = 0;
- memset(&rec.guid, 0, sizeof(rec.guid));
- mail_index_update_ext(sync_ctx->trans, seq,
- sync_ctx->ilist->ext_id, &rec, NULL);
- }
- if (node->children != NULL) {
- /* can't delete this directory before its children,
- but we may have made it non-selectable already */
- if (mailbox_list_index_sync_end(&sync_ctx, TRUE) < 0)
- return -1;
- return 0;
- }
-
- /* we can remove the entire node */
- mail_index_expunge(sync_ctx->trans, seq);
- mailbox_list_index_node_unlink(sync_ctx->ilist, node);
-
- if (mailbox_list_index_sync_end(&sync_ctx, TRUE) < 0)
- return -1;
- return 1;
-}
-
static int
index_list_delete_mailbox(struct mailbox_list *_list, const char *name)
{
- struct index_mailbox_list *list = (struct index_mailbox_list *)_list;
const char *path;
int ret;
}
if (ret == 0 || (_list->props & MAILBOX_LIST_PROP_AUTOCREATE_DIRS) != 0)
- index_list_delete_finish(list, name);
+ index_list_delete_finish(_list, name);
if (ret == 0) {
- if (index_list_delete_entry(list, name, TRUE) < 0)
+ if (mailbox_list_index_delete_entry(_list, name, TRUE) < 0)
return -1;
}
return ret;
static int
index_list_delete_dir(struct mailbox_list *_list, const char *name)
{
- struct index_mailbox_list *list = (struct index_mailbox_list *)_list;
int ret;
- if ((ret = index_list_delete_entry(list, name, FALSE)) < 0)
+ if ((ret = mailbox_list_index_delete_entry(_list, name, FALSE)) < 0)
return -1;
if (ret == 0) {
mailbox_list_set_error(_list, MAIL_ERROR_EXISTS,
ret = mailbox_list_index_sync_list(sync_ctx);
return mailbox_list_index_sync_end(&sync_ctx, ret == 0);
}
+
+int mailbox_list_index_delete_entry(struct mailbox_list *list, const char *name,
+ bool delete_selectable)
+{
+ struct mailbox_list_index_sync_context *sync_ctx;
+ struct mailbox_list_index_record rec;
+ struct mailbox_list_index_node *node;
+ const void *data;
+ bool expunged;
+ uint32_t seq;
+
+ if (mailbox_list_index_sync_begin(list, &sync_ctx) < 0)
+ return -1;
+
+ node = mailbox_list_index_lookup(list, name);
+ if (node == NULL) {
+ (void)mailbox_list_index_sync_end(&sync_ctx, FALSE);
+ mailbox_list_set_error(list, MAIL_ERROR_NOTFOUND,
+ T_MAIL_ERR_MAILBOX_NOT_FOUND(name));
+ return -1;
+ }
+ if (!mail_index_lookup_seq(sync_ctx->view, node->uid, &seq))
+ i_panic("mailbox list index: lost uid=%u", node->uid);
+ if (delete_selectable) {
+ /* make it at least non-selectable */
+ node->flags = MAILBOX_LIST_INDEX_FLAG_NOSELECT;
+ mail_index_update_flags(sync_ctx->trans, seq, MODIFY_REPLACE,
+ (enum mail_flags)node->flags);
+
+ mail_index_lookup_ext(sync_ctx->view, seq,
+ sync_ctx->ilist->ext_id,
+ &data, &expunged);
+ i_assert(data != NULL && !expunged);
+ memcpy(&rec, data, sizeof(rec));
+ rec.uid_validity = 0;
+ memset(&rec.guid, 0, sizeof(rec.guid));
+ mail_index_update_ext(sync_ctx->trans, seq,
+ sync_ctx->ilist->ext_id, &rec, NULL);
+ }
+ if (node->children != NULL) {
+ /* can't delete this directory before its children,
+ but we may have made it non-selectable already */
+ if (mailbox_list_index_sync_end(&sync_ctx, TRUE) < 0)
+ return -1;
+ return 0;
+ }
+
+ /* we can remove the entire node */
+ mail_index_expunge(sync_ctx->trans, seq);
+ mailbox_list_index_node_unlink(sync_ctx->ilist, node);
+
+ if (mailbox_list_index_sync_end(&sync_ctx, TRUE) < 0)
+ return -1;
+ return 1;
+}