]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added mail_index_map_lookup_keywords().
authorTimo Sirainen <tss@iki.fi>
Tue, 17 Jun 2008 10:57:48 +0000 (13:57 +0300)
committerTimo Sirainen <tss@iki.fi>
Tue, 17 Jun 2008 10:57:48 +0000 (13:57 +0300)
--HG--
branch : HEAD

src/lib-index/mail-index-view.c
src/lib-index/mail-index.h

index 290ea02119e1b0f67b1bfff192a3e9bdc0e87ea0..e54ad467b271df25fa45fd8c87b268072b86aa33 100644 (file)
@@ -442,30 +442,23 @@ bool mail_index_is_expunged(struct mail_index_view *view, uint32_t seq)
        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 mail_index_view *view, uint32_t seq,
        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) {
@@ -494,6 +487,36 @@ void mail_index_lookup_keywords(struct mail_index_view *view, uint32_t seq,
        }
 }
 
+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,
                           uint32_t *uid_r)
 {
index dd04aa1f20b360ecb83bea316a3b93155fde44c7..9c53fe46d4626759129b6d7299e7105abe20d280 100644 (file)
@@ -334,6 +334,9 @@ bool mail_index_is_expunged(struct mail_index_view *view, uint32_t seq);
 /* 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,