bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */
fd14806f879f6cd4f023750e0c4cac27a7f94fbbTimo Sirainen { MAIL_SORT_RELEVANCY, "x-score" }, /* FIXME: obsolete */
f1e9611e93dcb3b745c1904029084fa81644e1b3Timo Sirainenget_sort_program(struct client_command_context *cmd,
a04cd96888653891272a512f7735121193af7b35Timo Sirainen enum mail_sort_type program[MAX_SORT_PROGRAM_SIZE])
19557f192d37cd54a1a090a8a26d9d47265e4413Aki Tuomi /* empty list */
e60a349c641bb2f4723e4a395a25f55531682d2bTimo Sirainen client_send_command_error(cmd, "Empty sort program.");
c2fbbf7515aa419dc8b2d62a3c2bb0471d51a391Timo Sirainen for (; imap_arg_get_astring(args, &arg); args++) {
828edf966ee46f65ec5d907f310cab270e7e1088Timo Sirainen last_reverse = strcasecmp(arg, "reverse") == 0;
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen for (i = 0; sort_names[i].type != MAIL_SORT_END; i++) {
a04cd96888653891272a512f7735121193af7b35Timo Sirainen /* @UNSAFE: mask check should prevent us from ever
a04cd96888653891272a512f7735121193af7b35Timo Sirainen overflowing */
828edf966ee46f65ec5d907f310cab270e7e1088Timo Sirainen client_send_command_error(cmd, "Sort list ends with REVERSE.");
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen "Invalid sort list argument.");
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainenbool cmd_sort(struct client_command_context *cmd)
d43bed2d458520fd01c28229ce2b178a4593a4a7Timo Sirainen enum mail_sort_type sort_program[MAX_SORT_PROGRAM_SIZE];
9995d93294b03312d3fcd99cad602f97af9bff40Timo Sirainen ctx = p_new(cmd->pool, struct imap_search_context, 1);
9995d93294b03312d3fcd99cad602f97af9bff40Timo Sirainen if ((ret = cmd_search_parse_return_if_found(ctx, &args)) <= 0) {
9995d93294b03312d3fcd99cad602f97af9bff40Timo Sirainen /* error / waiting for unambiguity */
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen /* sort program */
e60a349c641bb2f4723e4a395a25f55531682d2bTimo Sirainen client_send_command_error(cmd, "Invalid sort argument.");
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen if (get_sort_program(cmd, list_args, sort_program) < 0) {
55a7410569737197afb302b07b488973324b0cc5Timo Sirainen /* charset */
c2fbbf7515aa419dc8b2d62a3c2bb0471d51a391Timo Sirainen client_send_command_error(cmd, "Invalid charset argument.");
c4b376dd6e0c423006d7ac83a39253bcaf8e7c47Timo Sirainen ret = imap_search_args_build(cmd, args, charset, &sargs);