dovecot: Moved several namespace booleans to a flags field. Remo...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Jun 27 20:21:05 EEST 2007
details: http://hg.dovecot.org/dovecot/rev/45735dd11f17
changeset: 5808:45735dd11f17
user: Timo Sirainen <tss at iki.fi>
date: Wed Jun 27 19:10:50 2007 +0300
description:
Moved several namespace booleans to a flags field. Removed unused
subscriptions boolean.
diffstat:
6 files changed, 48 insertions(+), 34 deletions(-)
src/imap/cmd-list.c | 15 ++++---
src/imap/cmd-namespace.c | 3 -
src/lib-storage/list/mailbox-list-fs-iter.c | 6 +-
src/lib-storage/list/mailbox-list-maildir-iter.c | 2
src/lib-storage/mail-namespace.c | 45 ++++++++++------------
src/lib-storage/mail-namespace.h | 11 ++++-
diffs (269 lines):
diff -r ec09ad1d017f -r 45735dd11f17 src/imap/cmd-list.c
--- a/src/imap/cmd-list.c Wed Jun 27 17:00:32 2007 +0300
+++ b/src/imap/cmd-list.c Wed Jun 27 19:10:50 2007 +0300
@@ -95,7 +95,8 @@ list_namespace_inbox(struct client *clie
{
const char *str;
- if (!ctx->inbox_found && ctx->ns->inbox && ctx->match_inbox &&
+ if (!ctx->inbox_found && ctx->match_inbox &&
+ (ctx->ns->flags & NAMESPACE_FLAG_INBOX) != 0 &&
(ctx->list_flags & MAILBOX_LIST_ITER_SUBSCRIBED) == 0) {
/* INBOX always exists */
str = t_strdup_printf("* LIST (\\Unmarked) \"%s\" \"INBOX\"",
@@ -110,7 +111,7 @@ list_insert_ns_prefix(string_t *name_str
{
if (strcasecmp(info->name, "INBOX") != 0) {
/* non-INBOX always has prefix */
- } else if (!ctx->ns->inbox) {
+ } else if ((ctx->ns->flags & NAMESPACE_FLAG_INBOX) == 0) {
/* INBOX from non-INBOX namespace. */
if (*ctx->ns->prefix == '\0') {
/* no namespace prefix, we can't list this */
@@ -172,7 +173,7 @@ list_namespace_mailboxes(struct client *
continue;
}
if (strcasecmp(name, "INBOX") == 0) {
- if (!ctx->ns->inbox)
+ if ((ctx->ns->flags & NAMESPACE_FLAG_INBOX) == 0)
continue;
name = "INBOX";
@@ -303,7 +304,8 @@ list_use_inboxcase(struct client_command
{
struct imap_match_glob *inbox_glob;
- if (*ctx->ns->prefix != '\0' && !ctx->ns->inbox)
+ if (*ctx->ns->prefix != '\0' &&
+ (ctx->ns->flags & NAMESPACE_FLAG_INBOX) == 0)
return IMAP_MATCH_NO;
/* if the original reference and mask combined produces something
@@ -391,14 +393,15 @@ list_namespace_init(struct client_comman
/* hidden and non-listable namespaces should still be seen
without wildcards. */
- match = (!ns->list_prefix &&
+ match = ((ns->flags & NAMESPACE_FLAG_LIST) == 0 &&
list_mask_has_wildcards(cur_mask)) ?
IMAP_MATCH_NO : imap_match(ctx->glob, cur_ns_prefix);
if (match < 0)
return;
len = strlen(ns->prefix);
- if (match == IMAP_MATCH_YES && ctx->ns->list_prefix &&
+ if (match == IMAP_MATCH_YES &&
+ (ctx->ns->flags & NAMESPACE_FLAG_LIST) != 0 &&
(ctx->list_flags & MAILBOX_LIST_ITER_SUBSCRIBED) == 0 &&
(!ctx->match_inbox ||
strncmp(ns->prefix, "INBOX", len-1) != 0)) {
diff -r ec09ad1d017f -r 45735dd11f17 src/imap/cmd-namespace.c
--- a/src/imap/cmd-namespace.c Wed Jun 27 17:00:32 2007 +0300
+++ b/src/imap/cmd-namespace.c Wed Jun 27 19:10:50 2007 +0300
@@ -12,7 +12,8 @@ static void list_namespaces(struct mail_
bool found = FALSE;
while (ns != NULL) {
- if (ns->type == type && !ns->hidden) {
+ if (ns->type == type &&
+ (ns->flags & NAMESPACE_FLAG_HIDDEN) == 0) {
if (!found) {
str_append_c(str, '(');
found = TRUE;
diff -r ec09ad1d017f -r 45735dd11f17 src/lib-storage/list/mailbox-list-fs-iter.c
--- a/src/lib-storage/list/mailbox-list-fs-iter.c Wed Jun 27 17:00:32 2007 +0300
+++ b/src/lib-storage/list/mailbox-list-fs-iter.c Wed Jun 27 19:10:50 2007 +0300
@@ -264,7 +264,8 @@ list_file(struct fs_list_iterate_context
/* make sure we give only one correct INBOX */
real_path = t_strconcat(ctx->dir->real_path, "/", fname, NULL);
- if (ctx->ctx.list->ns->inbox && strcasecmp(list_path, "INBOX") == 0) {
+ if ((ctx->ctx.list->ns->flags & NAMESPACE_FLAG_INBOX) != 0 &&
+ strcasecmp(list_path, "INBOX") == 0) {
if (ctx->inbox_listed) {
/* already listed the INBOX */
return 0;
@@ -424,7 +425,8 @@ fs_list_next(struct fs_list_iterate_cont
list_dir_context_free(dir);
}
- if (!ctx->inbox_found && ctx->ctx.list->ns->inbox &&
+ if (!ctx->inbox_found &&
+ (ctx->ctx.list->ns->flags & NAMESPACE_FLAG_INBOX) != 0 &&
ctx->glob != NULL && imap_match(ctx->glob, "INBOX") > 0) {
/* show inbox */
ctx->inbox_listed = TRUE;
diff -r ec09ad1d017f -r 45735dd11f17 src/lib-storage/list/mailbox-list-maildir-iter.c
--- a/src/lib-storage/list/mailbox-list-maildir-iter.c Wed Jun 27 17:00:32 2007 +0300
+++ b/src/lib-storage/list/mailbox-list-maildir-iter.c Wed Jun 27 19:10:50 2007 +0300
@@ -160,7 +160,7 @@ maildir_fill_readdir(struct maildir_list
return -1;
}
- if (ctx->ctx.list->ns->inbox &&
+ if ((ctx->ctx.list->ns->flags & NAMESPACE_FLAG_INBOX) != 0 &&
(ctx->ctx.flags & MAILBOX_LIST_ITER_SUBSCRIBED) == 0) {
/* make sure INBOX is there */
node = mailbox_tree_get(ctx->tree_ctx, "INBOX", &created);
diff -r ec09ad1d017f -r 45735dd11f17 src/lib-storage/mail-namespace.c
--- a/src/lib-storage/mail-namespace.c Wed Jun 27 17:00:32 2007 +0300
+++ b/src/lib-storage/mail-namespace.c Wed Jun 27 19:10:50 2007 +0300
@@ -30,20 +30,20 @@ namespace_add_env(pool_t pool, const cha
enum file_lock_method lock_method)
{
struct mail_namespace *ns;
- const char *sep, *type, *prefix;
+ const char *sep, *type, *prefix;
ns = p_new(pool, struct mail_namespace, 1);
sep = getenv(t_strdup_printf("NAMESPACE_%u_SEP", num));
type = getenv(t_strdup_printf("NAMESPACE_%u_TYPE", num));
prefix = getenv(t_strdup_printf("NAMESPACE_%u_PREFIX", num));
- ns->inbox = getenv(t_strdup_printf("NAMESPACE_%u_INBOX", num)) != NULL;
- ns->hidden = getenv(t_strdup_printf("NAMESPACE_%u_HIDDEN",
- num)) != NULL;
- ns->list_prefix = !ns->hidden && *prefix != '\0' &&
- getenv(t_strdup_printf("NAMESPACE_%u_LIST", num)) != NULL;
- ns->subscriptions = getenv(t_strdup_printf("NAMESPACE_%u_SUBSCRIPTIONS",
- num)) != NULL;
+ if (getenv(t_strdup_printf("NAMESPACE_%u_INBOX", num)) != NULL)
+ ns->flags |= NAMESPACE_FLAG_INBOX;
+ if (getenv(t_strdup_printf("NAMESPACE_%u_HIDDEN", num)) != NULL)
+ ns->flags |= NAMESPACE_FLAG_HIDDEN;
+ if ((ns->flags & NAMESPACE_FLAG_HIDDEN) == 0 && *prefix != '\0' &&
+ getenv(t_strdup_printf("NAMESPACE_%u_LIST", num)) != NULL)
+ ns->flags |= NAMESPACE_FLAG_LIST;
if (type == NULL || *type == '\0' || strncmp(type, "private", 7) == 0)
ns->type = NAMESPACE_PRIVATE;
@@ -61,12 +61,11 @@ namespace_add_env(pool_t pool, const cha
if ((flags & MAIL_STORAGE_FLAG_DEBUG) != 0) {
i_info("Namespace: type=%s, prefix=%s, sep=%s, "
- "inbox=%s, hidden=%s, list=%s, subscriptions=%s",
+ "inbox=%s, hidden=%s, list=%s",
type == NULL ? "" : type, prefix, sep == NULL ? "" : sep,
- ns->inbox ? "yes" : "no",
- ns->hidden ? "yes" : "no",
- ns->list ? "yes" : "no",
- ns->subscriptions ? "yes" : "no");
+ (ns->flags & NAMESPACE_FLAG_INBOX) ? "yes" : "no",
+ (ns->flags & NAMESPACE_FLAG_HIDDEN) ? "yes" : "no",
+ (ns->flags & NAMESPACE_FLAG_LIST) ? "yes" : "no");
}
ns->prefix = p_strdup(pool, prefix);
@@ -89,7 +88,7 @@ static bool namespaces_check(struct mail
char list_sep = '\0';
for (ns = namespaces; ns != NULL; ns = ns->next) {
- if (ns->inbox) {
+ if ((ns->flags & NAMESPACE_FLAG_INBOX) != 0) {
if (inbox_ns != NULL) {
i_error("namespace configuration error: "
"There can be only one namespace with "
@@ -102,14 +101,14 @@ static bool namespaces_check(struct mail
private_ns = ns;
private_ns_count++;
}
- if (ns->list_prefix &&
+ if ((ns->flags & NAMESPACE_FLAG_LIST) != 0 &&
ns->prefix[strlen(ns->prefix)-1] != ns->sep) {
i_error("namespace configuration error: "
"list=yes requires prefix=%s "
"to end with separator", ns->prefix);
return FALSE;
}
- if (ns->list_prefix) {
+ if ((ns->flags & NAMESPACE_FLAG_LIST) != 0) {
if (list_sep == '\0')
list_sep = ns->sep;
else if (list_sep != ns->sep) {
@@ -125,7 +124,7 @@ static bool namespaces_check(struct mail
if (private_ns_count == 1) {
/* just one private namespace. we'll assume it's
the INBOX namespace. */
- private_ns->inbox = TRUE;
+ private_ns->flags |= NAMESPACE_FLAG_INBOX;
} else {
i_error("namespace configuration error: "
"inbox=yes namespace missing");
@@ -209,8 +208,7 @@ int mail_namespaces_init(pool_t pool, co
ns = p_new(pool, struct mail_namespace, 1);
ns->type = NAMESPACE_PRIVATE;
- ns->inbox = TRUE;
- ns->subscriptions = TRUE;
+ ns->flags = NAMESPACE_FLAG_INBOX | NAMESPACE_FLAG_LIST;
ns->prefix = "";
if (mail_storage_create(ns, NULL, mail, user, flags, lock_method) < 0) {
@@ -239,7 +237,7 @@ struct mail_namespace *mail_namespaces_i
ns = p_new(pool, struct mail_namespace, 1);
ns->prefix = "";
- ns->inbox = TRUE;
+ ns->flags = NAMESPACE_FLAG_INBOX | NAMESPACE_FLAG_LIST;
return ns;
}
@@ -272,7 +270,7 @@ const char *mail_namespace_fix_sep(struc
char mail_namespace_get_root_sep(struct mail_namespace *namespaces)
{
- while (!namespaces->list_prefix)
+ while ((namespaces->flags & NAMESPACE_FLAG_LIST) == 0)
namespaces = namespaces->next;
return namespaces->sep;
}
@@ -282,7 +280,7 @@ mail_namespace_find_int(struct mail_name
bool show_hidden)
{
#define CHECK_VISIBILITY(ns, show_hidden) \
- ((!(ns)->hidden) || (show_hidden))
+ (((ns)->flags & NAMESPACE_FLAG_HIDDEN) == 0 || (show_hidden))
struct mail_namespace *ns = namespaces;
const char *box = *mailbox;
struct mail_namespace *best = NULL;
@@ -294,7 +292,8 @@ mail_namespace_find_int(struct mail_name
/* find the INBOX namespace */
*mailbox = "INBOX";
while (ns != NULL) {
- if (ns->inbox && CHECK_VISIBILITY(ns, show_hidden))
+ if ((ns->flags & NAMESPACE_FLAG_INBOX) != 0 &&
+ CHECK_VISIBILITY(ns, show_hidden))
return ns;
if (*ns->prefix == '\0')
best = ns;
diff -r ec09ad1d017f -r 45735dd11f17 src/lib-storage/mail-namespace.h
--- a/src/lib-storage/mail-namespace.h Wed Jun 27 17:00:32 2007 +0300
+++ b/src/lib-storage/mail-namespace.h Wed Jun 27 19:10:50 2007 +0300
@@ -7,17 +7,26 @@ enum namespace_type {
NAMESPACE_PUBLIC
};
+enum namespace_flags {
+ /* Namespace contains the INBOX mailbox (there can be only one) */
+ NAMESPACE_FLAG_INBOX = 0x01,
+ /* Namespace is visible only by explicitly using its full prefix */
+ NAMESPACE_FLAG_HIDDEN = 0x02,
+ /* Namespace is visible with LIST */
+ NAMESPACE_FLAG_LIST = 0x04
+};
+
struct mail_namespace {
/* Namespaces are sorted by their prefix length, "" comes first */
struct mail_namespace *next;
enum namespace_type type;
char sep, real_sep, sep_str[3];
+ enum namespace_flags flags;
const char *prefix;
size_t prefix_len;
- bool inbox, hidden, list_prefix, subscriptions;
struct mailbox_list *list;
/* FIXME: we should support multiple storages in one namespace */
struct mail_storage *storage;
More information about the dovecot-cvs
mailing list