From: Siavash Tavakoli Date: Thu, 7 Jan 2021 09:40:51 +0000 (+0000) Subject: dsync: Check namespace prefix when syncing shared namespaces X-Git-Tag: 2.3.15~405 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6832759cf5709839d3f5a3104d07bef8239f0a8f;p=thirdparty%2Fdovecot%2Fcore.git dsync: Check namespace prefix when syncing shared namespaces When iterating over namespaces, comparing namespace pointers doesn't work for shared namespaces. Instead, check the prefix and include all the mailboxes in the namespace for syncing. --- diff --git a/src/doveadm/dsync/dsync-brain.c b/src/doveadm/dsync/dsync-brain.c index 235e64aa57..98ed04f824 100644 --- a/src/doveadm/dsync/dsync-brain.c +++ b/src/doveadm/dsync/dsync-brain.c @@ -841,6 +841,20 @@ const char *dsync_brain_get_unexpected_changes_reason(struct dsync_brain *brain, return brain->changes_during_sync; } +static bool dsync_brain_want_shared_namespace(const struct mail_namespace *ns, + const struct mail_namespace *sync_ns) +{ + /* Include shared namespaces and all its + children in the sync (e.g. "Shared/example.com" + will be synced to "Shared/"). + This also allows "dsync -n Shared/example.com/" + with "Shared/example.com/username/" style + shared namespace config. */ + return (ns->type == MAIL_NAMESPACE_TYPE_SHARED) && + (sync_ns->type == MAIL_NAMESPACE_TYPE_SHARED) && + str_begins(ns->prefix, sync_ns->prefix); +} + bool dsync_brain_want_namespace(struct dsync_brain *brain, struct mail_namespace *ns) { @@ -850,6 +864,8 @@ bool dsync_brain_want_namespace(struct dsync_brain *brain, array_foreach(&brain->sync_namespaces, nsp) { if (ns == *nsp) return TRUE; + if (dsync_brain_want_shared_namespace(ns, *nsp)) + return TRUE; } return FALSE; }