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


##########
server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java:
##########
@@ -213,4 +221,50 @@ private Stream<MailboxMetaData> 
listUserMailboxes(MailboxSession mailboxSession)
             .toStream();
     }
 
+    public Mono<Result> runRulesOnMailbox(Username username, MailboxName 
mailboxName, Rules rules) { // TODO add a task context
+        MailboxSession mailboxSession = 
mailboxManager.createSystemSession(username);
+        RuleMatcher ruleMatcher = new RuleMatcher(rules.getRules());
+
+        return 
Mono.from(mailboxManager.getMailboxReactive(MailboxPath.forUser(username, 
mailboxName.asString()), mailboxSession))
+            .flatMapMany(messageManager -> 
Flux.from(messageManager.getMessagesReactive(MessageRange.all(), 
FetchGroup.HEADERS, mailboxSession))
+                .concatMap(Throwing.function(messageResult -> 
runRulesOnMessage(ruleMatcher, messageResult))))
+            .onErrorResume(e -> {
+                LOGGER.error("Error when applying rules to mailbox. Mailbox {} 
for user {}", mailboxName.asString(), username, e);
+                return Mono.just(Result.PARTIAL);
+            })
+            .reduce(Task::combine)
+            .switchIfEmpty(Mono.just(Result.COMPLETED))
+            .doFinally(any -> 
mailboxManager.endProcessingRequest(mailboxSession));
+    }
+
+    private Flux<Result> runRulesOnMessage(RuleMatcher ruleMatcher, 
MessageResult messageResult) throws MailboxException {
+        return Flux.fromStream(ruleMatcher.findApplicableRules(messageResult))
+            .map(Rule::getAction)
+            .concatMap(action -> applyActionOnMessage(messageResult, action));
+    }
+
+    private Mono<Result> applyActionOnMessage(MessageResult messageResult, 
Rule.Action action) {
+        return Mono.just(Result.COMPLETED); //TODO apply actions

Review Comment:
   Current actions with JMAPFiltering mailet:
   - appendInMailboxes
   - set flags (seen / important)
   - keywords
   - reject
   - forwards
   
   Setting flags and moving mails around in other mailboxes I think makes sense.
   
   I don't think we treat reject, it does not make sense I think here? If we 
want to trash mails we just move them to the trash mailbox?
   What about forwards? I don't think it has its place here too? (but less sure 
on this point so let me know wdyt)
   And I guess we do keywords too?



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