Skip to content

Commit

Permalink
imapc: Add imapc_mailbox.capabilities
Browse files Browse the repository at this point in the history
Use it instead of imapc_client_get_capabilities(). Simplifies the
following patch.
  • Loading branch information
sirainen authored and GitLab committed Apr 24, 2017
1 parent 6e40a39 commit 1505427
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 31 deletions.
10 changes: 3 additions & 7 deletions src/lib-storage/index/imapc/imapc-search.c
Expand Up @@ -65,8 +65,6 @@ imapc_build_search_query_arg(struct imapc_mailbox *mbox,
const struct mail_search_arg *arg,
string_t *str)
{
enum imapc_capability capa =
imapc_client_get_capabilities(mbox->storage->client->client);
struct mail_search_arg arg2 = *arg;
const char *error;

Expand Down Expand Up @@ -100,7 +98,7 @@ imapc_build_search_query_arg(struct imapc_mailbox *mbox,
return TRUE;
case SEARCH_BEFORE:
case SEARCH_SINCE:
if ((capa & IMAPC_CAPABILITY_WITHIN) == 0) {
if ((mbox->capabilities & IMAPC_CAPABILITY_WITHIN) == 0) {
/* a bit kludgy way to check this.. */
size_t pos = str_len(str);
if (!mail_search_arg_to_imap(str, arg, &error))
Expand All @@ -126,7 +124,7 @@ imapc_build_search_query_arg(struct imapc_mailbox *mbox,
return mail_search_arg_to_imap(str, arg, &error);
/* extensions */
case SEARCH_MODSEQ:
if ((capa & IMAPC_CAPABILITY_CONDSTORE) == 0)
if ((mbox->capabilities & IMAPC_CAPABILITY_CONDSTORE) == 0)
return FALSE;
return mail_search_arg_to_imap(str, arg, &error);
case SEARCH_INTHREAD:
Expand Down Expand Up @@ -164,15 +162,13 @@ static bool imapc_build_search_query(struct imapc_mailbox *mbox,
const struct mail_search_args *args,
const char **query_r)
{
enum imapc_capability capa =
imapc_client_get_capabilities(mbox->storage->client->client);
string_t *str = t_str_new(128);

if (!IMAPC_BOX_HAS_FEATURE(mbox, IMAPC_FEATURE_SEARCH)) {
/* SEARCH command passthrough not enabled */
return FALSE;
}
if ((capa & IMAPC_CAPABILITY_ESEARCH) == 0) {
if ((mbox->capabilities & IMAPC_CAPABILITY_ESEARCH) == 0) {
/* FIXME: not supported for now */
return FALSE;
}
Expand Down
34 changes: 17 additions & 17 deletions src/lib-storage/index/imapc/imapc-storage.c
Expand Up @@ -77,11 +77,8 @@ bool imap_resp_text_code_parse(const char *str, enum mail_error *error_r)

bool imapc_mailbox_has_modseqs(struct imapc_mailbox *mbox)
{
enum imapc_capability capa =
imapc_client_get_capabilities(mbox->storage->client->client);

return (capa & (IMAPC_CAPABILITY_CONDSTORE |
IMAPC_CAPABILITY_QRESYNC)) != 0 &&
return (mbox->capabilities & (IMAPC_CAPABILITY_CONDSTORE |
IMAPC_CAPABILITY_QRESYNC)) != 0 &&
IMAPC_BOX_HAS_FEATURE(mbox, IMAPC_FEATURE_MODSEQ);
}

Expand Down Expand Up @@ -606,14 +603,16 @@ imapc_mailbox_open_callback(const struct imapc_command_reply *reply,
imapc_client_stop(ctx->mbox->storage->client->client);
}

static void imapc_mailbox_get_extensions(struct imapc_mailbox *mbox)
static void imapc_mailbox_get_capabilities(struct imapc_mailbox *mbox)
{
enum imapc_capability capa =
imapc_client_get_capabilities(mbox->storage->client->client);
mbox->capabilities = imapc_client_get_capabilities(mbox->storage->client->client);
}

static void imapc_mailbox_get_extensions(struct imapc_mailbox *mbox)
{
if (mbox->guid_fetch_field_name == NULL) {
/* see if we can get message GUIDs somehow */
if ((capa & IMAPC_CAPABILITY_X_GM_EXT_1) != 0) {
if ((mbox->capabilities & IMAPC_CAPABILITY_X_GM_EXT_1) != 0) {
/* GMail */
mbox->guid_fetch_field_name = "X-GM-MSGID";
}
Expand All @@ -631,6 +630,7 @@ int imapc_mailbox_select(struct imapc_mailbox *mbox)
if (mbox->storage->client->auth_failed) {
return -1;
}
imapc_mailbox_get_capabilities(mbox);

if (imapc_mailbox_has_modseqs(mbox)) {
if (!array_is_created(&mbox->rseq_modseqs))
Expand Down Expand Up @@ -898,6 +898,8 @@ static int imapc_mailbox_run_status(struct mailbox *box,
struct imapc_simple_context sctx;
string_t *str;

imapc_mailbox_get_capabilities(mbox);

str = t_str_new(256);
if ((items & STATUS_MESSAGES) != 0)
str_append(str, " MESSAGES");
Expand Down Expand Up @@ -968,17 +970,17 @@ static int imapc_mailbox_get_status(struct mailbox *box,
return 0;
}

static int imapc_mailbox_get_namespaces(struct imapc_storage *storage)
static int imapc_mailbox_get_namespaces(struct imapc_mailbox *mbox)
{
enum imapc_capability capa;
struct imapc_storage *storage = mbox->storage;
struct imapc_command *cmd;
struct imapc_simple_context sctx;

if (storage->namespaces_requested)
return 0;

capa = imapc_client_get_capabilities(storage->client->client);
if ((capa & IMAPC_CAPABILITY_NAMESPACE) == 0) {
imapc_mailbox_get_capabilities(mbox);
if ((mbox->capabilities & IMAPC_CAPABILITY_NAMESPACE) == 0) {
/* NAMESPACE capability not supported */
return 0;
}
Expand Down Expand Up @@ -1028,7 +1030,7 @@ static int imapc_mailbox_get_metadata(struct mailbox *box,
items &= ~MAILBOX_METADATA_GUID;
}
if ((items & MAILBOX_METADATA_BACKEND_NAMESPACE) != 0) {
if (imapc_mailbox_get_namespaces(mbox->storage) < 0)
if (imapc_mailbox_get_namespaces(mbox) < 0)
return -1;

ns = imapc_namespace_find_mailbox(mbox->storage, box->name);
Expand Down Expand Up @@ -1088,16 +1090,14 @@ static void imapc_notify_changes(struct mailbox *box)
struct imapc_mailbox *mbox = (struct imapc_mailbox *)box;
const struct mail_storage_settings *set = box->storage->set;
struct imapc_command *cmd;
enum imapc_capability capa;

if (box->notify_callback == NULL) {
if (mbox->to_idle_check != NULL)
timeout_remove(&mbox->to_idle_check);
return;
}

capa = imapc_client_get_capabilities(mbox->storage->client->client);
if ((capa & IMAPC_CAPABILITY_IDLE) != 0) {
if ((mbox->capabilities & IMAPC_CAPABILITY_IDLE) != 0) {
/* remote server is already in IDLE. but since some servers
don't notice changes immediately, we'll force them to check
here by sending a NOOP. this helps with clients that break
Expand Down
1 change: 1 addition & 0 deletions src/lib-storage/index/imapc/imapc-storage.h
Expand Up @@ -91,6 +91,7 @@ struct imapc_mailbox {
struct mailbox box;
struct imapc_storage *storage;
struct imapc_client_mailbox *client_box;
enum imapc_capability capabilities;

struct mail_index_transaction *delayed_sync_trans;
struct mail_index_view *sync_view, *delayed_sync_view;
Expand Down
9 changes: 2 additions & 7 deletions src/lib-storage/index/imapc/imapc-sync.c
Expand Up @@ -165,13 +165,11 @@ imapc_sync_index_keyword(struct imapc_sync_context *ctx,
static void imapc_sync_expunge_finish(struct imapc_sync_context *ctx)
{
string_t *str;
enum imapc_capability caps;

if (array_count(&ctx->expunged_uids) == 0)
return;

caps = imapc_client_get_capabilities(ctx->mbox->storage->client->client);
if ((caps & IMAPC_CAPABILITY_UIDPLUS) == 0) {
if ((ctx->mbox->capabilities & IMAPC_CAPABILITY_UIDPLUS) == 0) {
/* just expunge everything */
imapc_sync_cmd(ctx, "EXPUNGE");
return;
Expand Down Expand Up @@ -547,13 +545,10 @@ static int imapc_sync(struct imapc_mailbox *mbox)
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 (!mbox->initial_sync_done) {
/* we just SELECTed/EXAMINEd the mailbox, don't do another
NOOP. */
} else if ((capabilities & IMAPC_CAPABILITY_IDLE) == 0 ||
} else if ((mbox->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
Expand Down

0 comments on commit 1505427

Please sign in to comment.