index-status.c revision 54f9cedf212e30f690e8c7487374f2ea890494c6
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (C) 2002 Timo Sirainen */
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen#include "lib.h"
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen#include "index-storage.h"
70ead6466f9baa8294e71fc2fba0a4f54f488b5eTimo Sirainen
a020eb653b2620a989e4795adceb6136037327b2Timo Sirainen#define STATUS_MESSAGE_COUNTS \
bdd36cfdba3ff66d25570a9ff568d69e1eb543cfTimo Sirainen (STATUS_MESSAGES | STATUS_RECENT | STATUS_UIDNEXT | \
dd7cbb32412c2f4d2d223af66672535bc1237246Timo Sirainen STATUS_UIDVALIDITY | STATUS_UNSEEN | STATUS_FIRST_UNSEEN_SEQ)
57f5683fd9dc9bc79816c418bb30fdbc33b68a8cTimo Sirainen
55cec51dba1352482e93db30d7ced6bc4fe15f3aTimo Sirainen/*static void
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainenget_keywords(struct mail_keywords *mcf, struct mailbox_status *status)
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen{
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen const char **flags;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen unsigned int i;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
1701b354e81ff1dfd0b6c7bb4412b8d9c2b9f986Timo Sirainen status->keywords_count = MAIL_KEYWORDS_COUNT;
1701b354e81ff1dfd0b6c7bb4412b8d9c2b9f986Timo Sirainen status->keywords = t_new(const char *, MAIL_KEYWORDS_COUNT);
67c47dbb3fde79218320fd38a45c33f61bbf3012Timo Sirainen
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen flags = mail_keywords_list_get(mcf);
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen for (i = 0; i < MAIL_KEYWORDS_COUNT; i++)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen status->keywords[i] = t_strdup(flags[i]);
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen}*/
87ca4b209c10954826b878da165d303d9b4dc5a2Timo Sirainen
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainenint index_storage_get_status(struct mailbox *box,
70ead6466f9baa8294e71fc2fba0a4f54f488b5eTimo Sirainen enum mailbox_status_items items,
fd8b93ca5cbeba64fe6fa5dc98a3e580fb046791Timo Sirainen struct mailbox_status *status)
1ae5d61ec366fdb2f3c5b150ca378d6141b0f4bdTimo Sirainen{
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen struct index_mailbox *ibox = (struct index_mailbox *) box;
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen const struct mail_index_header *hdr;
67c47dbb3fde79218320fd38a45c33f61bbf3012Timo Sirainen
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen memset(status, 0, sizeof(struct mailbox_status));
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainen
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen if ((items & STATUS_MESSAGE_COUNTS) != 0) {
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen /* sync mailbox to update message counts */
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen if (mailbox_sync(box, 0) < 0)
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen return -1;
c4478af52de63804efef2055580adf1dfc8679c6Timo Sirainen }
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen /* we can get most of the status items without any trouble */
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen if (mail_index_get_header(ibox->view, &hdr) < 0)
d1bf4ae66b8bf3b9e28df1823d6d4adda2b923b6Timo Sirainen return -1;
d1bf4ae66b8bf3b9e28df1823d6d4adda2b923b6Timo Sirainen if ((items & STATUS_MESSAGE_COUNTS) != 0) {
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen status->messages = hdr->messages_count;
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen status->unseen = hdr->messages_count - hdr->seen_messages_count;
5231ae561283595a73e9d838bdf4eb5d1b074679Josef 'Jeff' Sipek status->uidvalidity = hdr->uid_validity;
5231ae561283595a73e9d838bdf4eb5d1b074679Josef 'Jeff' Sipek status->uidnext = hdr->next_uid;
5231ae561283595a73e9d838bdf4eb5d1b074679Josef 'Jeff' Sipek }
5231ae561283595a73e9d838bdf4eb5d1b074679Josef 'Jeff' Sipek //FIXME:status->diskspace_full = ibox->nodiskspace;
379175cfba8150d481d9898b78330b719d128d84Timo Sirainen
379175cfba8150d481d9898b78330b719d128d84Timo Sirainen if (items & STATUS_FIRST_UNSEEN_SEQ) {
379175cfba8150d481d9898b78330b719d128d84Timo Sirainen if (mail_index_lookup_first(ibox->view, 0, MAIL_SEEN,
379175cfba8150d481d9898b78330b719d128d84Timo Sirainen &status->first_unseen_seq) < 0) {
379175cfba8150d481d9898b78330b719d128d84Timo Sirainen mail_storage_set_index_error(ibox);
34512eaad8b1b2f929e6d6e3a2f7252c29fba97bTimo Sirainen return -1;
677cc0d62b41c7506246bf1b992a400a11896474Timo Sirainen }
677cc0d62b41c7506246bf1b992a400a11896474Timo Sirainen }
34512eaad8b1b2f929e6d6e3a2f7252c29fba97bTimo Sirainen
34512eaad8b1b2f929e6d6e3a2f7252c29fba97bTimo Sirainen if ((items & STATUS_RECENT) != 0) {
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen i_assert(ibox->last_recent_count_initialized);
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen status->recent = ibox->last_recent_count;
a8d47e2427558d5011dfc75694b704760c1ef8baTimo Sirainen }
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen /*FIXME:if (items & STATUS_KEYWORDS)
4c892b0d94c5b1d6853dbe8e0b38059ea5b08ecaTimo Sirainen get_keywords(ibox, status);*/
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen mail_index_view_unlock(ibox->view);
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen return 0;
67c47dbb3fde79218320fd38a45c33f61bbf3012Timo Sirainen}
4c892b0d94c5b1d6853dbe8e0b38059ea5b08ecaTimo Sirainen