int imap_search_args_build(struct client_command_context *cmd, const struct imap_arg *args, const char *charset, struct mail_search_args **search_args_r) { struct mail_search_parser *parser; struct mail_search_args *sargs; const char *error; int ret; if (IMAP_ARG_IS_EOL(args)) { client_send_command_error(cmd, "Missing search parameters"); return -1; } parser = mail_search_parser_init_imap(args); ret = mail_search_build(mail_search_register_get_imap(), parser, &charset, &sargs, &error); mail_search_parser_deinit(&parser); if (ret < 0) { if (charset == NULL) { client_send_tagline(cmd, t_strconcat( "BAD [BADCHARSET] ", error, NULL)); } else { client_send_command_error(cmd, error); } return -1; } if (search_args_have_searchres(sargs->args)) { if (client_handle_search_save_ambiguity(cmd)) return 0; } mail_search_args_init(sargs, cmd->client->mailbox, TRUE, &cmd->client->search_saved_uidset); *search_args_r = sargs; return 1; }
static struct mail_search_args * virtual_search_args_parse(const string_t *rule, const char **error_r) { struct istream *input; struct imap_parser *imap_parser; const struct imap_arg *args; struct mail_search_parser *parser; struct mail_search_args *sargs; const char *charset = "UTF-8"; bool fatal; int ret; if (str_len(rule) == 0) { sargs = mail_search_build_init(); mail_search_build_add_all(sargs); return sargs; } input = i_stream_create_from_data(str_data(rule), str_len(rule)); (void)i_stream_read(input); imap_parser = imap_parser_create(input, NULL, (size_t)-1); ret = imap_parser_finish_line(imap_parser, 0, 0, &args); if (ret < 0) { sargs = NULL; *error_r = t_strdup(imap_parser_get_error(imap_parser, &fatal)); } else { parser = mail_search_parser_init_imap(args); if (mail_search_build(mail_search_register_get_imap(), parser, &charset, &sargs, error_r) < 0) sargs = NULL; mail_search_parser_deinit(&parser); } imap_parser_unref(&imap_parser); i_stream_destroy(&input); return sargs; }