static void snarf_mailbox_allocated(struct mailbox *box) { struct snarf_mail_storage *sstorage = SNARF_CONTEXT(box->storage); struct mailbox_vfuncs *v = box->vlast; struct snarf_mailbox *sbox; struct mailbox_list *snarf_list; const char *snarf_name; if (!box->inbox_user) return; if (sstorage != NULL && sstorage->snarfing_disabled) return; if (!snarf_box_find(box->storage->user, &snarf_list, &snarf_name)) return; sbox = p_new(box->pool, struct snarf_mailbox, 1); sbox->module_ctx.super = *v; box->vlast = &sbox->module_ctx.super; sbox->snarf_box = mailbox_alloc(snarf_list, snarf_name, MAILBOX_FLAG_KEEP_LOCKED); v->sync_init = snarf_sync_init; v->free = snarf_mailbox_free; MODULE_CONTEXT_SET(box, snarf_storage_module, sbox); }
static void snarf_mailbox_free(struct mailbox *box) { struct snarf_mailbox *sbox = SNARF_CONTEXT(box); mailbox_free(&sbox->snarf_box); sbox->module_ctx.super.free(box); }
static struct mailbox_sync_context * snarf_sync_init(struct mailbox *box, enum mailbox_sync_flags flags) { struct snarf_mailbox *sbox = SNARF_CONTEXT(box); (void)snarf(sbox->snarf_box, box); return sbox->module_ctx.super.sync_init(box, flags); }
static struct mailbox_sync_context * snarf_sync_init(struct mailbox *box, enum mailbox_sync_flags flags) { struct snarf_mailbox *sbox = SNARF_CONTEXT(box); (void)snarf(sbox->snarf_box, box); /* close the mailbox so that we don't have to keep it locked */ (void)mailbox_close(sbox->snarf_box); return sbox->module_ctx.super.sync_init(box, flags); }
static struct mailbox * snarf_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list, const char *vname, enum mailbox_flags flags) { struct snarf_mail_storage *sstorage = SNARF_CONTEXT(storage); struct mail_namespace *ns = mailbox_list_get_namespace(list); struct mailbox *box; struct mailbox_list *snarf_list; const char *snarf_name; struct stat st; if (strcmp(vname, "INBOX") == 0 && (ns->flags & NAMESPACE_FLAG_INBOX_USER) != 0) { if (stat(sstorage->snarf_path, &st) == 0) sstorage->snarfing_disabled = FALSE; else { if (errno != ENOENT) { mail_storage_set_critical(storage, "stat(%s) failed: %m", sstorage->snarf_path); } sstorage->snarfing_disabled = TRUE; /* use the snarf box as our real INBOX */ if (snarf_box_find(storage->user, &snarf_list, &snarf_name)) { list = snarf_list; vname = snarf_name; } } } box = sstorage->module_ctx.super. mailbox_alloc(storage, list, vname, flags); if (sstorage->snarfing_disabled) { box->inbox_user = TRUE; box->inbox_any = TRUE; } return box; }