Arsnael commented on code in PR #2824:
URL: https://github.com/apache/james-project/pull/2824#discussion_r2397783766


##########
server/protocols/webadmin/webadmin-jmap/src/main/java/org/apache/james/webadmin/data/jmap/RunRulesOnMailboxRoutes.java:
##########
@@ -137,6 +152,48 @@ public Task runRulesOnMailbox(Request request) throws 
UsersRepositoryException,
         }
     }
 
+    public List<UserTaskResponse> runRulesOnAllUsersMailbox(Request request, 
Response response) {
+        try {
+            actionPrecondition(request);
+            MailboxName mailboxName = getMailboxNameQueryParam(request);
+            RuleDTO ruleDTO = jsonDeserialize.readValue(request.body(), 
RuleDTO.class);
+            Rules rules = new 
Rules(RuleDTO.toRules(ImmutableList.of(ruleDTO)), Version.INITIAL);
+            rulesPrecondition(rules);
+
+            response.status(HttpStatus.CREATED_201);
+            return runRulesOnAllUsersMailbox(mailboxName, rules);
+        } catch (IllegalStateException e) {
+            LOGGER.info("Invalid argument on /messages", e);
+            throw ErrorResponder.builder()
+                .statusCode(HttpStatus.NOT_FOUND_404)
+                .type(ErrorResponder.ErrorType.NOT_FOUND)
+                .message("Invalid argument on /messages")
+                .cause(e)
+                .haltError();
+        } catch (JsonProcessingException e) {
+            throw ErrorResponder.builder()
+                .statusCode(HttpStatus.BAD_REQUEST_400)
+                .type(ErrorResponder.ErrorType.INVALID_ARGUMENT)
+                .message("JSON payload of the request is not valid")
+                .cause(e)
+                .haltError();
+        }
+    }
+
+    private List<UserTaskResponse> runRulesOnAllUsersMailbox(MailboxName 
mailboxName, Rules rules) {
+        return Flux.from(usersRepository.listReactive())
+            .filter(Throwing.predicate( username -> 
mailboxForUserExists(username, mailboxName)))

Review Comment:
   No it's for mailboxName query param, which is the original mailbox on which 
to apply the filtering rule. If mailbox does not exist, no message, no 
filtering. It's not the destination mailbox here :)



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to