]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Allow set/get for Dovecot-private attributes via internal attributes.
authorTimo Sirainen <tss@iki.fi>
Mon, 7 Sep 2015 13:22:11 +0000 (16:22 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 7 Sep 2015 13:22:11 +0000 (16:22 +0300)
This allows registering attributes with MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT
prefix and having them be get/set via dict, instead of failing them.

src/lib-storage/index/index-attribute.c
src/lib-storage/mail-storage-private.h
src/lib-storage/mailbox-attribute.c

index 645bc38aab753bb197463421e12a0e9c53f30b76..6fa6a5798be616a4a0b8ab06470931ce3497406a 100644 (file)
@@ -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)
index 03d7f27af5a69dc15a45314615c7d6eb53b8b8a3..acce8216dce349ca978a4600d145931c1132c765 100644 (file)
@@ -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 {
index 2d7bd415c65851480dc52074ccfc774655d0adcb..c5252ada87d3f21c1b3e807f8b2b6b0d0818ce37 100644 (file)
@@ -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 */