bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainenextern struct mail_storage mdbox_deleted_storage;
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainenextern struct dbox_storage_vfuncs mdbox_deleted_dbox_storage_vfuncs;
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainenstatic struct mail_storage *mdbox_deleted_storage_alloc(void)
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen pool = pool_alloconly_create("mdbox deleted storage", 2048);
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen storage = p_new(pool, struct mdbox_storage, 1);
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen storage->storage.v = mdbox_dbox_storage_vfuncs;
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen storage->storage.storage = mdbox_deleted_storage;
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainenstatic struct mailbox *
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainenmdbox_deleted_mailbox_alloc(struct mail_storage *storage,
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen flags |= MAILBOX_FLAG_READONLY | MAILBOX_FLAG_NO_INDEX_FILES;
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen pool = pool_alloconly_create("mdbox deleted mailbox", 1024*3);
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen index_storage_mailbox_alloc(&mbox->box, vname, flags, MAIL_INDEX_PREFIX);
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainenmdbox_deleted_mailbox_create_indexes(struct mailbox *box,
b67974c4b89ab6950c2694cce8dfb1b6561cc084Josef 'Jeff' Sipek struct mdbox_mailbox *mbox = MDBOX_MAILBOX(box);
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen struct mail_index_transaction *new_trans = NULL;
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen if (update != NULL && update->uid_validity != 0)
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen new_trans = mail_index_transaction_begin(box->view, 0);
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen offsetof(struct mail_index_header, uid_validity),
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen if (mail_index_transaction_commit(&new_trans) < 0) {
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainenstatic const char *
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainenmdbox_get_attachment_path_suffix(struct dbox_file *file ATTR_UNUSED)
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainenmdbox_deleted_mailbox_get_metadata(struct mailbox *box,
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen if (index_mailbox_get_metadata(box, items, metadata_r) < 0)
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainenmdbox_deleted_save_alloc(struct mailbox_transaction_context *t)
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainenmdbox_deleted_save_begin(struct mail_save_context *ctx,
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen mail_storage_set_error(ctx->transaction->box->storage,
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen MAIL_ERROR_NOTPOSSIBLE, "mdbox_deleted doesn't support saving mails");
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainenmdbox_deleted_save_continue(struct mail_save_context *ctx ATTR_UNUSED)
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainenstatic int mdbox_deleted_save_finish(struct mail_save_context *ctx)
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainenmdbox_deleted_save_cancel(struct mail_save_context *ctx)
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainenstatic int mdbox_deleted_sync(struct mdbox_mailbox *mbox,
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen /* don't bother supporting incremental syncs */
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen if (!mbox->box.inbox_user && mbox->box.name[0] != '\0') {
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen /* since mailbox list currently shows all the existing
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen mailboxes, we don't want all of them to list the deleted
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen messages. only show messages in user's INBOX or the
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen namespace prefix. */
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen if (mdbox_deleted_mailbox_create_indexes(&mbox->box, NULL, NULL) < 0)
0e94016c18197cb42d00be0085e6da4223a1c84eTimo Sirainen sync_flags = index_storage_get_sync_flags(&mbox->box);
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen if (mail_index_sync_begin(mbox->box.index, &index_sync_ctx,
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen map_count = mdbox_map_get_messages_count(mbox->storage->map);
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen for (map_seq = 1; map_seq <= map_count; map_seq++) {
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen if (mdbox_map_lookup_seq_full(mbox->storage->map, map_seq,
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen rec.map_uid = mdbox_map_lookup_uid(mbox->storage->map,
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen if (mail_index_sync_commit(&index_sync_ctx) < 0) {
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainenmdbox_deleted_storage_sync_init(struct mailbox *box,
b67974c4b89ab6950c2694cce8dfb1b6561cc084Josef 'Jeff' Sipek struct mdbox_mailbox *mbox = MDBOX_MAILBOX(box);
e098ac1cd4ff0afb33b22cc7fd288014f4fdb0bcTimo Sirainen if (index_mailbox_want_full_sync(&mbox->box, flags) ||
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen ret = mdbox_deleted_sync(mbox, mdbox_sync_flags);
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen return index_mailbox_sync_init(box, flags, ret < 0);
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen .class_flags = MAIL_STORAGE_CLASS_FLAG_UNIQUE_ROOT |
b90c23a9862b91594959b918b035d73f7bc0b265Timo Sirainen MAIL_STORAGE_CLASS_FLAG_HAVE_MAIL_SAVE_GUIDS |