int mail_search_build(struct mail_search_register *reg, struct mail_search_parser *parser, const char **charset, struct mail_search_args **args_r, const char **error_r) { struct mail_search_build_context ctx; struct mail_search_args *args; struct mail_search_arg *root; const char *str; int ret; *args_r = NULL; *error_r = NULL; args = mail_search_build_init(); memset(&ctx, 0, sizeof(ctx)); ctx.pool = args->pool; ctx.reg = reg; ctx.parser = parser; ctx.charset = p_strdup(ctx.pool, *charset); ret = mail_search_build_list(&ctx, &root); if (!ctx.charset_checked && ret == 0) { /* make sure we give an error message if charset is invalid */ ret = mail_search_build_get_utf8(&ctx, "", &str); } if (ret < 0) { *error_r = ctx._error != NULL ? t_strdup(ctx._error) : t_strdup(mail_search_parser_get_error(parser)); if (ctx.unknown_charset) *charset = NULL; pool_unref(&args->pool); return -1; } if (root->type == SEARCH_SUB && !root->match_not) { /* simple SUB root */ args->args = root->value.subargs; } else { args->args = root; } *args_r = args; return 0; }
int mail_search_build(struct mail_search_register *reg, struct mail_search_parser *parser, const char *charset, struct mail_search_args **args_r, const char **error_r) { struct mail_search_build_context ctx; struct mail_search_args *args; struct mail_search_arg *root; *args_r = NULL; *error_r = NULL; args = mail_search_build_init(); args->charset = p_strdup(args->pool, charset); memset(&ctx, 0, sizeof(ctx)); ctx.pool = args->pool; ctx.reg = reg; ctx.parser = parser; if (mail_search_build_list(&ctx, &root) < 0) { *error_r = ctx._error != NULL ? t_strdup(ctx._error) : t_strdup(mail_search_parser_get_error(parser)); pool_unref(&args->pool); return -1; } if (root->type == SEARCH_SUB && !root->not) { /* simple SUB root */ args->args = root->value.subargs; } else { args->args = root; } *args_r = args; return 0; }