Skip to content

Commit

Permalink
imap: Access enabled features via new imap_client_feature_* variables
Browse files Browse the repository at this point in the history
This simplifies the following commits.
  • Loading branch information
sirainen authored and villesavolainen committed Feb 6, 2019
1 parent 184165f commit bbae1b3
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/imap/cmd-enable.c
Expand Up @@ -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");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/imap/cmd-fetch.c
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/imap/cmd-select.c
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/imap/cmd-store.c
Expand Up @@ -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");
Expand Down Expand Up @@ -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),
Expand Down
5 changes: 4 additions & 1 deletion src/imap/imap-client.c
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/imap/imap-client.h
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/imap/imap-fetch.c
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/imap/imap-notify.c
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/imap/imap-search.c
Expand Up @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions src/imap/imap-state.c
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/imap/imap-status.c
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/imap/imap-sync.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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, ' ');
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bbae1b3

Please sign in to comment.