dovecot-1.2: Added mail_index_map_lookup_keywords().

dovecot at dovecot.org dovecot at dovecot.org
Tue Jun 17 15:31:11 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/cca4ef877d43
changeset: 7880:cca4ef877d43
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Jun 17 13:57:48 2008 +0300
description:
Added mail_index_map_lookup_keywords().

diffstat:

2 files changed, 41 insertions(+), 15 deletions(-)
src/lib-index/mail-index-view.c |   53 +++++++++++++++++++++++++++------------
src/lib-index/mail-index.h      |    3 ++

diffs (105 lines):

diff -r bc05d48eac44 -r cca4ef877d43 src/lib-index/mail-index-view.c
--- a/src/lib-index/mail-index-view.c	Tue Jun 17 13:56:50 2008 +0300
+++ b/src/lib-index/mail-index-view.c	Tue Jun 17 13:57:48 2008 +0300
@@ -442,30 +442,23 @@ bool mail_index_is_expunged(struct mail_
 	return expunged;
 }
 
-void mail_index_lookup_keywords(struct mail_index_view *view, uint32_t seq,
+static void
+mail_index_data_lookup_keywords(struct mail_index_map *map,
+				const unsigned char *data,
 				ARRAY_TYPE(keyword_indexes) *keyword_idx)
 {
-	struct mail_index_map *map;
-	const void *data;
-	const unsigned char *keyword_data;
 	const unsigned int *keyword_idx_map;
 	unsigned int i, j, keyword_count, index_idx;
-	uint32_t ext_id, idx;
+	uint32_t idx;
 	uint16_t record_size;
 
 	array_clear(keyword_idx);
-
-	/* get the keywords data. */
-	ext_id = view->index->keywords_ext_id;
-	mail_index_lookup_ext_full(view, seq, ext_id, &map, &data, NULL);
 	if (data == NULL) {
 		/* no keywords at all in index */
 		return;
 	}
-        keyword_data = data;
-
-	(void)mail_index_ext_get_size(view, ext_id, map, NULL,
-				      &record_size, NULL);
+	(void)mail_index_ext_get_size(NULL, map->index->keywords_ext_id,
+				      map, NULL, &record_size, NULL);
 
 	/* keyword_idx_map[] contains file => index keyword mapping */
 	if (!array_is_created(&map->keyword_idx_map))
@@ -474,12 +467,12 @@ void mail_index_lookup_keywords(struct m
 	keyword_idx_map = array_get(&map->keyword_idx_map, &keyword_count);
 	for (i = 0, idx = 0; i < record_size; i++) {
 		/* first do the quick check to see if there's keywords at all */
-		if (keyword_data[i] == 0)
+		if (data[i] == 0)
 			continue;
 
 		idx = i * CHAR_BIT;
 		for (j = 0; j < CHAR_BIT; j++, idx++) {
-			if ((keyword_data[i] & (1 << j)) == 0)
+			if ((data[i] & (1 << j)) == 0)
 				continue;
 
 			if (idx >= keyword_count) {
@@ -492,6 +485,36 @@ void mail_index_lookup_keywords(struct m
 			array_append(keyword_idx, &index_idx, 1);
 		}
 	}
+}
+
+void mail_index_map_lookup_keywords(struct mail_index_map *map, uint32_t seq,
+				    ARRAY_TYPE(keyword_indexes) *keyword_idx)
+{
+	const struct mail_index_ext *ext;
+	const struct mail_index_record *rec;
+	const void *data;
+	uint32_t idx;
+
+	if (!mail_index_map_get_ext_idx(map, map->index->keywords_ext_id, &idx))
+		data = NULL;
+	else {
+		rec = MAIL_INDEX_MAP_IDX(map, seq-1);
+		ext = array_idx(&map->extensions, idx);
+		data = ext->record_offset == 0 ? NULL :
+			CONST_PTR_OFFSET(rec, ext->record_offset);
+	}
+	mail_index_data_lookup_keywords(map, data, keyword_idx);
+}
+
+void mail_index_lookup_keywords(struct mail_index_view *view, uint32_t seq,
+				ARRAY_TYPE(keyword_indexes) *keyword_idx)
+{
+	struct mail_index_map *map;
+	const void *data;
+
+	mail_index_lookup_ext_full(view, seq, view->index->keywords_ext_id,
+				   &map, &data, NULL);
+	mail_index_data_lookup_keywords(map, data, keyword_idx);
 }
 
 void mail_index_lookup_uid(struct mail_index_view *view, uint32_t seq,
diff -r bc05d48eac44 -r cca4ef877d43 src/lib-index/mail-index.h
--- a/src/lib-index/mail-index.h	Tue Jun 17 13:56:50 2008 +0300
+++ b/src/lib-index/mail-index.h	Tue Jun 17 13:57:48 2008 +0300
@@ -334,6 +334,9 @@ bool mail_index_is_expunged(struct mail_
 /* Note that returned keyword indexes aren't sorted. */
 void mail_index_lookup_keywords(struct mail_index_view *view, uint32_t seq,
 				ARRAY_TYPE(keyword_indexes) *keyword_idx);
+/* Return keywords from given map. */
+void mail_index_map_lookup_keywords(struct mail_index_map *map, uint32_t seq,
+				    ARRAY_TYPE(keyword_indexes) *keyword_idx);
 /* Returns the UID for given message. May be slightly faster than
    mail_index_lookup()->uid. */
 void mail_index_lookup_uid(struct mail_index_view *view, uint32_t seq,


More information about the dovecot-cvs mailing list