cmd-subscribe.c revision 1c885b304f060e3ac4fe04195a2f53457d0ac99e
89a126810703c666309310d0f3189e9834d70b5bTimo Sirainen/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainenstatic bool have_listable_namespace_prefix(struct mail_namespace *ns,
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen if ((ns->flags & (NAMESPACE_FLAG_LIST_PREFIX |
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /* if prefix has multiple hierarchies, allow subscribing to
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen any of the hierarchies */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen if (strncmp(ns->prefix, name, name_len) == 0 &&
043c8a96a035379bcba04f487d58457beefdfcaaTimo Sirainenbool cmd_subscribe_full(struct client_command_context *cmd, bool subscribe)
043c8a96a035379bcba04f487d58457beefdfcaaTimo Sirainen const char *mailbox, *verify_name, *real_name;
043c8a96a035379bcba04f487d58457beefdfcaaTimo Sirainen /* <mailbox> */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen if (!client_read_string_args(cmd, 1, &mailbox))
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen real_ns = client_find_namespace(cmd, &real_name,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /* now find a namespace where the subscription can be added to */
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen ns = mail_namespace_find_subscribable(cmd->client->user->namespaces,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen client_send_tagline(cmd, "NO Unknown subscription namespace.");
8fb1e3e2349c9940732b5bb77a2a4053b8f72a4fTimo Sirainen /* subscription is being written to a different namespace
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen than where the mailbox exists. */
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen mailbox = t_strconcat(real_ns->prefix, real_name, NULL);
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen /* drop the common prefix */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen i_assert(strncmp(ns->prefix, mailbox, strlen(ns->prefix)) == 0);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen if ((cmd->client->workarounds & WORKAROUND_TB_EXTRA_MAILBOX_SEP) != 0 &&
cf52b37d807553e91a2d6fb7cb2c8b4c34589e1dTimo Sirainen *mailbox != '\0' && mailbox[strlen(mailbox)-1] ==
4b058f90f9e8a2c6b2eed275de4eb8cc5195a71dTimo Sirainen /* verify the validity without the trailing '/' */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen verify_name = t_strndup(verify_name, strlen(verify_name)-1);
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen if (have_listable_namespace_prefix(cmd->client->user->namespaces,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /* subscribing to a listable namespace prefix, allow it. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen if (mailbox_list_set_subscribed(ns->list, mailbox, subscribe) < 0)
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen "OK Subscribe completed." :
87460b08cb97b31cde640d4975a6aa2c1d0e7226Timo Sirainen "OK Unsubscribe completed.");