Skip to content

Commit

Permalink
imapc: Fixed assert-crash in mailbox syncing, if mailbox couldn't be …
Browse files Browse the repository at this point in the history
…opened.

Usually meaning that syncing was attempted when IMAP server couldn't be
connected to. Fixes the assert:

Panic: file imapc-client.c: line 439 (imapc_client_get_capabilities):
assertion failed: (conn != NULL)
  • Loading branch information
sirainen committed Jan 28, 2016
1 parent 6e9454f commit a221d0d
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/lib-storage/index/imapc/imapc-sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,12 +502,28 @@ static int imapc_sync(struct imapc_mailbox *mbox)
return 0;
}

static void
imapc_noop_if_needed(struct imapc_mailbox *mbox, enum mailbox_sync_flags flags)
{
enum imapc_capability capabilities;

capabilities = imapc_client_get_capabilities(mbox->storage->client->client);
if ((capabilities & IMAPC_CAPABILITY_IDLE) == 0 ||
(flags & MAILBOX_SYNC_FLAG_FULL_READ) != 0) {
/* do NOOP to make sure we have the latest changes before
starting sync. this is necessary either because se don't
support IDLE at all, or because we want to be sure that we
have the latest changes (IDLE is started with a small delay,
so we might not actually even be in IDLE right not) */
imapc_mailbox_noop(mbox);
}
}

struct mailbox_sync_context *
imapc_mailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
{
struct imapc_mailbox *mbox = (struct imapc_mailbox *)box;
struct imapc_mailbox_list *list = mbox->storage->client->_list;
enum imapc_capability capabilities;
bool changes;
int ret = 0;

Expand All @@ -522,16 +538,8 @@ imapc_mailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
ret = -1;
}

capabilities = imapc_client_get_capabilities(mbox->storage->client->client);
if ((capabilities & IMAPC_CAPABILITY_IDLE) == 0 ||
(flags & MAILBOX_SYNC_FLAG_FULL_READ) != 0) {
/* do NOOP to make sure we have the latest changes before
starting sync. this is necessary either because se don't
support IDLE at all, or because we want to be sure that we
have the latest changes (IDLE is started with a small delay,
so we might not actually even be in IDLE right not) */
imapc_mailbox_noop(mbox);
}
if (ret == 0)
imapc_noop_if_needed(mbox, flags);

if (imapc_mailbox_commit_delayed_trans(mbox, &changes) < 0)
ret = -1;
Expand Down

0 comments on commit a221d0d

Please sign in to comment.