You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2021/03/08 08:28:12 UTC

[GitHub] [james-project] chibenwa opened a new pull request #326: MAILBOX-405 Add a task to subscribe all mailboxes belonging to a user

chibenwa opened a new pull request #326:
URL: https://github.com/apache/james-project/pull/326


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[GitHub] [james-project] chibenwa commented on a change in pull request #326: MAILBOX-405 Add a task to subscribe all mailboxes belonging to a user

Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #326:
URL: https://github.com/apache/james-project/pull/326#discussion_r589307722



##########
File path: src/site/markdown/server/manage-webadmin.md
##########
@@ -1136,6 +1136,33 @@ Warning: Canceling this task should be considered unsafe as it will leave the cu
 Warning: While we have been trying to reduce the inconsistency window to a maximum (by keeping track of ongoing events),
 concurrent changes done during the reIndexing might be ignored.
 
+### Subscribing a user to all of its mailboxes
+ 
+```
+curl -XPOST http://ip:port/users/{usernameToBeUsed}/mailboxes?task=subscribeAll
+```
+
+Will schedule a task for subscribing a user to all of its mailboxes.

Review comment:
       > What's the goal of this task? 
   
   Due to partial renames TB do mess the subscription up, keeping subscribed some mailboxes that no longer exists, and keeping unsubscribed mailboxes that exists.
   
   This results in 'grey unusable' folders. Updating the subscription to the real mailbox works.
   
   Most users are unaware of what a subscription  is. And managing subscriptions manually is a fastidious task (some of our users have 1000+ mailboxes). 
   
   As such having a task to do it automatically as an admin allows to easily solve such problems when reported.
   
   > What happens if a user deliberately wants to not subscribe to some of her folders?
   
   The scope is to only run if it is relevant for the given users (they complains about subscription related bugs).
   
   People able to manage their subscription themselves are not affected.
   
   That's why I decided that the task should be user scoped, to allow such flexibility.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[GitHub] [james-project] Arsnael commented on a change in pull request #326: MAILBOX-405 Add a task to subscribe all mailboxes belonging to a user

Posted by GitBox <gi...@apache.org>.
Arsnael commented on a change in pull request #326:
URL: https://github.com/apache/james-project/pull/326#discussion_r589891441



##########
File path: server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/SubscribeAllTask.java
##########
@@ -0,0 +1,135 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.webadmin.service;
+
+import java.time.Clock;
+import java.time.Instant;
+import java.util.Collection;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.james.core.Username;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.SubscriptionManager;
+import org.apache.james.mailbox.exception.SubscriptionException;
+import org.apache.james.mailbox.model.search.MailboxQuery;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskExecutionDetails;
+import org.apache.james.task.TaskType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.github.fge.lambdas.Throwing;
+
+public class SubscribeAllTask implements Task {
+    static final TaskType TASK_TYPE = TaskType.of("SubscribeAllTask");
+    private static final Logger LOGGER = LoggerFactory.getLogger(SubscribeAllTask.class);
+
+    public static class AdditionalInformation implements TaskExecutionDetails.AdditionalInformation {
+        private final Username username;
+        private final long subscribedCount;
+        private final long unsubscribedCount;
+        private final Instant timestamp;
+
+        public AdditionalInformation(Username username, long subscribedCount, long unsubscribedCount, Instant timestamp) {
+            this.username = username;
+            this.subscribedCount = subscribedCount;
+            this.unsubscribedCount = unsubscribedCount;
+            this.timestamp = timestamp;
+        }
+
+        public Username getUsername() {
+            return username;
+        }
+
+        public long getSubscribedCount() {
+            return subscribedCount;
+        }
+
+        public long getUnsubscribedCount() {
+            return unsubscribedCount;
+        }
+
+        @Override
+        public Instant timestamp() {
+            return timestamp;
+        }
+    }
+
+    private final MailboxManager mailboxManager;
+    private final SubscriptionManager subscriptionManager;
+    private final Username username;
+    private final AtomicLong subscribedCount;
+    private final AtomicLong unsubscribedCount;
+
+    public SubscribeAllTask(MailboxManager mailboxManager, SubscriptionManager subscriptionManager, Username username) {
+        this.mailboxManager = mailboxManager;
+        this.subscriptionManager = subscriptionManager;
+        this.username = username;
+        subscribedCount = new AtomicLong(0);
+        unsubscribedCount = new AtomicLong(0);
+    }
+
+    @Override
+    public Result run() {
+        final MailboxSession session = mailboxManager.createSystemSession(username);
+        try {
+            Collection<String> subscriptions = subscriptionManager.subscriptions(session);
+            List<String> names = mailboxManager.search(MailboxQuery.privateMailboxesBuilder(session).build(), session)
+                .map(mailbox -> mailbox.getPath().getName())
+                .collectList()
+                .block();
+
+            subscriptions.stream()
+                .filter(subscription -> !names.contains(subscription))
+                .forEach(Throwing.consumer(subscription -> {
+                    subscriptionManager.unsubscribe(session, subscription);
+                    unsubscribedCount.incrementAndGet();
+                }));
+            names.stream()
+                .filter(name -> !subscriptions.contains(name))
+                .forEach(Throwing.consumer(name -> {
+                    subscriptionManager.subscribe(session, name);
+                    subscribedCount.incrementAndGet();
+                }));
+
+        } catch (SubscriptionException e) {
+            LOGGER.error("Couldnot retrieve subscriptions for {}", username, e);

Review comment:
       ```suggestion
                LOGGER.error("Could not retrieve subscriptions for {}", username, e); 
   ```

##########
File path: server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/SubscribeAllTask.java
##########
@@ -0,0 +1,135 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.webadmin.service;
+
+import java.time.Clock;
+import java.time.Instant;
+import java.util.Collection;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.james.core.Username;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.SubscriptionManager;
+import org.apache.james.mailbox.exception.SubscriptionException;
+import org.apache.james.mailbox.model.search.MailboxQuery;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskExecutionDetails;
+import org.apache.james.task.TaskType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.github.fge.lambdas.Throwing;
+
+public class SubscribeAllTask implements Task {
+    static final TaskType TASK_TYPE = TaskType.of("SubscribeAllTask");
+    private static final Logger LOGGER = LoggerFactory.getLogger(SubscribeAllTask.class);
+
+    public static class AdditionalInformation implements TaskExecutionDetails.AdditionalInformation {
+        private final Username username;
+        private final long subscribedCount;
+        private final long unsubscribedCount;
+        private final Instant timestamp;
+
+        public AdditionalInformation(Username username, long subscribedCount, long unsubscribedCount, Instant timestamp) {
+            this.username = username;
+            this.subscribedCount = subscribedCount;
+            this.unsubscribedCount = unsubscribedCount;
+            this.timestamp = timestamp;
+        }
+
+        public Username getUsername() {
+            return username;
+        }
+
+        public long getSubscribedCount() {
+            return subscribedCount;
+        }
+
+        public long getUnsubscribedCount() {
+            return unsubscribedCount;
+        }
+
+        @Override
+        public Instant timestamp() {
+            return timestamp;
+        }
+    }
+
+    private final MailboxManager mailboxManager;
+    private final SubscriptionManager subscriptionManager;
+    private final Username username;
+    private final AtomicLong subscribedCount;
+    private final AtomicLong unsubscribedCount;
+
+    public SubscribeAllTask(MailboxManager mailboxManager, SubscriptionManager subscriptionManager, Username username) {
+        this.mailboxManager = mailboxManager;
+        this.subscriptionManager = subscriptionManager;
+        this.username = username;
+        subscribedCount = new AtomicLong(0);
+        unsubscribedCount = new AtomicLong(0);
+    }
+
+    @Override
+    public Result run() {
+        final MailboxSession session = mailboxManager.createSystemSession(username);
+        try {
+            Collection<String> subscriptions = subscriptionManager.subscriptions(session);
+            List<String> names = mailboxManager.search(MailboxQuery.privateMailboxesBuilder(session).build(), session)
+                .map(mailbox -> mailbox.getPath().getName())
+                .collectList()
+                .block();
+
+            subscriptions.stream()
+                .filter(subscription -> !names.contains(subscription))
+                .forEach(Throwing.consumer(subscription -> {
+                    subscriptionManager.unsubscribe(session, subscription);
+                    unsubscribedCount.incrementAndGet();
+                }));
+            names.stream()
+                .filter(name -> !subscriptions.contains(name))
+                .forEach(Throwing.consumer(name -> {
+                    subscriptionManager.subscribe(session, name);
+                    subscribedCount.incrementAndGet();
+                }));
+
+        } catch (SubscriptionException e) {
+            LOGGER.error("Couldnot retrieve subscriptions for {}", username, e);

Review comment:
       ```suggestion
               LOGGER.error("Could not retrieve subscriptions for {}", username, e); 
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[GitHub] [james-project] chibenwa closed pull request #326: MAILBOX-405 Add a task to subscribe all mailboxes belonging to a user

Posted by GitBox <gi...@apache.org>.
chibenwa closed pull request #326:
URL: https://github.com/apache/james-project/pull/326


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[GitHub] [james-project] rouazana commented on a change in pull request #326: MAILBOX-405 Add a task to subscribe all mailboxes belonging to a user

Posted by GitBox <gi...@apache.org>.
rouazana commented on a change in pull request #326:
URL: https://github.com/apache/james-project/pull/326#discussion_r589308835



##########
File path: src/site/markdown/server/manage-webadmin.md
##########
@@ -1136,6 +1136,33 @@ Warning: Canceling this task should be considered unsafe as it will leave the cu
 Warning: While we have been trying to reduce the inconsistency window to a maximum (by keeping track of ongoing events),
 concurrent changes done during the reIndexing might be ignored.
 
+### Subscribing a user to all of its mailboxes
+ 
+```
+curl -XPOST http://ip:port/users/{usernameToBeUsed}/mailboxes?task=subscribeAll
+```
+
+Will schedule a task for subscribing a user to all of its mailboxes.

Review comment:
       Thanks, I'm ok with these explanations, but they are clearly missing in this documentation.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[GitHub] [james-project] rouazana commented on a change in pull request #326: MAILBOX-405 Add a task to subscribe all mailboxes belonging to a user

Posted by GitBox <gi...@apache.org>.
rouazana commented on a change in pull request #326:
URL: https://github.com/apache/james-project/pull/326#discussion_r589316221



##########
File path: docs/modules/servers/pages/distributed/operate/webadmin.adoc
##########
@@ -1301,6 +1301,9 @@ Will schedule a task for subscribing a user to all of its mailboxes.
 link:#_endpoints_returning_a_task[More details about endpoints returning
 a task].
 
+Most users are unaware of what an IMAP subscription is, nor how they can manage it. If the subscription list gets out
+of sync with the mailbox list, it could result in downgraded user experience (see MAILBOX-405). This task allow

Review comment:
       ```suggestion
   of sync with the mailbox list, it could result in downgraded user experience (see MAILBOX-405). This task allows
   ```
   thanks!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[GitHub] [james-project] Arsnael commented on a change in pull request #326: MAILBOX-405 Add a task to subscribe all mailboxes belonging to a user

Posted by GitBox <gi...@apache.org>.
Arsnael commented on a change in pull request #326:
URL: https://github.com/apache/james-project/pull/326#discussion_r589891441



##########
File path: server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/SubscribeAllTask.java
##########
@@ -0,0 +1,135 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.webadmin.service;
+
+import java.time.Clock;
+import java.time.Instant;
+import java.util.Collection;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.james.core.Username;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.SubscriptionManager;
+import org.apache.james.mailbox.exception.SubscriptionException;
+import org.apache.james.mailbox.model.search.MailboxQuery;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskExecutionDetails;
+import org.apache.james.task.TaskType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.github.fge.lambdas.Throwing;
+
+public class SubscribeAllTask implements Task {
+    static final TaskType TASK_TYPE = TaskType.of("SubscribeAllTask");
+    private static final Logger LOGGER = LoggerFactory.getLogger(SubscribeAllTask.class);
+
+    public static class AdditionalInformation implements TaskExecutionDetails.AdditionalInformation {
+        private final Username username;
+        private final long subscribedCount;
+        private final long unsubscribedCount;
+        private final Instant timestamp;
+
+        public AdditionalInformation(Username username, long subscribedCount, long unsubscribedCount, Instant timestamp) {
+            this.username = username;
+            this.subscribedCount = subscribedCount;
+            this.unsubscribedCount = unsubscribedCount;
+            this.timestamp = timestamp;
+        }
+
+        public Username getUsername() {
+            return username;
+        }
+
+        public long getSubscribedCount() {
+            return subscribedCount;
+        }
+
+        public long getUnsubscribedCount() {
+            return unsubscribedCount;
+        }
+
+        @Override
+        public Instant timestamp() {
+            return timestamp;
+        }
+    }
+
+    private final MailboxManager mailboxManager;
+    private final SubscriptionManager subscriptionManager;
+    private final Username username;
+    private final AtomicLong subscribedCount;
+    private final AtomicLong unsubscribedCount;
+
+    public SubscribeAllTask(MailboxManager mailboxManager, SubscriptionManager subscriptionManager, Username username) {
+        this.mailboxManager = mailboxManager;
+        this.subscriptionManager = subscriptionManager;
+        this.username = username;
+        subscribedCount = new AtomicLong(0);
+        unsubscribedCount = new AtomicLong(0);
+    }
+
+    @Override
+    public Result run() {
+        final MailboxSession session = mailboxManager.createSystemSession(username);
+        try {
+            Collection<String> subscriptions = subscriptionManager.subscriptions(session);
+            List<String> names = mailboxManager.search(MailboxQuery.privateMailboxesBuilder(session).build(), session)
+                .map(mailbox -> mailbox.getPath().getName())
+                .collectList()
+                .block();
+
+            subscriptions.stream()
+                .filter(subscription -> !names.contains(subscription))
+                .forEach(Throwing.consumer(subscription -> {
+                    subscriptionManager.unsubscribe(session, subscription);
+                    unsubscribedCount.incrementAndGet();
+                }));
+            names.stream()
+                .filter(name -> !subscriptions.contains(name))
+                .forEach(Throwing.consumer(name -> {
+                    subscriptionManager.subscribe(session, name);
+                    subscribedCount.incrementAndGet();
+                }));
+
+        } catch (SubscriptionException e) {
+            LOGGER.error("Couldnot retrieve subscriptions for {}", username, e);

Review comment:
       ```suggestion
               LOGGER.error("Could not retrieve subscriptions for {}", username, e);
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[GitHub] [james-project] Arsnael commented on a change in pull request #326: MAILBOX-405 Add a task to subscribe all mailboxes belonging to a user

Posted by GitBox <gi...@apache.org>.
Arsnael commented on a change in pull request #326:
URL: https://github.com/apache/james-project/pull/326#discussion_r589891441



##########
File path: server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/SubscribeAllTask.java
##########
@@ -0,0 +1,135 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.webadmin.service;
+
+import java.time.Clock;
+import java.time.Instant;
+import java.util.Collection;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.james.core.Username;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.SubscriptionManager;
+import org.apache.james.mailbox.exception.SubscriptionException;
+import org.apache.james.mailbox.model.search.MailboxQuery;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskExecutionDetails;
+import org.apache.james.task.TaskType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.github.fge.lambdas.Throwing;
+
+public class SubscribeAllTask implements Task {
+    static final TaskType TASK_TYPE = TaskType.of("SubscribeAllTask");
+    private static final Logger LOGGER = LoggerFactory.getLogger(SubscribeAllTask.class);
+
+    public static class AdditionalInformation implements TaskExecutionDetails.AdditionalInformation {
+        private final Username username;
+        private final long subscribedCount;
+        private final long unsubscribedCount;
+        private final Instant timestamp;
+
+        public AdditionalInformation(Username username, long subscribedCount, long unsubscribedCount, Instant timestamp) {
+            this.username = username;
+            this.subscribedCount = subscribedCount;
+            this.unsubscribedCount = unsubscribedCount;
+            this.timestamp = timestamp;
+        }
+
+        public Username getUsername() {
+            return username;
+        }
+
+        public long getSubscribedCount() {
+            return subscribedCount;
+        }
+
+        public long getUnsubscribedCount() {
+            return unsubscribedCount;
+        }
+
+        @Override
+        public Instant timestamp() {
+            return timestamp;
+        }
+    }
+
+    private final MailboxManager mailboxManager;
+    private final SubscriptionManager subscriptionManager;
+    private final Username username;
+    private final AtomicLong subscribedCount;
+    private final AtomicLong unsubscribedCount;
+
+    public SubscribeAllTask(MailboxManager mailboxManager, SubscriptionManager subscriptionManager, Username username) {
+        this.mailboxManager = mailboxManager;
+        this.subscriptionManager = subscriptionManager;
+        this.username = username;
+        subscribedCount = new AtomicLong(0);
+        unsubscribedCount = new AtomicLong(0);
+    }
+
+    @Override
+    public Result run() {
+        final MailboxSession session = mailboxManager.createSystemSession(username);
+        try {
+            Collection<String> subscriptions = subscriptionManager.subscriptions(session);
+            List<String> names = mailboxManager.search(MailboxQuery.privateMailboxesBuilder(session).build(), session)
+                .map(mailbox -> mailbox.getPath().getName())
+                .collectList()
+                .block();
+
+            subscriptions.stream()
+                .filter(subscription -> !names.contains(subscription))
+                .forEach(Throwing.consumer(subscription -> {
+                    subscriptionManager.unsubscribe(session, subscription);
+                    unsubscribedCount.incrementAndGet();
+                }));
+            names.stream()
+                .filter(name -> !subscriptions.contains(name))
+                .forEach(Throwing.consumer(name -> {
+                    subscriptionManager.subscribe(session, name);
+                    subscribedCount.incrementAndGet();
+                }));
+
+        } catch (SubscriptionException e) {
+            LOGGER.error("Couldnot retrieve subscriptions for {}", username, e);

Review comment:
       s/Couldnot/Could not

##########
File path: src/site/markdown/server/manage-webadmin.md
##########
@@ -1145,7 +1145,10 @@ curl -XPOST http://ip:port/users/{usernameToBeUsed}/mailboxes?task=subscribeAll
 Will schedule a task for subscribing a user to all of its mailboxes.
  
 [More details about endpoints returning a task](#Endpoints_returning_a_task).
- 
+
+Most users are unaware of what an IMAP subscription is, nor how they can manage it. If the subscription list gets out
+of sync with the mailbox list, it could result in downgraded user experience (see MAILBOX-405). This task allow

Review comment:
       ```suggestion
   of sync with the mailbox list, it could result in downgraded user experience (see MAILBOX-405). This task allows
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[GitHub] [james-project] chibenwa commented on pull request #326: MAILBOX-405 Add a task to subscribe all mailboxes belonging to a user

Posted by GitBox <gi...@apache.org>.
chibenwa commented on pull request #326:
URL: https://github.com/apache/james-project/pull/326#issuecomment-796456580


   Merged


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[GitHub] [james-project] rouazana commented on a change in pull request #326: MAILBOX-405 Add a task to subscribe all mailboxes belonging to a user

Posted by GitBox <gi...@apache.org>.
rouazana commented on a change in pull request #326:
URL: https://github.com/apache/james-project/pull/326#discussion_r589260672



##########
File path: src/site/markdown/server/manage-webadmin.md
##########
@@ -1136,6 +1136,33 @@ Warning: Canceling this task should be considered unsafe as it will leave the cu
 Warning: While we have been trying to reduce the inconsistency window to a maximum (by keeping track of ongoing events),
 concurrent changes done during the reIndexing might be ignored.
 
+### Subscribing a user to all of its mailboxes
+ 
+```
+curl -XPOST http://ip:port/users/{usernameToBeUsed}/mailboxes?task=subscribeAll
+```
+
+Will schedule a task for subscribing a user to all of its mailboxes.

Review comment:
       What's the goal of this task? What happens if a user deliberately wants to not subscribe to some of her folders?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org