From: Timo Sirainen Date: Mon, 7 Sep 2015 13:22:11 +0000 (+0300) Subject: lib-storage: Allow set/get for Dovecot-private attributes via internal attributes. X-Git-Tag: 2.2.19.rc1~91 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ab5269901fa285cf66bc55dd068979d4fdbb4c23;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Allow set/get for Dovecot-private attributes via internal attributes. This allows registering attributes with MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT prefix and having them be get/set via dict, instead of failing them. --- diff --git a/src/lib-storage/index/index-attribute.c b/src/lib-storage/index/index-attribute.c index 645bc38aab..6fa6a5798b 100644 --- a/src/lib-storage/index/index-attribute.c +++ b/src/lib-storage/index/index-attribute.c @@ -197,7 +197,8 @@ int index_storage_attribute_set(struct mailbox_transaction_context *t, time_t ts = value->last_change != 0 ? value->last_change : ioloop_time; int ret = 0; - if (!MAILBOX_ATTRIBUTE_KEY_IS_USER_ACCESSIBLE(key)) { + if (!t->internal_attribute && + !MAILBOX_ATTRIBUTE_KEY_IS_USER_ACCESSIBLE(key)) { mail_storage_set_error(t->box->storage, MAIL_ERROR_PARAMS, "Internal attributes cannot be changed directly"); return -1; @@ -237,7 +238,8 @@ int index_storage_attribute_get(struct mailbox_transaction_context *t, memset(value_r, 0, sizeof(*value_r)); - if (!MAILBOX_ATTRIBUTE_KEY_IS_USER_ACCESSIBLE(key)) + if (!t->internal_attribute && + !MAILBOX_ATTRIBUTE_KEY_IS_USER_ACCESSIBLE(key)) return 0; if (index_storage_get_dict(t->box, type, &dict, &mailbox_prefix) < 0) diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index 03d7f27af5..acce8216dc 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -529,6 +529,8 @@ struct mailbox_transaction_context { unsigned int stats_track:1; /* We've done some non-transactional (e.g. dovecot-uidlist updates) */ unsigned int nontransactional_changes:1; + /* FIXME: v2.3: this should be in attribute_get/set() parameters */ + unsigned int internal_attribute:1; }; union mail_search_module_context { diff --git a/src/lib-storage/mailbox-attribute.c b/src/lib-storage/mailbox-attribute.c index 2d7bd415c6..c5252ada87 100644 --- a/src/lib-storage/mailbox-attribute.c +++ b/src/lib-storage/mailbox-attribute.c @@ -138,7 +138,8 @@ mailbox_attribute_set_common(struct mailbox_transaction_context *t, const struct mail_attribute_value *value) { const struct mailbox_attribute_internal *iattr; - + int ret; + iattr = mailbox_internal_attribute_get(type, key); /* allow internal server attribute only for inbox */ @@ -170,7 +171,13 @@ mailbox_attribute_set_common(struct mailbox_transaction_context *t, } } - return t->box->v.attribute_set(t, type, key, value); + /* FIXME: v2.3 should move the internal_attribute to attribute_set() + parameter (as flag). not done yet for API backwards compatibility */ + t->internal_attribute = iattr != NULL && + iattr->rank != MAIL_ATTRIBUTE_INTERNAL_RANK_AUTHORITY; + ret = t->box->v.attribute_set(t, type, key, value); + t->internal_attribute = FALSE; + return ret; } int mailbox_attribute_set(struct mailbox_transaction_context *t, @@ -261,8 +268,14 @@ mailbox_attribute_get_common(struct mailbox_transaction_context *t, } } - /* user entries */ - if ((ret = t->box->v.attribute_get(t, type, key, value_r)) != 0) + /* user entries - FIXME: v2.3 should move the internal_attribute to + attribute_get() parameter (as flag). not done yet for API backwards + compatibility */ + t->internal_attribute = iattr != NULL && + iattr->rank != MAIL_ATTRIBUTE_INTERNAL_RANK_AUTHORITY; + ret = t->box->v.attribute_get(t, type, key, value_r); + t->internal_attribute = FALSE; + if (ret != 0) return ret; /* default entries */