dovecot-2.2: lib-storage: Allow set/get for Dovecot-private attr...

dovecot at dovecot.org dovecot at dovecot.org
Mon Sep 7 13:40:56 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/5d3c7d882bfb
changeset: 19103:5d3c7d882bfb
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Sep 07 16:22:11 2015 +0300
description:
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.

diffstat:

 src/lib-storage/index/index-attribute.c |   6 ++++--
 src/lib-storage/mail-storage-private.h  |   2 ++
 src/lib-storage/mailbox-attribute.c     |  21 +++++++++++++++++----
 3 files changed, 23 insertions(+), 6 deletions(-)

diffs (80 lines):

diff -r 31f8e377b632 -r 5d3c7d882bfb src/lib-storage/index/index-attribute.c
--- a/src/lib-storage/index/index-attribute.c	Mon Sep 07 16:38:24 2015 +0300
+++ b/src/lib-storage/index/index-attribute.c	Mon Sep 07 16:22:11 2015 +0300
@@ -197,7 +197,8 @@
 	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 @@
 
 	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 -r 31f8e377b632 -r 5d3c7d882bfb src/lib-storage/mail-storage-private.h
--- a/src/lib-storage/mail-storage-private.h	Mon Sep 07 16:38:24 2015 +0300
+++ b/src/lib-storage/mail-storage-private.h	Mon Sep 07 16:22:11 2015 +0300
@@ -529,6 +529,8 @@
 	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 -r 31f8e377b632 -r 5d3c7d882bfb src/lib-storage/mailbox-attribute.c
--- a/src/lib-storage/mailbox-attribute.c	Mon Sep 07 16:38:24 2015 +0300
+++ b/src/lib-storage/mailbox-attribute.c	Mon Sep 07 16:22:11 2015 +0300
@@ -138,7 +138,8 @@
 			     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 @@
 		}
 	}
 	
-	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 @@
 		}
 	}
 
-	/* 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 */


More information about the dovecot-cvs mailing list