From 8868eddb51d450f46255fa938939347eb8a1299c Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 7 Sep 2015 23:08:44 +0300 Subject: [PATCH] imap: NOTIFY (SUBSCRIPTIONS) assert-crashed when subscriptions hadn't been refreshed. --- src/imap/cmd-notify.c | 27 +++++++++++++++++++++++++++ src/imap/imap-notify.h | 1 + 2 files changed, 28 insertions(+) diff --git a/src/imap/cmd-notify.c b/src/imap/cmd-notify.c index d093573c84..217da68716 100644 --- a/src/imap/cmd-notify.c +++ b/src/imap/cmd-notify.c @@ -206,11 +206,34 @@ static void cmd_notify_add_personal(struct imap_notify_context *ctx, } } +static int +imap_notify_refresh_subscriptions(struct client_command_context *cmd, + struct imap_notify_context *ctx) +{ + struct mailbox_list_iterate_context *iter; + struct mail_namespace *ns; + + if (!ctx->have_subscriptions) + return 0; + + /* make sure subscriptions are refreshed at least once */ + for (ns = ctx->client->user->namespaces; ns != NULL; ns = ns->next) { + iter = mailbox_list_iter_init(ns->list, "*", MAILBOX_LIST_ITER_SELECT_SUBSCRIBED); + (void)mailbox_list_iter_next(iter); + if (mailbox_list_iter_deinit(&iter) < 0) { + client_send_list_error(cmd, ns->list); + return -1; + } + } + return 0; +} + static void cmd_notify_add_subscribed(struct imap_notify_context *ctx, enum imap_notify_event events) { struct mail_namespace *ns; + ctx->have_subscriptions = TRUE; for (ns = ctx->client->user->namespaces; ns != NULL; ns = ns->next) { cmd_notify_add_mailbox(ctx, ns, "", IMAP_NOTIFY_TYPE_SUBSCRIBED, events); @@ -523,6 +546,10 @@ bool cmd_notify(struct client_command_context *cmd) "NO [NOTIFICATIONOVERFLOW] Too many mailbox names"); pool_unref(&pool); return TRUE; + } else if (imap_notify_refresh_subscriptions(cmd, ctx) < 0) { + /* tagline already sent */ + pool_unref(&pool); + return TRUE; } else if (imap_notify_begin(ctx) < 0) { client_send_tagline(cmd, "NO [NOTIFICATIONOVERFLOW] NOTIFY not supported for these mailboxes."); diff --git a/src/imap/imap-notify.h b/src/imap/imap-notify.h index eef8998217..43f0dbbbf1 100644 --- a/src/imap/imap-notify.h +++ b/src/imap/imap-notify.h @@ -49,6 +49,7 @@ struct imap_notify_context { struct imap_fetch_context *fetch_ctx; struct timeout *to_watch; + unsigned int have_subscriptions:1; unsigned int selected_set:1; unsigned int selected_immediate_expunges:1; unsigned int send_immediate_status:1; -- 2.47.3