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/09 02:36:44 UTC
[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
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