cmd-sort.c revision 2f25f180578a4c280c9f5fda1cb9f22410084a1e
5a580c3a38ced62d4bcc95b8ac7c4f2935b5d294Timo Sirainen/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
bd63b5b860658b01b1f46f26d406e1e4a9dc019aTimo Sirainenget_sort_program(struct client_command_context *cmd,
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen enum mail_sort_type program[MAX_SORT_PROGRAM_SIZE])
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen unsigned int i, pos;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen /* empyty list */
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen client_send_command_error(cmd, "Empty sort program.");
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen for (; args->type == IMAP_ARG_ATOM || args->type == IMAP_ARG_STRING;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen last_reverse = strcasecmp(arg, "reverse") == 0;
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen for (i = 0; sort_names[i].type != MAIL_SORT_END; i++) {
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen /* @UNSAFE: mask check should prevent us from ever
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen overflowing */
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen client_send_command_error(cmd, "Sort list ends with REVERSE.");
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen "Invalid sort list argument.");
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainenbool cmd_sort(struct client_command_context *cmd)
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen enum mail_sort_type sort_program[MAX_SORT_PROGRAM_SIZE];
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen /* sort program */
250a06cde50c4004ac1cc72279b75a229a7f90f5Timo Sirainen client_send_command_error(cmd, "Invalid sort argument.");
250a06cde50c4004ac1cc72279b75a229a7f90f5Timo Sirainen if (get_sort_program(cmd, IMAP_ARG_LIST_ARGS(args), sort_program) < 0)
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen /* charset */
1c633f71ec2060e5bfa500a97f34cd881a958ecdTimo Sirainen if (args->type != IMAP_ARG_ATOM && args->type != IMAP_ARG_STRING) {
6a33ecc05e60b511c1ae176ef113546e1012c18fTimo Sirainen "Invalid charset argument.");
6a33ecc05e60b511c1ae176ef113546e1012c18fTimo Sirainen ctx = p_new(cmd->pool, struct imap_search_context, 1);
6a33ecc05e60b511c1ae176ef113546e1012c18fTimo Sirainen if ((ret = cmd_search_parse_return_if_found(ctx, &args)) <= 0) {
6a33ecc05e60b511c1ae176ef113546e1012c18fTimo Sirainen /* error / waiting for unambiguity */
6a33ecc05e60b511c1ae176ef113546e1012c18fTimo Sirainen ret = imap_search_args_build(cmd, args, charset, &sargs);