index-status.c revision a5cc9935581d9503b5f77097390d903b8add6c44
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Copyright (C) 2002 Timo Sirainen */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include "lib.h"
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainen#include "index-storage.h"
16f816d3f3c32ae3351834253f52ddd0212bcbf3Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint index_storage_get_status_locked(struct index_mailbox *ibox,
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen enum mailbox_status_items items,
ffd9a1898a18fadfc5dce399162c25d50548f905Timo Sirainen struct mailbox_status *status_r)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen{
89b548af722113acb5d63dfffb44423cb60f91e4Timo Sirainen const struct mail_index_header *hdr;
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen memset(status_r, 0, sizeof(struct mailbox_status));
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
66ae183b6e895216037bd921367670f4b0665911Timo Sirainen /* we can get most of the status items without any trouble */
e86d0d34fe365da4c7ca4312d575bfcbf3a01c0eTimo Sirainen hdr = mail_index_get_header(ibox->view);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen status_r->messages = hdr->messages_count;
da5d50534cfca45d0aaaf0bdac17b287b4588809Timo Sirainen status_r->recent = ibox->synced_recent_count;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen status_r->unseen =
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen hdr->messages_count - hdr->seen_messages_count;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen status_r->uidvalidity = hdr->uid_validity;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen status_r->uidnext = hdr->next_uid;
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen if (items & STATUS_FIRST_UNSEEN_SEQ) {
46c31f64b9f0949f00b7819f45b22f2d64b2ea27Timo Sirainen if (mail_index_lookup_first(ibox->view, 0, MAIL_SEEN,
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen &status_r->first_unseen_seq) < 0) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen mail_storage_set_index_error(ibox);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen return -1;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen }
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen }
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (items & STATUS_KEYWORDS)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen status_r->keywords = mail_index_get_keywords(ibox->index);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen return 0;
024815ea2ffdda9ea79919f18e865663977f73eaTimo Sirainen}
8fa41238067c854435884c459963fde6f8c6436bTimo Sirainen
8fa41238067c854435884c459963fde6f8c6436bTimo Sirainenint index_storage_get_status(struct mailbox *box,
91dca97b367c54a139c268b56a0c67f564bd9197Timo Sirainen enum mailbox_status_items items,
91dca97b367c54a139c268b56a0c67f564bd9197Timo Sirainen struct mailbox_status *status)
46c31f64b9f0949f00b7819f45b22f2d64b2ea27Timo Sirainen{
46c31f64b9f0949f00b7819f45b22f2d64b2ea27Timo Sirainen struct index_mailbox *ibox = (struct index_mailbox *)box;
d6badc27cd6e8d3398877b6766cb0aaeef3a7800Timo Sirainen int ret;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (!box->opened)
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen index_storage_mailbox_open(ibox);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen ret = index_storage_get_status_locked(ibox, items, status);
41e1c7380edda701719d8ce1fb4d465d2ec4c84dTimo Sirainen if (box->transaction_count == 0)
91dca97b367c54a139c268b56a0c67f564bd9197Timo Sirainen mail_index_view_unlock(ibox->view);
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen return ret;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen}
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen