From: Timo Sirainen Date: Wed, 28 Nov 2018 10:26:33 +0000 (+0200) Subject: imap: Access enabled features via new imap_client_feature_* variables X-Git-Tag: 2.3.9~1039 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bccc16d9ce65b080a6a59df88428622f3ab51d33;p=thirdparty%2Fdovecot%2Fcore.git imap: Access enabled features via new imap_client_feature_* variables This simplifies the following commits. --- diff --git a/src/imap/cmd-enable.c b/src/imap/cmd-enable.c index 2200856d55..2c7e2fbb2f 100644 --- a/src/imap/cmd-enable.c +++ b/src/imap/cmd-enable.c @@ -22,11 +22,11 @@ bool cmd_enable(struct client_command_context *cmd) str = t_str_ucase(str); if (strcmp(str, "CONDSTORE") == 0) { if (client_enable(cmd->client, - MAILBOX_FEATURE_CONDSTORE) == 0) + imap_feature_condstore) == 0) str_append(reply, " CONDSTORE"); } else if (strcmp(str, "QRESYNC") == 0) { - if (client_enable(cmd->client, MAILBOX_FEATURE_QRESYNC | - MAILBOX_FEATURE_CONDSTORE) == 0) + if (client_enable(cmd->client, imap_feature_qresync | + imap_feature_condstore) == 0) str_append(reply, " QRESYNC"); } } diff --git a/src/imap/cmd-fetch.c b/src/imap/cmd-fetch.c index 7b9ff2d220..0e1d30e5a3 100644 --- a/src/imap/cmd-fetch.c +++ b/src/imap/cmd-fetch.c @@ -128,7 +128,7 @@ fetch_parse_modifier(struct imap_fetch_context *ctx, } if (strcmp(name, "VANISHED") == 0 && cmd->uid) { if ((ctx->client->enabled_features & - MAILBOX_FEATURE_QRESYNC) == 0) { + imap_feature_qresync) == 0) { client_send_command_error(cmd, "QRESYNC not enabled"); return FALSE; } diff --git a/src/imap/cmd-select.c b/src/imap/cmd-select.c index 206601005c..f72a331df9 100644 --- a/src/imap/cmd-select.c +++ b/src/imap/cmd-select.c @@ -109,7 +109,7 @@ select_parse_qresync(struct imap_select_context *ctx, unsigned int count; if ((ctx->cmd->client->enabled_features & - MAILBOX_FEATURE_QRESYNC) == 0) { + imap_feature_qresync) == 0) { *error_r = "QRESYNC not enabled"; return FALSE; } @@ -411,7 +411,7 @@ bool cmd_select_full(struct client_command_context *cmd, bool readonly) if (ctx->condstore) { /* Enable while no mailbox is opened to avoid sending HIGHESTMODSEQ for previously opened mailbox */ - (void)client_enable(client, MAILBOX_FEATURE_CONDSTORE); + (void)client_enable(client, imap_feature_condstore); } ret = select_open(ctx, mailbox, readonly); diff --git a/src/imap/cmd-store.c b/src/imap/cmd-store.c index 0a8302a987..f97decad2d 100644 --- a/src/imap/cmd-store.c +++ b/src/imap/cmd-store.c @@ -67,7 +67,7 @@ store_parse_modifiers(struct imap_store_context *ctx, return FALSE; } (void)client_enable(ctx->cmd->client, - MAILBOX_FEATURE_CONDSTORE); + imap_feature_condstore); } else { client_send_command_error(ctx->cmd, "Unknown STORE modifier"); @@ -254,7 +254,7 @@ bool cmd_store(struct client_command_context *cmd) came externally, so we'll just send the UID for all flag changes that we see. */ if (cmd->uid && (!ctx.silent || (client->enabled_features & - MAILBOX_FEATURE_CONDSTORE) != 0)) + imap_feature_condstore) != 0)) imap_sync_flags |= IMAP_SYNC_FLAG_SEND_UID; return cmd_sync(cmd, (cmd->uid ? 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES), diff --git a/src/imap/imap-client.c b/src/imap/imap-client.c index 80b24e7877..e994134b2c 100644 --- a/src/imap/imap-client.c +++ b/src/imap/imap-client.c @@ -39,6 +39,9 @@ struct imap_module_register imap_module_register = { 0 }; struct client *imap_clients = NULL; unsigned int imap_client_count = 0; +unsigned int imap_feature_condstore = MAILBOX_FEATURE_CONDSTORE; +unsigned int imap_feature_qresync = MAILBOX_FEATURE_QRESYNC; + static const char *client_command_state_names[CLIENT_COMMAND_STATE_DONE+1] = { "wait-input", "wait-output", @@ -1457,7 +1460,7 @@ int client_enable(struct client *client, enum mailbox_feature features) return 0; ret = mailbox_enable(client->mailbox, features); - if ((features & MAILBOX_FEATURE_CONDSTORE) != 0 && ret == 0) { + if ((features & imap_feature_condstore) != 0 && ret == 0) { /* CONDSTORE being enabled while mailbox is selected. Notify client of the latest HIGHESTMODSEQ. */ ret = mailbox_get_status(client->mailbox, diff --git a/src/imap/imap-client.h b/src/imap/imap-client.h index d53dc1624d..637b644127 100644 --- a/src/imap/imap-client.h +++ b/src/imap/imap-client.h @@ -250,6 +250,9 @@ extern struct imap_module_register imap_module_register; extern struct client *imap_clients; extern unsigned int imap_client_count; +extern unsigned int imap_feature_condstore; +extern unsigned int imap_feature_qresync; + /* Create new client with specified input/output handles. socket specifies if the handle is a socket. */ struct client *client_create(int fd_in, int fd_out, const char *session_id, diff --git a/src/imap/imap-fetch.c b/src/imap/imap-fetch.c index 4df3cd5ee8..ea5c00c8c9 100644 --- a/src/imap/imap-fetch.c +++ b/src/imap/imap-fetch.c @@ -870,7 +870,7 @@ bool imap_fetch_modseq_init(struct imap_fetch_init_context *ctx) ctx->error = "FETCH MODSEQ can't be used with non-permanent modseqs"; return FALSE; } - (void)client_enable(ctx->fetch_ctx->client, MAILBOX_FEATURE_CONDSTORE); + (void)client_enable(ctx->fetch_ctx->client, imap_feature_condstore); imap_fetch_add_handler(ctx, IMAP_FETCH_HANDLER_FLAG_BUFFERED, NULL, fetch_modseq, NULL); return TRUE; diff --git a/src/imap/imap-notify.c b/src/imap/imap-notify.c index cf8199e19c..772af33176 100644 --- a/src/imap/imap-notify.c +++ b/src/imap/imap-notify.c @@ -51,7 +51,7 @@ static int imap_notify_status(struct imap_notify_namespace *notify_ns, int ret = 1; i_zero(&items); - if ((client->enabled_features & MAILBOX_FEATURE_CONDSTORE) != 0) + if ((client->enabled_features & imap_feature_condstore) != 0) items.status |= STATUS_HIGHESTMODSEQ; box = mailbox_alloc(notify_ns->ns->list, rec->vname, 0); diff --git a/src/imap/imap-search.c b/src/imap/imap-search.c index 95d5e40e53..521f3adc4d 100644 --- a/src/imap/imap-search.c +++ b/src/imap/imap-search.c @@ -576,7 +576,7 @@ bool imap_search_start(struct imap_search_context *ctx, if (ctx->have_modseqs) { ctx->return_options |= SEARCH_RETURN_MODSEQ; - (void)client_enable(cmd->client, MAILBOX_FEATURE_CONDSTORE); + (void)client_enable(cmd->client, imap_feature_condstore); } ctx->box = cmd->client->mailbox; diff --git a/src/imap/imap-state.c b/src/imap/imap-state.c index edb6c15a2f..1047aadc44 100644 --- a/src/imap/imap-state.c +++ b/src/imap/imap-state.c @@ -238,7 +238,7 @@ imap_state_export_mailbox(buffer_t *dest, struct client *client, numpack_encode(dest, status.uidvalidity); numpack_encode(dest, status.uidnext); numpack_encode(dest, status.messages); - if ((client->enabled_features & MAILBOX_FEATURE_QRESYNC) != 0 && + if ((client->enabled_features & imap_feature_qresync) != 0 && !client->nonpermanent_modseqs) numpack_encode(dest, client->sync_last_full_modseq); else @@ -284,12 +284,12 @@ int imap_state_export_base(struct client *client, bool internal, /* IMAP features */ if (client->enabled_features != 0) { - i_assert((client->enabled_features & ~(MAILBOX_FEATURE_CONDSTORE | - MAILBOX_FEATURE_QRESYNC)) == 0); + i_assert((client->enabled_features & ~(imap_feature_condstore | + imap_feature_qresync)) == 0); buffer_append_c(dest, IMAP_STATE_TYPE_ENABLED_FEATURES); - if ((client->enabled_features & MAILBOX_FEATURE_CONDSTORE) != 0) + if ((client->enabled_features & imap_feature_condstore) != 0) buffer_append_c(dest, IMAP_STATE_FEATURE_CONDSTORE); - if ((client->enabled_features & MAILBOX_FEATURE_QRESYNC) != 0) + if ((client->enabled_features & imap_feature_qresync) != 0) buffer_append_c(dest, IMAP_STATE_FEATURE_QRESYNC); buffer_append_c(dest, '\0'); } @@ -427,7 +427,7 @@ import_send_expunges(struct client *client, return -1; } - if ((client->enabled_features & MAILBOX_FEATURE_QRESYNC) == 0) { + if ((client->enabled_features & imap_feature_qresync) == 0) { str = t_str_new(32); for (i = expunge_count; i > 0; i--) { str_truncate(str, 0); @@ -475,7 +475,7 @@ import_send_flag_changes(struct client *client, pool_unref(&pool); imap_fetch_init_nofail_handler(fetch_ctx, imap_fetch_flags_init); - if ((client->enabled_features & MAILBOX_FEATURE_QRESYNC) != 0) { + if ((client->enabled_features & imap_feature_qresync) != 0) { imap_fetch_init_nofail_handler(fetch_ctx, imap_fetch_uid_init); imap_fetch_init_nofail_handler(fetch_ctx, imap_fetch_modseq_init); } @@ -678,7 +678,7 @@ import_state_mailbox_open(struct client *client, *error_r = "Couldn't send flag changes"; return -1; } - if ((client->enabled_features & MAILBOX_FEATURE_QRESYNC) != 0 && + if ((client->enabled_features & imap_feature_qresync) != 0 && !client->nonpermanent_modseqs && status.highest_modseq != state->highest_modseq) { client_send_line(client, t_strdup_printf( @@ -730,10 +730,10 @@ import_state_enabled_features(struct client *client, const unsigned char *data, feature = data[i]; switch (feature) { case IMAP_STATE_FEATURE_CONDSTORE: - client->enabled_features |= MAILBOX_FEATURE_CONDSTORE; + client->enabled_features |= imap_feature_condstore; break; case IMAP_STATE_FEATURE_QRESYNC: - client->enabled_features |= MAILBOX_FEATURE_QRESYNC; + client->enabled_features |= imap_feature_qresync; break; default: *error_r = t_strdup_printf( diff --git a/src/imap/imap-status.c b/src/imap/imap-status.c index 56e7fbb0ac..01cb8f8883 100644 --- a/src/imap/imap-status.c +++ b/src/imap/imap-status.c @@ -80,7 +80,7 @@ int imap_status_get(struct client_command_context *cmd, } if ((items->status & STATUS_HIGHESTMODSEQ) != 0) - (void)client_enable(client, MAILBOX_FEATURE_CONDSTORE); + (void)client_enable(client, imap_feature_condstore); ret = mailbox_get_status(box, items->status, &result_r->status); if (items->metadata != 0 && ret == 0) { diff --git a/src/imap/imap-sync.c b/src/imap/imap-sync.c index ad5d471f6a..658e0a2a18 100644 --- a/src/imap/imap-sync.c +++ b/src/imap/imap-sync.c @@ -195,7 +195,7 @@ imap_sync_init(struct client *client, struct mailbox *box, ctx->messages_count = client->messages_count; i_array_init(&ctx->tmp_keywords, client->keywords.announce_count + 8); - if ((client->enabled_features & MAILBOX_FEATURE_QRESYNC) != 0) { + if ((client->enabled_features & imap_feature_qresync) != 0) { i_array_init(&ctx->expunges, 128); /* always send UIDs in FETCH replies */ ctx->imap_flags |= IMAP_SYNC_FLAG_SEND_UID; @@ -345,7 +345,7 @@ int imap_sync_deinit(struct imap_sync_context *ctx, ret = imap_sync_finish(ctx, TRUE); imap_client_notify_finished(ctx->client); - if ((ctx->client->enabled_features & MAILBOX_FEATURE_QRESYNC) != 0 && + if ((ctx->client->enabled_features & imap_feature_qresync) != 0 && !ctx->client->nonpermanent_modseqs) imap_sync_send_highestmodseq(ctx, sync_cmd); @@ -387,7 +387,7 @@ static int imap_sync_send_flags(struct imap_sync_context *ctx, string_t *str) str_printfa(str, "* %u FETCH (", ctx->seq); if ((ctx->imap_flags & IMAP_SYNC_FLAG_SEND_UID) != 0) str_printfa(str, "UID %u ", ctx->mail->uid); - if ((ctx->client->enabled_features & MAILBOX_FEATURE_CONDSTORE) != 0 && + if ((ctx->client->enabled_features & imap_feature_condstore) != 0 && !ctx->client->nonpermanent_modseqs) { imap_sync_add_modseq(ctx, str); str_append_c(str, ' '); @@ -557,7 +557,7 @@ int imap_sync_more(struct imap_sync_context *ctx) break; case MAILBOX_SYNC_TYPE_MODSEQ: if ((ctx->client->enabled_features & - MAILBOX_FEATURE_CONDSTORE) == 0) + imap_feature_condstore) == 0) break; if (!ctx->client->notify_flag_changes) { /* NOTIFY: FlagChange not specified for