From: Timo Sirainen Date: Tue, 31 Mar 2009 00:27:02 +0000 (-0400) Subject: Added mail_index_lookup_view_flags() X-Git-Tag: 1.2.rc1~33 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dd9712b013e5a14939deed84b2e391d89897d2cf;p=thirdparty%2Fdovecot%2Fcore.git Added mail_index_lookup_view_flags() --HG-- branch : HEAD --- diff --git a/src/lib-index/mail-index-view.c b/src/lib-index/mail-index-view.c index a30b9b904f..15059e61b7 100644 --- a/src/lib-index/mail-index-view.c +++ b/src/lib-index/mail-index-view.c @@ -389,25 +389,30 @@ static void view_lookup_keywords(struct mail_index_view *view, uint32_t seq, mail_index_data_lookup_keywords(map, data, keyword_idx); } +static const void * +view_map_lookup_ext_full(struct mail_index_map *map, + const struct mail_index_record *rec, uint32_t ext_id) +{ + const struct mail_index_ext *ext; + uint32_t idx; + + if (!mail_index_map_get_ext_idx(map, ext_id, &idx)) + return NULL; + + ext = array_idx(&map->extensions, idx); + return ext->record_offset == 0 ? NULL : + CONST_PTR_OFFSET(rec, ext->record_offset); +} + static void view_lookup_ext_full(struct mail_index_view *view, uint32_t seq, uint32_t ext_id, struct mail_index_map **map_r, const void **data_r, bool *expunged_r) { - const struct mail_index_ext *ext; const struct mail_index_record *rec; - uint32_t idx, offset; rec = view->v.lookup_full(view, seq, map_r, expunged_r); - if (!mail_index_map_get_ext_idx(*map_r, ext_id, &idx)) { - *data_r = NULL; - return; - } - - ext = array_idx(&(*map_r)->extensions, idx); - offset = ext->record_offset; - - *data_r = offset == 0 ? NULL : CONST_PTR_OFFSET(rec, offset); + *data_r = view_map_lookup_ext_full(*map_r, rec, ext_id); } static void view_get_header_ext(struct mail_index_view *view, @@ -524,6 +529,23 @@ void mail_index_lookup_keywords(struct mail_index_view *view, uint32_t seq, view->v.lookup_keywords(view, seq, keyword_idx); } +void mail_index_lookup_view_flags(struct mail_index_view *view, uint32_t seq, + enum mail_flags *flags_r, + ARRAY_TYPE(keyword_indexes) *keyword_idx) +{ + const struct mail_index_record *rec; + const unsigned char *keyword_data; + + i_assert(seq > 0 && seq <= mail_index_view_get_messages_count(view)); + + rec = MAIL_INDEX_MAP_IDX(view->map, seq-1); + *flags_r = rec->flags; + + keyword_data = view_map_lookup_ext_full(view->map, rec, + view->index->keywords_ext_id); + mail_index_data_lookup_keywords(view->map, keyword_data, keyword_idx); +} + void mail_index_lookup_uid(struct mail_index_view *view, uint32_t seq, uint32_t *uid_r) { diff --git a/src/lib-index/mail-index.h b/src/lib-index/mail-index.h index 75aa5961bc..d9c6381317 100644 --- a/src/lib-index/mail-index.h +++ b/src/lib-index/mail-index.h @@ -343,6 +343,12 @@ void mail_index_lookup_keywords(struct mail_index_view *view, uint32_t seq, /* 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); +/* mail_index_lookup[_keywords]() returns the latest flag changes. + This function instead attempts to return the flags and keywords done by the + last view sync. */ +void mail_index_lookup_view_flags(struct mail_index_view *view, uint32_t seq, + enum mail_flags *flags_r, + 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,