imap-commands-util.c revision 4e1f733fa64d01785de4ec987d83af65c273b9d1
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand/* Copyright (c) 2002-2014 Dovecot authors, see the included COPYING file */
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normandclient_find_namespace_full(struct client *client,
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand struct mail_namespace *namespaces = client->user->namespaces;
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand if (imap_utf7_to_utf8(*mailbox, utf8_name) < 0) {
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand *error_r = "NO Mailbox name is not valid mUTF-7";
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand ns = mail_namespace_find(namespaces, str_c(utf8_name));
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand if ((ns->flags & NAMESPACE_FLAG_AUTOCREATED) != 0 &&
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand /* this matched only the autocreated prefix="" namespace.
67e571de63a8e465dc8f1b17e16744a1d3fb552cStéphane Graber give a nice human-readable error message */
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand "NO Client tried to access nonexistent namespace. "
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand "(Mailbox name should probably be prefixed with: %s)",
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand mail_namespace_find_inbox(namespaces)->prefix);
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand str_c(utf8_name)[str_len(utf8_name)-1] == mail_namespace_get_sep(ns)) {
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand /* drop the extra trailing hierarchy separator */
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand str_truncate(utf8_name, str_len(utf8_name)-1);
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normandclient_find_namespace(struct client_command_context *cmd, const char **mailbox)
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand ns = client_find_namespace_full(cmd->client, mailbox, &error);
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normandbool client_verify_open_mailbox(struct client_command_context *cmd)
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand client_send_tagline(cmd, "BAD No mailbox selected.");
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normandint client_open_save_dest_box(struct client_command_context *cmd,
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand const char *name, struct mailbox **destbox_r)
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand mailbox_equals(cmd->client->mailbox, ns, name)) {
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand box = mailbox_alloc(ns->list, name, MAILBOX_FLAG_SAVEONLY);
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand error_string = mailbox_get_last_error(box, &error);
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand if (mailbox_enable(box, cmd->client->enabled_features) < 0) {
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normandimap_get_error_string(struct client_command_context *cmd,
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand const char *error_string, enum mail_error error)
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand if ((cmd->cmd_flags & COMMAND_FLAG_USE_NONEXISTENT) != 0)
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand if (resp_code == NULL || *error_string == '[')
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand return t_strdup_printf("NO [%s] %s", resp_code, error_string);
8d06bd135af4852f24660be965aba2d781223af4Dwight Engenvoid client_send_list_error(struct client_command_context *cmd,
8d06bd135af4852f24660be965aba2d781223af4Dwight Engen error_string = mailbox_list_get_last_error(list, &error);
8d06bd135af4852f24660be965aba2d781223af4Dwight Engen client_send_tagline(cmd, imap_get_error_string(cmd, error_string,
8d06bd135af4852f24660be965aba2d781223af4Dwight Engenvoid client_send_box_error(struct client_command_context *cmd,
63c3090c913142cd19f443b040cdede2c0522ce8Qiang Huang client_send_storage_error(cmd, mailbox_get_storage(box));
8d06bd135af4852f24660be965aba2d781223af4Dwight Engenvoid client_send_storage_error(struct client_command_context *cmd,
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand mailbox_is_inconsistent(cmd->client->mailbox)) {
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand /* we can't do forced CLOSE, so have to disconnect */
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand "IMAP session state is inconsistent, please relogin.");
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand error_string = mail_storage_get_last_error(storage, &error);
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand client_send_tagline(cmd, imap_get_error_string(cmd, error_string,
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normandvoid client_send_untagged_storage_error(struct client *client,
fe3b02ff94da199a8a327b3e92b6e42f2d875a45Wolfgang Bumiller /* we can't do forced CLOSE, so have to disconnect */
e555005b15a1d8e95997bd2d72abd0bc230a541dQiang Huang "IMAP session state is inconsistent, please relogin.");
8d06bd135af4852f24660be965aba2d781223af4Dwight Engen error_string = mail_storage_get_last_error(storage, &error);
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand client_send_line(client, t_strconcat("* NO ", error_string, NULL));
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normandbool client_parse_mail_flags(struct client_command_context *cmd,
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand const char *const **keywords_r)
8d06bd135af4852f24660be965aba2d781223af4Dwight Engen "Flags list contains non-atoms.");
8d06bd135af4852f24660be965aba2d781223af4Dwight Engen /* system flag */
cda02a28c0f41feb359ebbddd68ed5f1dcd4930eMichel Normand /* keyword validity checks are done by lib-storage */
501cbc717f4a6d9cace36ea78c88d9f00e9b7fdbMichel Normand array_append_zero(&keywords); /* NULL-terminate */
501cbc717f4a6d9cace36ea78c88d9f00e9b7fdbMichel Normandvoid client_send_mailbox_flags(struct client *client, bool selecting)
501cbc717f4a6d9cace36ea78c88d9f00e9b7fdbMichel Normand unsigned int count = array_count(client->keywords.names);
501cbc717f4a6d9cace36ea78c88d9f00e9b7fdbMichel Normand const char *const *keywords;
501cbc717f4a6d9cace36ea78c88d9f00e9b7fdbMichel Normand if (!selecting && count == client->keywords.announce_count) {
501cbc717f4a6d9cace36ea78c88d9f00e9b7fdbMichel Normand /* no changes to keywords and we're not selecting a mailbox */
&status);
const unsigned int *kw_indexes;
const char *const *all_names;
unsigned int all_count;