28
29
bool cmd_subscribe_full(struct client_command_context *cmd, bool subscribe)
30
struct mail_namespace *ns;
31
const char *mailbox, *verify_name;
31
struct mail_namespace *ns, *real_ns;
32
struct mail_storage *storage;
33
const char *mailbox, *mailbox2 = NULL, *verify_name, *real_name;
34
bool unsubscribed_mailbox2;
34
37
if (!client_read_string_args(cmd, 1, &mailbox))
37
39
verify_name = mailbox;
38
ns = mail_namespace_find_subscribable(cmd->client->namespaces,
42
ns = client_find_namespace(cmd, &real_name);
45
storage = ns->storage;
47
/* now find a namespace where the subscription can be added to */
48
ns = mail_namespace_find_subscribable(cmd->client->user->namespaces,
41
client_send_tagline(cmd, "NO Unknown namespace.");
51
client_send_tagline(cmd, "NO Unknown subscription namespace.");
55
real_ns = mail_storage_get_namespace(storage);
57
/* subscription is being written to a different namespace
58
than where the mailbox exists. */
59
mailbox = t_strconcat(real_ns->prefix, real_name, NULL);
60
/* drop the common prefix */
61
i_assert(strncmp(ns->prefix, mailbox, strlen(ns->prefix)) == 0);
62
mailbox += strlen(ns->prefix);
45
65
if ((client_workarounds & WORKAROUND_TB_EXTRA_MAILBOX_SEP) != 0 &&
46
66
*mailbox != '\0' && mailbox[strlen(mailbox)-1] ==
47
67
mail_storage_get_hierarchy_sep(ns->storage)) {
48
68
/* verify the validity without the trailing '/' */
49
69
verify_name = t_strndup(verify_name, strlen(verify_name)-1);
71
mailbox = t_strndup(mailbox, strlen(mailbox)-1);
52
if (have_listable_namespace_prefix(cmd->client->namespaces,
74
if (have_listable_namespace_prefix(cmd->client->user->namespaces,
54
76
/* subscribing to a listable namespace prefix, allow it. */
77
} else if (subscribe) {
78
if (!client_verify_mailbox_name(cmd, verify_name,
79
CLIENT_VERIFY_MAILBOX_SHOULD_EXIST))
56
82
if (!client_verify_mailbox_name(cmd, verify_name,
83
CLIENT_VERIFY_MAILBOX_NAME))
61
if (mailbox_list_set_subscribed(ns->list, mailbox, subscribe) < 0)
87
unsubscribed_mailbox2 = FALSE;
88
if (!subscribe && mailbox2 != NULL) {
89
/* try to unsubscribe both "box" and "box/" */
90
if (mailbox_list_set_subscribed(ns->list, mailbox2, FALSE) == 0)
91
unsubscribed_mailbox2 = TRUE;
94
if (mailbox_list_set_subscribed(ns->list, mailbox, subscribe) < 0 &&
95
!unsubscribed_mailbox2) {
62
96
client_send_list_error(cmd, ns->list);
64
98
client_send_tagline(cmd, subscribe ?
65
99
"OK Subscribe completed." :
66
100
"OK Unsubscribe completed.");