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


##########
server/protocols/webadmin/webadmin-mailbox/pom.xml:
##########
@@ -141,6 +141,10 @@
             <groupId>${james.groupId}</groupId>
             <artifactId>james-server-data-api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>james-server-data-jmap</artifactId>

Review Comment:
   IMO this is not cool to add JMAP-ish dependencies in here.
   
   Can we relocate this in `webadmin-jmap`?



##########
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:
   > I don't think we treat reject, it does not make sense I think here?
   
   Yes it makes no functional sense so let's just throw a 
NotImplementedException
   
   > What about forwards?
   
   It *could* make sense but it's heavy to implement so maybe better just 
ingore it for now and throw too
   
   > And I guess we do keywords too?
   
   IMO yes ;-)
   
   We need however to think about a set/unset/reset semantic. In the local 
delivery pipeline only the set semantic make sense.  Here we could have 
potentially both...
   
   I do not have the spec in mind. Let's focus on getting the "rules running on 
folder" here. Let's keep the chageset minimal so let's just implement `move` 
for now. We will specify other actions afterward.



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