int index_storage_attribute_get(struct mailbox_transaction_context *t, enum mail_attribute_type type, const char *key, struct mail_attribute_value *value_r) { struct dict *dict; const char *mailbox_prefix; int ret; memset(value_r, 0, sizeof(*value_r)); if (strncmp(key, MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT, strlen(MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT)) == 0) return 0; if (index_storage_get_dict(t->box, type, &dict, &mailbox_prefix) < 0) return -1; ret = dict_lookup(dict, pool_datastack_create(), key_get_prefixed(type, mailbox_prefix, key), &value_r->value); if (ret < 0) { mail_storage_set_internal_error(t->box->storage); return -1; } return ret; }
int index_storage_attribute_get(struct mailbox *box, enum mail_attribute_type type, const char *key, struct mail_attribute_value *value_r, bool internal_attribute) { struct dict *dict; const char *mailbox_prefix, *error; int ret; memset(value_r, 0, sizeof(*value_r)); if (!internal_attribute && !MAILBOX_ATTRIBUTE_KEY_IS_USER_ACCESSIBLE(key)) return 0; if (index_storage_get_dict(box, type, &dict, &mailbox_prefix) < 0) return -1; ret = dict_lookup(dict, pool_datastack_create(), key_get_prefixed(type, mailbox_prefix, key), &value_r->value, &error); if (ret < 0) { mail_storage_set_critical(box->storage, "Failed to set attribute %s: %s", key, error); return -1; } return ret; }
static int index_storage_attribute_get_dict_trans(struct mailbox_transaction_context *t, enum mail_attribute_type type, struct dict_transaction_context **dtrans_r, const char **mailbox_prefix_r) { struct dict_transaction_context **dtransp = NULL; struct dict *dict; struct mailbox_metadata metadata; switch (type) { case MAIL_ATTRIBUTE_TYPE_PRIVATE: dtransp = &t->attr_pvt_trans; break; case MAIL_ATTRIBUTE_TYPE_SHARED: dtransp = &t->attr_shared_trans; break; } i_assert(dtransp != NULL); if (*dtransp != NULL) { /* transaction already created */ if (mailbox_get_metadata(t->box, MAILBOX_METADATA_GUID, &metadata) < 0) return -1; *mailbox_prefix_r = guid_128_to_string(metadata.guid); *dtrans_r = *dtransp; return 0; } if (index_storage_get_dict(t->box, type, &dict, mailbox_prefix_r) < 0) return -1; *dtransp = *dtrans_r = dict_transaction_begin(dict); return 0; }
struct mailbox_attribute_iter * index_storage_attribute_iter_init(struct mailbox *box, enum mail_attribute_type type, const char *prefix) { struct index_storage_attribute_iter *iter; struct dict *dict; const char *mailbox_prefix; iter = i_new(struct index_storage_attribute_iter, 1); iter->iter.box = box; if (index_storage_get_dict(box, type, &dict, &mailbox_prefix) < 0) { if (mailbox_get_last_mail_error(box) == MAIL_ERROR_NOTPOSSIBLE) iter->dict_disabled = TRUE; } else { iter->prefix = i_strdup(key_get_prefixed(type, mailbox_prefix, prefix)); iter->prefix_len = strlen(iter->prefix); iter->diter = dict_iterate_init(dict, iter->prefix, DICT_ITERATE_FLAG_RECURSE | DICT_ITERATE_FLAG_NO_VALUE); } return &iter->iter; }
static int index_storage_attribute_get_dict_trans(struct mailbox_transaction_context *t, enum mail_attribute_type type, struct dict_transaction_context **dtrans_r, const char **mailbox_prefix_r) { struct dict_transaction_context **dtransp = NULL; struct dict *dict; switch (type) { case MAIL_ATTRIBUTE_TYPE_PRIVATE: dtransp = &t->attr_pvt_trans; break; case MAIL_ATTRIBUTE_TYPE_SHARED: dtransp = &t->attr_shared_trans; break; } i_assert(dtransp != NULL); if (index_storage_get_dict(t->box, type, &dict, mailbox_prefix_r) < 0) return -1; *dtransp = *dtrans_r = dict_transaction_begin(dict); return 0; }