mailbox_internal_attribute_get(enum mail_attribute_type type,
const char *key)
{
+ const struct mailbox_attribute_internal *iattr;
struct mailbox_attribute_internal dreg;
unsigned int insert_idx;
dreg.type = type;
dreg.key = key;
- if (!array_bsearch_insert_pos(&mailbox_internal_attributes,
- &dreg, mailbox_attribute_internal_cmp,
- &insert_idx))
+ if (array_bsearch_insert_pos(&mailbox_internal_attributes,
+ &dreg, mailbox_attribute_internal_cmp,
+ &insert_idx)) {
+ /* exact match */
+ return array_idx(&mailbox_internal_attributes, insert_idx);
+ }
+ if (insert_idx == 0) {
+ /* not found at all */
return NULL;
-
- return array_idx(&mailbox_internal_attributes, insert_idx);
+ }
+ iattr = array_idx(&mailbox_internal_attributes, insert_idx-1);
+ if (strncmp(iattr->key, key, strlen(iattr->key)) != 0) {
+ /* iattr isn't a prefix of key */
+ return NULL;
+ } else if ((iattr->flags & MAIL_ATTRIBUTE_INTERNAL_FLAG_CHILDREN) != 0) {
+ /* iattr is a prefix of key and it wants to handle the key */
+ return iattr;
+ } else {
+ return NULL;
+ }
}
static void
case MAIL_ATTRIBUTE_INTERNAL_RANK_DEFAULT:
case MAIL_ATTRIBUTE_INTERNAL_RANK_OVERRIDE:
/* notify about assignment */
- if (iattr->set != NULL && iattr->set(t, value) < 0)
+ if (iattr->set != NULL && iattr->set(t, key, value) < 0)
return -1;
break;
case MAIL_ATTRIBUTE_INTERNAL_RANK_AUTHORITY:
return -1;
}
/* assign internal attribute */
- return iattr->set(t, value);
+ return iattr->set(t, key, value);
default:
i_unreached();
}
if (iattr != NULL) {
switch (iattr->rank) {
case MAIL_ATTRIBUTE_INTERNAL_RANK_OVERRIDE:
- if ((ret = iattr->get(t, value_r)) != 0) {
+ if ((ret = iattr->get(t, key, value_r)) != 0) {
if (ret < 0)
return -1;
value_r->flags |= MAIL_ATTRIBUTE_VALUE_FLAG_READONLY;
case MAIL_ATTRIBUTE_INTERNAL_RANK_DEFAULT:
break;
case MAIL_ATTRIBUTE_INTERNAL_RANK_AUTHORITY:
- if ((ret = iattr->get(t, value_r)) <= 0)
+ if ((ret = iattr->get(t, key, value_r)) <= 0)
return ret;
value_r->flags |= MAIL_ATTRIBUTE_VALUE_FLAG_READONLY;
return 1;
if (iattr != NULL) {
switch (iattr->rank) {
case MAIL_ATTRIBUTE_INTERNAL_RANK_DEFAULT:
- if ((ret = iattr->get(t, value_r)) < 0)
+ if ((ret = iattr->get(t, key, value_r)) < 0)
return ret;
if (ret > 0) {
value_r->flags |= MAIL_ATTRIBUTE_VALUE_FLAG_READONLY;
MAIL_ATTRIBUTE_INTERNAL_RANK_AUTHORITY
};
+enum mail_attribute_internal_flags {
+ /* Apply this attribute to the given key and its children. */
+ MAIL_ATTRIBUTE_INTERNAL_FLAG_CHILDREN = 0x01
+};
+
struct mailbox_attribute_internal {
enum mail_attribute_type type;
const char *key;
enum mail_attribute_internal_rank rank;
+ enum mail_attribute_internal_flags flags;
/* Get the value of this internal attribute */
- int (*get)(struct mailbox_transaction_context *t,
+ int (*get)(struct mailbox_transaction_context *t, const char *key,
struct mail_attribute_value *value_r);
/* Set the value of this internal attribute */
- int (*set)(struct mailbox_transaction_context *t,
+ int (*set)(struct mailbox_transaction_context *t, const char *key,
const struct mail_attribute_value *value);
};