t_pop();
}
-static void new_messages(struct mailbox *mailbox, unsigned int messages_count,
- unsigned int recent_count, void *context)
+static void message_count_changed(struct mailbox *mailbox, unsigned int count,
+ void *context)
{
struct client *client = context;
char str[MAX_INT_STRLEN+20];
if (client->mailbox != mailbox)
return;
- i_snprintf(str, sizeof(str), "* %u EXISTS", messages_count);
+ i_snprintf(str, sizeof(str), "* %u EXISTS", count);
client_send_line(client, str);
+}
+
+static void recent_count_changed(struct mailbox *mailbox, unsigned int count,
+ void *context)
+{
+ struct client *client = context;
+ char str[MAX_INT_STRLEN+20];
+
+ if (client->mailbox != mailbox)
+ return;
- i_snprintf(str, sizeof(str), "* %u RECENT", recent_count);
+ i_snprintf(str, sizeof(str), "* %u RECENT", count);
client_send_line(client, str);
}
notify_no,
expunge,
update_flags,
- new_messages,
+ message_count_changed,
+ recent_count_changed,
new_keywords
};
}
}
- if ((items & STATUS_RECENT) != 0)
- status->recent = ibox->get_recent_count(ibox);
+ if ((items & STATUS_RECENT) != 0) {
+ i_assert(ibox->last_recent_count_initialized);
+ status->recent = ibox->last_recent_count;
+ }
/*FIXME:if (items & STATUS_KEYWORDS)
get_keywords(ibox, status);*/
struct mail *mail_interface;
uint32_t (*get_recent_count)(struct index_mailbox *ibox);
+ unsigned int last_recent_count;
struct timeout *autosync_to;
struct index_autosync_file *autosync_files;
unsigned int sent_readonly_flags_warning:1;
unsigned int autosync_pending:1;
unsigned int mail_read_mmaped:1;
+ unsigned int last_recent_count_initialized:1;
};
struct index_transaction_context {
void *sc_context;
enum mail_index_sync_type sync_mask;
uint32_t seq, seq1, seq2;
- uint32_t messages_count, new_messages_count, recent_count;
+ uint32_t messages_count, last_messages_count, recent_count;
int ret;
sync_mask = MAIL_INDEX_SYNC_MASK_ALL;
return -1;
}
+ if (!ibox->last_recent_count_initialized) {
+ ibox->last_recent_count_initialized = TRUE;
+ ibox->last_recent_count = ibox->get_recent_count(ibox);
+ }
+ last_messages_count = mail_index_view_get_message_count(ibox->view);
+
if ((flags & MAILBOX_SYNC_FLAG_NO_EXPUNGES) != 0) {
expunges_count = 0;
expunges = NULL;
if (ret < 0)
mail_storage_set_index_error(ibox);
- messages_count = new_messages_count =
- mail_index_view_get_message_count(ibox->view);
-
if (sc->expunge != NULL) {
+ /* expunges[] is a sorted array of sequences. it's easiest for
+ us to print them from end to beginning. */
+ messages_count = mail_index_view_get_message_count(ibox->view);
for (i = expunges_count*2; i > 0; i -= 2) {
seq = expunges[i-1];
if (seq > messages_count)
seq = messages_count;
for (; seq >= expunges[i-2]; seq--) {
sc->expunge(&ibox->box, seq, sc_context);
- new_messages_count--;
+ last_messages_count--;
}
}
}
mail_index_view_sync_end(ctx);
messages_count = mail_index_view_get_message_count(ibox->view);
- if (messages_count != new_messages_count) {
+ if (messages_count != last_messages_count) {
+ sc->message_count_changed(&ibox->box, messages_count,
+ sc_context);
recent_count = ibox->get_recent_count(ibox);
- sc->new_messages(&ibox->box, messages_count, recent_count,
- sc_context);
+ } else if (expunges_count != 0)
+ recent_count = ibox->get_recent_count(ibox);
+ else
+ recent_count = ibox->last_recent_count;
+
+ if (recent_count != ibox->last_recent_count) {
+ ibox->last_recent_count = recent_count;
+ sc->recent_count_changed(&ibox->box, recent_count, sc_context);
}
mail_index_view_unlock(ibox->view);
const struct mail_full_flags *flags,
void *context);
- /* EXISTS, RECENT */
- void (*new_messages)(struct mailbox *mailbox,
- unsigned int messages_count,
- unsigned int recent_count, void *context);
+ /* EXISTS */
+ void (*message_count_changed)(struct mailbox *mailbox,
+ unsigned int count, void *context);
+ /* RECENT */
+ void (*recent_count_changed)(struct mailbox *mailbox,
+ unsigned int count, void *context);
/* FLAGS, PERMANENTFLAGS */
void (*new_keywords)(struct mailbox *mailbox,
const char *keywords[],
- unsigned int keywords_count,
- void *context);
+ unsigned int keywords_count, void *context);
};
{
}
-static void new_messages(struct mailbox *mailbox __attr_unused__,
- unsigned int messages_count __attr_unused__,
- unsigned int recent_count __attr_unused__,
- void *context __attr_unused__)
+static void message_count_changed(struct mailbox *mailbox __attr_unused__,
+ unsigned int count __attr_unused__,
+ void *context __attr_unused__)
{
}
+static void recent_count_changed(struct mailbox *mailbox __attr_unused__,
+ unsigned int count __attr_unused__,
+ void *context __attr_unused__)
+{
+}
+
+
static void new_keywords(struct mailbox *mailbox __attr_unused__,
const char *keywords[] __attr_unused__,
unsigned int keywords_count __attr_unused__,
notify_no,
expunge,
update_flags,
- new_messages,
+ message_count_changed,
+ recent_count_changed,
new_keywords
};