break;
}
+ /* non-match */
+ if (_ctx->args->stop_on_nonmatch) {
+ ret = -1;
+ break;
+ }
+
cost2 = search_get_cost(mail->transaction);
ctx->cost += cost2 - cost1;
cost1 = cost2;
if (imail->data.search_results == NULL)
break;
- /* searching wasn't finished yet */
+ /* prefetch running - searching wasn't finished yet */
if (search_finish_prefetch(ctx, imail))
break;
/* search finished as non-match */
+ if (ctx->mail_ctx.args->stop_on_nonmatch) {
+ ret = -1;
+ break;
+ }
}
return ret;
}
*args_r = NULL;
*error_r = NULL;
- args = mail_search_build_init();
-
memset(&ctx, 0, sizeof(ctx));
+ ctx.args = args = mail_search_build_init();
ctx.pool = args->pool;
ctx.reg = reg;
ctx.parser = parser;
struct mail_search_build_context {
pool_t pool;
+ struct mail_search_args *args;
struct mail_search_register *reg;
struct mail_search_parser *parser;
const char *charset;
return mail_search_build_str(ctx, SEARCH_MAILBOX_GUID);
}
+static struct mail_search_arg *
+human_search_oldestonly(struct mail_search_build_context *ctx)
+{
+ ctx->args->stop_on_nonmatch = TRUE;
+ return mail_search_build_new(ctx, SEARCH_ALL);
+}
+
static const struct mail_search_register_arg human_register_args[] = {
{ "OR", human_search_or },
/* Other Dovecot extensions: */
{ "GUID", human_search_guid },
{ "MAILBOX", human_search_mailbox },
- { "MAILBOX-GUID", human_search_mailbox_guid }
+ { "MAILBOX-GUID", human_search_mailbox_guid },
+ { "OLDESTONLY", human_search_oldestonly }
};
static struct mail_search_register *
unsigned int simplified:1;
unsigned int have_inthreads:1;
+ /* Stop mail_search_next() when finding a non-matching mail.
+ (Could be useful when wanting to find only the oldest mails.) */
+ unsigned int stop_on_nonmatch:1;
};
#define ARG_SET_RESULT(arg, res) \