commands-util.c revision cb05ecbd96ddb5e53c1850d27434541138a3f284
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (C) 2002-2003 Timo Sirainen */
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen/* Maximum length for mailbox name, including it's path. This isn't fully
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen exact since the user can create folder hierarchy with small names, then
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen rename them to larger names. Mail storages should set more strict limits
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen to them, mbox/maildir currently allow paths only up to PATH_MAX. */
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainenclient_find_namespace(struct client_command_context *cmd, const char **mailbox)
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen ns = mail_namespace_find(cmd->client->namespaces, mailbox);
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen client_send_tagline(cmd, "NO Unknown namespace.");
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainenclient_find_storage(struct client_command_context *cmd, const char **mailbox)
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainenbool client_verify_mailbox_name(struct client_command_context *cmd,
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen const char *orig_mailbox, *p;
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen /* make sure it even looks valid */
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen client_send_tagline(cmd, "NO Empty mailbox name.");
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen if (ns->real_sep != ns->sep && ns->prefix_len < strlen(orig_mailbox)) {
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen /* make sure there are no real separators used in the mailbox
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen "NO Character not allowed "
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen "in mailbox name: '%c'",
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen /* make sure two hierarchy separators aren't next to each others */
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen if (p[0] == ns->real_sep && p[-1] == ns->real_sep) {
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen client_send_tagline(cmd, "NO Invalid mailbox name.");
9346506a9f4dd9a6285fe8595588e73161849235Timo Sirainen client_send_tagline(cmd, "NO Mailbox name too long.");
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen /* check what our storage thinks of it */
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen if (mailbox_list_get_mailbox_name_status(list, mailbox,
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen client_send_tagline(cmd, "NO Mailbox exists.");
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen "NO [TRYCREATE] Mailbox doesn't exist: ",
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen str_sanitize(orig_mailbox, MAILBOX_MAX_NAME_LEN),
9fd2181788a61500641c66aec0f8c746b19bf830Timo Sirainen "NO Invalid mailbox name: ",
c6afd726060aae56b6622c6c52aec10231c4bf1cTimo Sirainen str_sanitize(orig_mailbox, MAILBOX_MAX_NAME_LEN),
9346506a9f4dd9a6285fe8595588e73161849235Timo Sirainen "NO Mailbox parent doesn't allow inferior mailboxes.");
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainenbool client_verify_open_mailbox(struct client_command_context *cmd)
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen client_send_tagline(cmd, "BAD No mailbox selected.");
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainenvoid client_send_list_error(struct client_command_context *cmd,
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen error_string = mailbox_list_get_last_error(list, &error);
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen client_send_tagline(cmd, t_strconcat("NO ", error_string, NULL));
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainenvoid client_send_storage_error(struct client_command_context *cmd,
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen mailbox_is_inconsistent(cmd->client->mailbox)) {
668f92ab0ef7aa42445716d653c5673ed874ab65Timo Sirainen /* we can't do forced CLOSE, so have to disconnect */
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen "Mailbox is in inconsistent state, please relogin.");
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen error_string = mail_storage_get_last_error(storage, &error);
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen client_send_tagline(cmd, t_strconcat("NO ", error_string, NULL));
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainenvoid client_send_untagged_storage_error(struct client *client,
4a9bbf81af2eba25653bbc4f744cc35e7bc9bb34Timo Sirainen /* we can't do forced CLOSE, so have to disconnect */
4a9bbf81af2eba25653bbc4f744cc35e7bc9bb34Timo Sirainen "Mailbox is in inconsistent state, please relogin.");
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen error_string = mail_storage_get_last_error(storage, &error);
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen client_send_line(client, t_strconcat("* NO ", error_string, NULL));
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainenbool client_parse_mail_flags(struct client_command_context *cmd,
9f37ef2a9192e7d47e3d7ac959080fd01120f2e9Aki Tuomi const char *const **keywords_r)
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen "Flags list contains non-atoms.");
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen /* system flag */
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainen "BAD Invalid system flag ",
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen /* keyword validity checks are done by lib-storage */
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen (void)array_append_space(&keywords); /* NULL-terminate */
50c617761ee9653bd44646a95178773a3686d62eTimo Sirainenstatic const char *get_keywords_string(const ARRAY_TYPE(keywords) *keywords)
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen const char *const *names;
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen unsigned int i, count;
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen for (i = 0; i < count; i++) {
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen#define SYSTEM_FLAGS "\\Answered \\Flagged \\Deleted \\Seen \\Draft"
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainenvoid client_send_mailbox_flags(struct client *client, struct mailbox *box,
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen const char *str;
ed157532dafb9dc25f98fda89bc1e324c3926898Timo Sirainen t_strconcat("* FLAGS ("SYSTEM_FLAGS, str, ")", NULL));
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen client_send_line(client, "* OK [PERMANENTFLAGS ()] "
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen "Read-only mailbox.");
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen t_strconcat("* OK [PERMANENTFLAGS ("SYSTEM_FLAGS, str,
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainenbool client_save_keywords(struct mailbox_keywords *dest,
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen /* first check if anything changes */
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen old_names = array_get(&dest->keywords, &old_count);
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen for (i = 0; i < count; i++) {
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen p_array_init(&dest->keywords, dest->pool, array_count(keywords));
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen for (i = 0; i < count; i++) {
8bad545017a5c2b69cf6fa06a50763b3b68fb161Timo Sirainen const char *name = p_strdup(dest->pool, names[i]);
return TRUE;
const char *name2)
const char *name1;
return FALSE;
return TRUE;