]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dsync: Check namespace prefix when syncing shared namespaces
authorSiavash Tavakoli <siavash.tavakoli@open-xchange.com>
Thu, 7 Jan 2021 09:40:51 +0000 (09:40 +0000)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 11 Feb 2021 10:42:15 +0000 (10:42 +0000)
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.

src/doveadm/dsync/dsync-brain.c

index 235e64aa573d65ab5bb0e7ce03edd6d534ac5a57..98ed04f82450cf5e11052a86a1ab1dcc5c15e22a 100644 (file)
@@ -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;
        }