dovecot-2.2: lib-storage: Allow mail_*cache_fields settings to s...

dovecot at dovecot.org dovecot at dovecot.org
Wed May 15 13:44:11 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/07bc030f18d3
changeset: 16359:07bc030f18d3
user:      Timo Sirainen <tss at iki.fi>
date:      Wed May 15 13:44:01 2013 +0300
description:
lib-storage: Allow mail_*cache_fields settings to specify any hdr.* fields.
Also the fields were previously set only once globally, so if the process
served multiple users, it wouldn't have been possible to use per-user values
for these fields.

diffstat:

 src/lib-storage/index/index-storage.c |  60 ++++++++++++++++++----------------
 1 files changed, 31 insertions(+), 29 deletions(-)

diffs (93 lines):

diff -r ac0170b8db14 -r 07bc030f18d3 src/lib-storage/index/index-storage.c
--- a/src/lib-storage/index/index-storage.c	Wed May 15 13:36:43 2013 +0300
+++ b/src/lib-storage/index/index-storage.c	Wed May 15 13:44:01 2013 +0300
@@ -28,27 +28,35 @@
 struct index_storage_module index_storage_module =
 	MODULE_CONTEXT_INIT(&mail_storage_module_register);
 
-static void set_cache_decisions(const char *set, const char *fields,
+static void set_cache_decisions(struct mail_cache *cache,
+				const char *set, const char *fields,
 				enum mail_cache_decision_type dec)
 {
+	struct mail_cache_field field;
 	const char *const *arr;
-	int i;
+	unsigned int idx;
 
 	if (fields == NULL || *fields == '\0')
 		return;
 
 	for (arr = t_strsplit_spaces(fields, " ,"); *arr != NULL; arr++) {
-		for (i = 0; i < MAIL_INDEX_CACHE_FIELD_COUNT; i++) {
-			if (strcasecmp(global_cache_fields[i].name,
-				       *arr) == 0) {
-				global_cache_fields[i].decision = dec;
-				break;
-			}
+		const char *name = *arr;
+
+		idx = mail_cache_register_lookup(cache, name);
+		if (idx != UINT_MAX) {
+			field = *mail_cache_register_get_field(cache, idx);
+		} else if (strncasecmp(name, "hdr.", 4) == 0) {
+			memset(&field, 0, sizeof(field));
+			field.name = name;
+			field.type = MAIL_CACHE_FIELD_HEADER;
+		} else {
+			i_error("%s: Unknown cache field name '%s', ignoring",
+				set, *arr);
+			continue;
 		}
-		if (i == MAIL_INDEX_CACHE_FIELD_COUNT) {
-			i_error("%s: Invalid cache field name '%s', ignoring ",
-				set, *arr);
-		}
+
+		field.decision = dec;
+		mail_cache_register_fields(cache, &field, 1);
 	}
 }
 
@@ -56,30 +64,24 @@
 {
 	struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box);
 	const struct mail_storage_settings *set = box->storage->set;
-	static bool initialized = FALSE;
 	struct mail_cache *cache = box->cache;
 
-	if (!initialized) {
-		initialized = TRUE;
-
-		set_cache_decisions("mail_cache_fields",
-				    set->mail_cache_fields,
-				    MAIL_CACHE_DECISION_TEMP);
-		set_cache_decisions("mail_always_cache_fields",
-				    set->mail_always_cache_fields,
-				    MAIL_CACHE_DECISION_YES |
-				    MAIL_CACHE_DECISION_FORCED);
-		set_cache_decisions("mail_never_cache_fields",
-				    set->mail_never_cache_fields,
-				    MAIL_CACHE_DECISION_NO |
-				    MAIL_CACHE_DECISION_FORCED);
-	}
-
 	ibox->cache_fields = i_malloc(sizeof(global_cache_fields));
 	memcpy(ibox->cache_fields, global_cache_fields,
 	       sizeof(global_cache_fields));
 	mail_cache_register_fields(cache, ibox->cache_fields,
 				   MAIL_INDEX_CACHE_FIELD_COUNT);
+	set_cache_decisions(cache, "mail_cache_fields",
+			    set->mail_cache_fields,
+			    MAIL_CACHE_DECISION_TEMP);
+	set_cache_decisions(cache, "mail_always_cache_fields",
+			    set->mail_always_cache_fields,
+			    MAIL_CACHE_DECISION_YES |
+			    MAIL_CACHE_DECISION_FORCED);
+	set_cache_decisions(cache, "mail_never_cache_fields",
+			    set->mail_never_cache_fields,
+			    MAIL_CACHE_DECISION_NO |
+			    MAIL_CACHE_DECISION_FORCED);
 }
 
 void index_storage_lock_notify(struct mailbox *box,


More information about the dovecot-cvs mailing list