imap-commands-util.c revision 10ac3345fef3976ef573122de2a58a50c2fa63ce
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2002-2017 Dovecot authors, see the included COPYING file */
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainenclient_find_namespace_full(struct client *client,
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen struct mail_namespace *namespaces = client->user->namespaces;
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen if (imap_utf7_to_utf8(*mailbox, utf8_name) < 0) {
948b838c8e9896132e3a2d802fb5dad37e8dc716Timo Sirainen *error_r = "NO Mailbox name is not valid mUTF-7";
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainen ns = mail_namespace_find(namespaces, str_c(utf8_name));
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen if ((ns->flags & NAMESPACE_FLAG_AUTOCREATED) != 0 &&
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen /* this matched only the autocreated prefix="" namespace.
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen give a nice human-readable error message */
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen "NO Client tried to access nonexistent namespace. "
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen "(Mailbox name should probably be prefixed with: %s)",
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen mail_namespace_find_inbox(namespaces)->prefix);
5a0ac2e5ef482016e00575a7dce83f52c1704732Timo Sirainen str_c(utf8_name)[str_len(utf8_name)-1] == mail_namespace_get_sep(ns)) {
7823ef73e51bb81a17dcb306aff89016d4ce258fTimo Sirainen /* drop the extra trailing hierarchy separator */
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen str_truncate(utf8_name, str_len(utf8_name)-1);
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainenclient_find_namespace(struct client_command_context *cmd, const char **mailbox)
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen ns = client_find_namespace_full(cmd->client, mailbox, &error);
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainenbool client_verify_open_mailbox(struct client_command_context *cmd)
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainen client_send_tagline(cmd, "BAD No mailbox selected.");
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainenvoid imap_client_close_mailbox(struct client *client)
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainen if (array_is_created(&client->fetch_failed_uids))
dd2df6a67f10792ce31a3666197c0b6885893a3aTimo Sirainenint client_open_save_dest_box(struct client_command_context *cmd,
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen mailbox_equals(cmd->client->mailbox, ns, name)) {
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainen box = mailbox_alloc(ns->list, name, MAILBOX_FLAG_SAVEONLY);
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainen error_string = mailbox_get_last_error(box, &error);
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainen if (mailbox_enable(box, cmd->client->enabled_features) < 0) {
0c3ec2538c366bb5583f0b4ca2ce60804756b51cTimo Sirainenimap_get_error_string(struct client_command_context *cmd,
0c3ec2538c366bb5583f0b4ca2ce60804756b51cTimo Sirainen const char *error_string, enum mail_error error)
65d8efa66dca27db85f74ee2574188b51569a4c2Timo Sirainen case MAIL_ERROR_LOOKUP_ABORTED: /* BUG: shouldn't be visible here */
2c42748505ef4aed83ff59b34e50ed5606900c86Timo Sirainen if ((cmd->cmd_flags & COMMAND_FLAG_USE_NONEXISTENT) != 0)
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen if (resp_code == NULL || *error_string == '[')
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen return t_strconcat("NO ", error_string, NULL);
a91f2c465f026ca4ebb9e6c8e92800175c0dece6Timo Sirainen return t_strdup_printf("NO [%s] %s", resp_code, error_string);
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainenvoid client_send_list_error(struct client_command_context *cmd,
a91f2c465f026ca4ebb9e6c8e92800175c0dece6Timo Sirainen error_string = mailbox_list_get_last_error(list, &error);
a91f2c465f026ca4ebb9e6c8e92800175c0dece6Timo Sirainen client_send_tagline(cmd, imap_get_error_string(cmd, error_string,
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainenvoid client_disconnect_if_inconsistent(struct client *client)
a91f2c465f026ca4ebb9e6c8e92800175c0dece6Timo Sirainen /* we can't do forced CLOSE, so have to disconnect */
a91f2c465f026ca4ebb9e6c8e92800175c0dece6Timo Sirainen "IMAP session state is inconsistent, please relogin.");
4ce6338bf945cccfff9e4ce7cc6aa2246851b84aTimo Sirainenvoid client_send_box_error(struct client_command_context *cmd,
5c92436a61569c0b56a9374e60e779fa4455edefTimo Sirainen client_send_storage_error(cmd, mailbox_get_storage(box));
beffc30d933c5e134c45cc871852a8427eba7e70Timo Sirainenvoid client_send_storage_error(struct client_command_context *cmd,
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen error_string = mail_storage_get_last_error(storage, &error);
a91f2c465f026ca4ebb9e6c8e92800175c0dece6Timo Sirainen client_send_tagline(cmd, imap_get_error_string(cmd, error_string,
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen client_disconnect_if_inconsistent(cmd->client);
421973339968d444d4433cb4d47d1f150e4ab288Timo Sirainenvoid client_send_untagged_storage_error(struct client *client,
16b5dc27e7db42849510403d37e3629aba14de21Timo Sirainen error_string = mail_storage_get_last_error(storage, &error);
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen client_send_line(client, t_strconcat("* NO ", error_string, NULL));
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainenbool client_parse_mail_flags(struct client_command_context *cmd,
1c6f6f5bef70f16546b3bc8f4cd5f93f373e82a2Timo Sirainen const char *const **keywords_r)
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen "Flags list contains non-atoms.");
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen /* system flag */
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen /* keyword validity checks are done by lib-storage */
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen array_append_zero(&keywords); /* NULL-terminate */
65d8efa66dca27db85f74ee2574188b51569a4c2Timo Sirainenvoid client_send_mailbox_flags(struct client *client, bool selecting)
65d8efa66dca27db85f74ee2574188b51569a4c2Timo Sirainen unsigned int count = array_count(client->keywords.names);
65d8efa66dca27db85f74ee2574188b51569a4c2Timo Sirainen const char *const *keywords;
65d8efa66dca27db85f74ee2574188b51569a4c2Timo Sirainen if (!selecting && count == client->keywords.announce_count) {
65d8efa66dca27db85f74ee2574188b51569a4c2Timo Sirainen /* no changes to keywords and we're not selecting a mailbox */
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen mailbox_get_open_status(client->mailbox, STATUS_PERMANENT_FLAGS,
421973339968d444d4433cb4d47d1f150e4ab288Timo Sirainen imap_write_flags(str, status.flags, keywords);
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen imap_write_flags(str, status.permanent_flags, keywords);
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen if (status.permanent_flags != 0 || keywords != NULL)
ab7b5b9286104974c2a572a499ccf8b56c5d2955Timo Sirainenvoid client_update_mailbox_flags(struct client *client,
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainenconst char *const *
16b5dc27e7db42849510403d37e3629aba14de21Timo Sirainenclient_get_keyword_names(struct client *client, ARRAY_TYPE(keywords) *dest,
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen const unsigned int *kw_indexes;
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen const char *const *all_names;
f89cb43088c8b46d12d66ac924724b53ab14ce66Timo Sirainen /* convert indexes to names */