bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2016-2018 Dovecot authors, see the included COPYING file */
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschstatic int mail_search_mime_build_list(struct mail_search_mime_build_context *ctx,
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschmail_search_mime_build_new(struct mail_search_mime_build_context *ctx,
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch arg = p_new(ctx->ctx->pool, struct mail_search_mime_arg, 1);
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschmail_search_mime_build_str(struct mail_search_mime_build_context *ctx,
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (mail_search_parse_string(ctx->ctx->parser, &value) < 0)
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch sarg->value.str = p_strdup(ctx->ctx->pool, value);
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschmail_search_mime_build_key_int(struct mail_search_mime_build_context *ctx,
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch struct mail_search_mime_arg *old_parent = ctx->parent;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch const struct mail_search_mime_register_arg *reg_arg;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if ((ret = mail_search_parse_key(ctx->ctx->parser, &key)) <= 0)
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (strcmp(key, MAIL_SEARCH_PARSER_KEY_LIST) == 0) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (mail_search_mime_build_list(ctx, &sarg) < 0)
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch ctx->ctx->_error = "No MIMEPART keys inside list";
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch reg_arg = mail_search_mime_register_find(key);
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch (ctx->ctx->pool, "Unknown MIMEPART key ", key, NULL);
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschint mail_search_mime_build_key(struct mail_search_mime_build_context *ctx,
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch ret = mail_search_mime_build_key_int(ctx, parent, arg_r);
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschstatic int mail_search_mime_build_list(struct mail_search_mime_build_context *ctx,
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch enum mail_search_mime_arg_type cur_type = SEARCH_MIME_SUB;
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch sarg = p_new(ctx->ctx->pool, struct mail_search_mime_arg, 1);
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch while ((ret = mail_search_mime_build_key_int(ctx, sarg, subargs)) > 0) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch /* expected type */
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch /* type changed. everything in this list must now
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch belong to this type. */
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch "Use parenthesis when mixing ANDs and ORs";
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Boschint mail_search_mime_build(struct mail_search_build_context *bctx,
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch p_new(bctx->pool, struct mail_search_mime_part, 1);
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if ((ret=mail_search_mime_build_key(&ctx, NULL, &root)) < 0)
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch if (root->type == SEARCH_MIME_SUB && !root->match_not) {
74bc7e646663255703e10e0c0b7242ad7ad52f94Stephan Bosch /* simple SUB root */