Skip to content

Commit

Permalink
imap: Fix recent flags importing when un-hibernating
Browse files Browse the repository at this point in the history
The initial RECENT counter that was sent didn't include pre-hibernation
\Recent flags.

\Recent flags were also added for mails that were already expunged, which
could have caused recent counter to be wrong later on, and possibly
assert-crash with:

Panic: file index-status.c: line 130 (index_storage_get_open_status): assertion failed: (status_r->recent <= status_r->messages)
  • Loading branch information
sirainen authored and GitLab committed Nov 18, 2016
1 parent 591f83c commit 551fef6
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/imap/imap-state.c
Expand Up @@ -9,7 +9,7 @@
#include "str-sanitize.h"
#include "imap-util.h"
#include "mail-search-build.h"
#include "mail-storage.h"
#include "mail-storage-private.h"
#include "mailbox-recent-flags.h"
#include "imap-client.h"
#include "imap-fetch.h"
Expand Down Expand Up @@ -627,7 +627,6 @@ import_state_mailbox_open(struct client *client,
client->mailbox = box;
client->mailbox_examined = state->examined;
client->messages_count = status.messages;
client->recent_count = status.recent;
client->uidvalidity = status.uidvalidity;
client->notify_uidnext = status.uidnext;

Expand All @@ -640,6 +639,18 @@ import_state_mailbox_open(struct client *client,
state->messages - expunge_count);
return -1;
}

client_update_mailbox_flags(client, status.keywords);
array_foreach(&state->recent_uids, range) {
for (uid = range->seq1; uid <= range->seq2; uid++) {
uint32_t seq;

if (mail_index_lookup_seq(box->view, uid, &seq))
mailbox_recent_flags_set_uid_forced(box, uid);
}
}
client->recent_count = mailbox_recent_flags_count(box);

if (state->messages - expunge_count < client->messages_count) {
/* new messages arrived */
client_send_line(client,
Expand All @@ -648,11 +659,6 @@ import_state_mailbox_open(struct client *client,
t_strdup_printf("* %u RECENT", client->recent_count));
}

client_update_mailbox_flags(client, status.keywords);
array_foreach(&state->recent_uids, range) {
for (uid = range->seq1; uid <= range->seq2; uid++)
mailbox_recent_flags_set_uid_forced(box, uid);
}
if (array_count(status.keywords) == state->keywords_count &&
mailbox_status_keywords_crc32(&status) == state->keywords_crc32) {
/* no changes to keywords */
Expand Down

0 comments on commit 551fef6

Please sign in to comment.