index-status.c revision 97f6b32429970e5befdd777b4104598623a8c806
45312f52ff3a3d4c137447be4c7556500c2f8bf2Timo Sirainen/* Copyright (c) 2002-2011 Dovecot authors, see the included COPYING file */
137c1851d63c6575ebab35d261380423c4cf2b47Timo Sirainenindex_storage_get_status_cache_fields(struct mailbox *box,
41e09cca158ab614961e03deac60f12a58235cd3Timo Sirainen unsigned int i, count;
137c1851d63c6575ebab35d261380423c4cf2b47Timo Sirainen fields = mail_cache_register_get_list(box->cache,
137c1851d63c6575ebab35d261380423c4cf2b47Timo Sirainen cache_fields = t_new(ARRAY_TYPE(const_string), 1);
137c1851d63c6575ebab35d261380423c4cf2b47Timo Sirainen for (i = 0; i < count; i++) {
0d0451206a91e9f96e522075dce28a89adc2325dTimo Sirainen dec = fields[i].decision & ~MAIL_CACHE_DECISION_FORCED;
0d0451206a91e9f96e522075dce28a89adc2325dTimo Sirainen array_append(cache_fields, &fields[i].name, 1);
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainenindex_storage_virtual_size_add_new(struct mailbox *box,
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box);
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen else if (!mail_index_lookup_seq_range(box->view, 1,
137c1851d63c6575ebab35d261380423c4cf2b47Timo Sirainen "vsize-hdr has invalid message-count (%u < %u)",
137c1851d63c6575ebab35d261380423c4cf2b47Timo Sirainen /* some messages have been expunged, rescan */
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen mail_search_build_add_seqset(search_args, seq2 + 1,
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen search_ctx = mailbox_search_init(trans, search_args, NULL);
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen mail = mail_alloc(trans, MAIL_FETCH_VIRTUAL_SIZE, NULL);
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen while (mailbox_search_next(search_ctx, mail)) {
137c1851d63c6575ebab35d261380423c4cf2b47Timo Sirainen if (mail_get_virtual_size(mail, &vsize) < 0) {
9b5a8e766112d24c12499aca85da5ddf24baad25Timo Sirainen /* success, cache all */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen /* search failed, cache only up to highest seen uid */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen mail_index_update_header_ext(trans->itrans, ibox->vsize_hdr_ext_id,
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenindex_storage_get_status_virtual_size(struct mailbox *box,
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen mail_index_get_header_ext(box->view, ibox->vsize_hdr_ext_id,
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen if (vsize_hdr.highest_uid + 1 == status_r->uidnext &&
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen vsize_hdr.message_count == status_r->messages) {
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen /* up to date */
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen if (vsize_hdr.highest_uid >= status_r->uidnext) {
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen "vsize-hdr has invalid highest-uid (%u >= %u)",
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen index_storage_virtual_size_add_new(box, &vsize_hdr);
137c1851d63c6575ebab35d261380423c4cf2b47Timo Sirainenvoid index_storage_get_status(struct mailbox *box,
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen memset(status_r, 0, sizeof(struct mailbox_status));
4d5d16ff85dacf56ddd70f76e0ccdb12b9d314d0Timo Sirainen /* we can get most of the status items without any trouble */
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen status_r->recent = index_mailbox_get_recent_count(box);
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen i_assert(status_r->recent <= status_r->messages);
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen status_r->unseen = hdr->messages_count - hdr->seen_messages_count;
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen status_r->first_recent_uid = hdr->first_recent_uid;
d48a2f3288eba53dd10d9d8029ec583d78a977e0Timo Sirainen status_r->nonpermanent_modseqs = mail_index_is_in_memory(box->index);
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen /* modseqs not enabled yet, but we can't return 0 */
b529a94ab17fe69cdcfab08d7030266cb2a564e4Timo Sirainen mail_index_lookup_first(box->view, 0, MAIL_SEEN,
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen status_r->keywords = mail_index_get_keywords(box->index);
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen index_storage_get_status_cache_fields(box, status_r);