Skip to content

Commit

Permalink
imapc: Support imapc_features=search without ESEARCH extension
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed Apr 24, 2017
1 parent 906bc95 commit efcc1c4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
11 changes: 10 additions & 1 deletion src/lib-storage/index/imapc/imapc-mailbox.c
Expand Up @@ -546,6 +546,13 @@ imapc_untagged_esearch_gmail_pop3(const struct imap_arg *args,
mail_index_keywords_unref(&kw);
}

static void imapc_untagged_search(const struct imapc_untagged_reply *reply,
struct imapc_mailbox *mbox)
{
if (mbox != NULL)
imapc_search_reply_search(reply->args, mbox);
}

static void imapc_untagged_esearch(const struct imapc_untagged_reply *reply,
struct imapc_mailbox *mbox)
{
Expand All @@ -567,7 +574,7 @@ static void imapc_untagged_esearch(const struct imapc_untagged_reply *reply,
strcmp(mbox->sync_gmail_pop3_search_tag, str) == 0)
imapc_untagged_esearch_gmail_pop3(reply->args+1, mbox);
else
imapc_search_reply(reply->args+1, mbox);
imapc_search_reply_esearch(reply->args+1, mbox);
}

static void
Expand Down Expand Up @@ -674,6 +681,8 @@ void imapc_mailbox_register_callbacks(struct imapc_mailbox *mbox)
imapc_untagged_fetch);
imapc_mailbox_register_untagged(mbox, "EXPUNGE",
imapc_untagged_expunge);
imapc_mailbox_register_untagged(mbox, "SEARCH",
imapc_untagged_search);
imapc_mailbox_register_untagged(mbox, "ESEARCH",
imapc_untagged_esearch);
imapc_mailbox_register_resp_text(mbox, "UIDVALIDITY",
Expand Down
34 changes: 27 additions & 7 deletions src/lib-storage/index/imapc/imapc-search.c
Expand Up @@ -168,14 +168,13 @@ static bool imapc_build_search_query(struct imapc_mailbox *mbox,
/* SEARCH command passthrough not enabled */
return FALSE;
}
if ((mbox->capabilities & IMAPC_CAPABILITY_ESEARCH) == 0) {
/* FIXME: not supported for now */
return FALSE;
}
if (imapc_search_is_fast_local(args->args))
return FALSE;

str_append(str, "SEARCH RETURN (ALL) ");
if ((mbox->capabilities & IMAPC_CAPABILITY_ESEARCH) != 0)
str_append(str, "SEARCH RETURN (ALL) ");
else
str_append(str, "SEARCH ");
if (!imapc_build_search_query_args(mbox, args->args, FALSE, str))
return FALSE;
*query_r = str_c(str);
Expand Down Expand Up @@ -278,8 +277,29 @@ int imapc_search_deinit(struct mail_search_context *ctx)
return index_storage_search_deinit(ctx);
}

void imapc_search_reply(const struct imap_arg *args,
struct imapc_mailbox *mbox)
void imapc_search_reply_search(const struct imap_arg *args,
struct imapc_mailbox *mbox)
{
const char *atom;
uint32_t seq;

if (mbox->search_ctx == NULL) {
i_error("Unexpected SEARCH reply");
return;
}

for (unsigned int i = 0; args[i].type != IMAP_ARG_EOL; i++) {
if (!imap_arg_get_atom(&args[i], &atom) ||
str_to_uint32(atom, &seq) < 0 || seq == 0) {
i_error("Invalid SEARCH reply");
break;
}
seq_range_array_add(&mbox->search_ctx->rseqs, seq);
}
}

void imapc_search_reply_esearch(const struct imap_arg *args,
struct imapc_mailbox *mbox)
{
const char *atom;

Expand Down
6 changes: 4 additions & 2 deletions src/lib-storage/index/imapc/imapc-search.h
Expand Up @@ -10,7 +10,9 @@ imapc_search_init(struct mailbox_transaction_context *t,
bool imapc_search_next_update_seq(struct mail_search_context *ctx);
int imapc_search_deinit(struct mail_search_context *ctx);

void imapc_search_reply(const struct imap_arg *args,
struct imapc_mailbox *mbox);
void imapc_search_reply_search(const struct imap_arg *args,
struct imapc_mailbox *mbox);
void imapc_search_reply_esearch(const struct imap_arg *args,
struct imapc_mailbox *mbox);

#endif

0 comments on commit efcc1c4

Please sign in to comment.