You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by "Arsnael (via GitHub)" <gi...@apache.org> on 2025/09/19 10:00:49 UTC

[PR] Ability to run rules on folders [james-project]

Arsnael opened a new pull request, #2817:
URL: https://github.com/apache/james-project/pull/2817

   WIP, just started...


-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Webadmin route: Ability to run rules on folders for a specific user [james-project]

Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
Arsnael commented on code in PR #2817:
URL: https://github.com/apache/james-project/pull/2817#discussion_r2375178639


##########
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:
   Realizing I forgot this comment... will address sorry



-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Ability to run rules on folders [james-project]

Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
Arsnael commented on PR #2817:
URL: https://github.com/apache/james-project/pull/2817#issuecomment-3317975822

   Also what would be the response of the triage tasks? Something like:
   
   ```
   {
       "mailboxName": "Inbox",
       "username": "bob@example.org",
       "type": "RunRulesOnMailboxTask",
       "rulesOnMessagesApplySuccessfully": 10
   }
   ```
   
   more params?


-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Ability to run rules on folders [james-project]

Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Ability to run rules on folders [james-project]

Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
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)
   - 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)



-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Webadmin route: Ability to run rules on folders for a specific user [james-project]

Posted by "quantranhong1999 (via GitHub)" <gi...@apache.org>.
quantranhong1999 commented on code in PR #2817:
URL: https://github.com/apache/james-project/pull/2817#discussion_r2375304034


##########
docs/modules/servers/partials/operate/webadmin.adoc:
##########
@@ -1800,6 +1800,66 @@ the following `additionalInformation`:
 }
 ....
 
+=== Running a filtering rule on a mailbox
+
+....
+curl -XPOST http://ip:port/users/{usernameToBeUsed}/mailboxes/{mailboxName}/messages \
+-d '{
+  "id": "1",
+  "name": "rule 1",
+  "action": {
+    "appendIn": {
+      "mailboxIds": ["23"]
+    }
+  },

Review Comment:
   Likely we need to implement the "moveTo" action which relies on `mailboxName` to ease usage.
   
   cf ticket description `Action 'moveTo' based on a mailbox name (needed to trun mass treatment on several users as we cannot hard code mailboxid)`
   
   IMO this can be a part of the cluster-wide PR (that runs on mailboxes of users, for which we can not use hardcoded mailboxId).



-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Webadmin route: Ability to run rules on folders for a specific user [james-project]

Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
Arsnael commented on PR #2817:
URL: https://github.com/apache/james-project/pull/2817#issuecomment-3337129510

   Was green, rebased and cleaned up the history
   


-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Ability to run rules on folders [james-project]

Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #2817:
URL: https://github.com/apache/james-project/pull/2817#discussion_r2372398652


##########
server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java:
##########
@@ -213,4 +222,81 @@ private Stream<MailboxMetaData> listUserMailboxes(MailboxSession mailboxSession)
             .toStream();
     }
 
+    public Mono<Result> runRulesOnMailbox(Username username, MailboxName mailboxName, Rules rules, RunRulesOnMailboxTask.Context 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, mailboxSession, context))))
+            .onErrorResume(e -> {
+                LOGGER.error("Error when applying rules to mailbox. Mailbox {} for user {}", mailboxName.asString(), username, e);
+                context.incrementFails();
+                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, MailboxSession mailboxSession, RunRulesOnMailboxTask.Context context) throws MailboxException {
+        return Flux.fromStream(ruleMatcher.findApplicableRules(messageResult))
+            .map(Rule::getAction)
+            .concatMap(action -> applyActionOnMessage(messageResult, action, mailboxSession, context));
+    }
+
+    private Mono<Result> applyActionOnMessage(MessageResult messageResult, Rule.Action action, MailboxSession mailboxSession, RunRulesOnMailboxTask.Context context) {
+        actionOnMessagePreconditions(action);
+        return appendInMailboxes(messageResult, action, mailboxSession, context);
+    }
+
+    private void actionOnMessagePreconditions(Rule.Action action) { // TODO move up to the task route?
+        if (action.isMarkAsSeen() || action.isMarkAsImportant() || action.isReject()
+            || action.getForward().isPresent() || !action.getWithKeywords().isEmpty()) {
+            throw new NotImplementedException("Only action on moving messages is supported for now");
+        }
+
+        if (action.getAppendInMailboxes().getMailboxIds().isEmpty()) {
+            throw new IllegalArgumentException("Move action should not be empty");
+        }
+    }
+
+    private Mono<Result> appendInMailboxes(MessageResult messageResult, Rule.Action action, MailboxSession mailboxSession, RunRulesOnMailboxTask.Context context) {
+        ImmutableList<String> mailboxIds = action.getAppendInMailboxes().getMailboxIds();
+
+        if (mailboxIds.isEmpty()) {
+            return Mono.just(Result.COMPLETED);
+        }
+
+        if (mailboxIds.contains(messageResult.getMailboxId().serialize())) {
+            return copyInMailboxes(messageResult.getUid(), messageResult.getMailboxId(), mailboxIds, mailboxSession, context);
+        } else {
+            return moveInMailboxes(messageResult, mailboxIds, mailboxSession, context);
+        }

Review Comment:
   We can rely on `MessageIdManager::setInMailboxesReactive` which better matches the "mailbox list" semantic?
   
   Being more atomic it's likely to be less of a mess in case of failure.



-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Webadmin route: Ability to run rules on folders for a specific user [james-project]

Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #2817:
URL: https://github.com/apache/james-project/pull/2817#discussion_r2376081883


##########
server/protocols/jmap-rfc-8621/src/main/java/org/apache/james/jmap/mailet/filter/FilteringHeaders.java:
##########
@@ -0,0 +1,94 @@
+/****************************************************************
+ * 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.jmap.mailet.filter;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import jakarta.mail.MessagingException;
+
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.Header;
+import org.apache.james.mailbox.model.Headers;
+import org.apache.james.mailbox.model.MessageResult;
+import org.apache.mailet.Mail;
+
+public interface FilteringHeaders {
+    class MailFilteringHeaders implements FilteringHeaders {
+        private final Mail mail;
+
+        public MailFilteringHeaders(Mail mail) {
+            this.mail = mail;
+        }
+
+

Review Comment:
   ```suggestion
           }
   
   ```



-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Ability to run rules on folders [james-project]

Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
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)
   - reject
   - forwards
   
   Setting flags and moving mails around in other mailboxes I think we need to do.
   
   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)



-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Webadmin route: Ability to run rules on folders for a specific user [james-project]

Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #2817:
URL: https://github.com/apache/james-project/pull/2817#discussion_r2376110192


##########
server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java:
##########
@@ -213,4 +226,63 @@ private Stream<MailboxMetaData> listUserMailboxes(MailboxSession mailboxSession)
             .toStream();
     }
 
+    public Mono<Result> runRulesOnMailbox(Username username, MailboxName mailboxName, Rules rules, RunRulesOnMailboxTask.Context 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, mailboxSession, context))))

Review Comment:
   IMO that's maybe a bit harsh
   
   We could `flatmap` + `LOW_CONCURRENCY` ?



-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Webadmin route: Ability to run rules on folders for a specific user [james-project]

Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #2817:
URL: https://github.com/apache/james-project/pull/2817#discussion_r2376066035


##########
docs/modules/servers/partials/operate/webadmin.adoc:
##########
@@ -1800,6 +1800,66 @@ the following `additionalInformation`:
 }
 ....
 
+=== Running a filtering rule on a mailbox
+
+....
+curl -XPOST http://ip:port/users/{usernameToBeUsed}/mailboxes/{mailboxName}/messages \
+-d '{
+  "id": "1",
+  "name": "rule 1",
+  "action": {
+    "appendIn": {
+      "mailboxIds": ["23"]
+    }
+  },

Review Comment:
   > Likely we need to implement the "moveTo" action which relies on mailboxName to ease usage.
   
   Yes but as a follow up PR please.



-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Webadmin route: Ability to run rules on folders for a specific user [james-project]

Posted by "quantranhong1999 (via GitHub)" <gi...@apache.org>.
quantranhong1999 commented on PR #2817:
URL: https://github.com/apache/james-project/pull/2817#issuecomment-3336634791

   `org.apache.james.webadmin.integration.memory.MemoryWebAdminServerIntegrationTest.jmapUserTasksShouldBeExposed` related?


-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Webadmin route: Ability to run rules on folders for a specific user [james-project]

Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
Arsnael commented on PR #2817:
URL: https://github.com/apache/james-project/pull/2817#issuecomment-3333044056

   IntelliJ drove me insane in the middle of moving classes... but eventually got it! Potentially maybe still some mess I missed, dont hesitate to comment


-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Ability to run rules on folders [james-project]

Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on PR #2817:
URL: https://github.com/apache/james-project/pull/2817#issuecomment-3318075841

   > Also what would be the response of the triage tasks? Something like:
   
   IMO it would need to be a task.
   
   Yes the proposal could be a good begining.


-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Ability to run rules on folders [james-project]

Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #2817:
URL: https://github.com/apache/james-project/pull/2817#discussion_r2372398652


##########
server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java:
##########
@@ -213,4 +222,81 @@ private Stream<MailboxMetaData> listUserMailboxes(MailboxSession mailboxSession)
             .toStream();
     }
 
+    public Mono<Result> runRulesOnMailbox(Username username, MailboxName mailboxName, Rules rules, RunRulesOnMailboxTask.Context 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, mailboxSession, context))))
+            .onErrorResume(e -> {
+                LOGGER.error("Error when applying rules to mailbox. Mailbox {} for user {}", mailboxName.asString(), username, e);
+                context.incrementFails();
+                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, MailboxSession mailboxSession, RunRulesOnMailboxTask.Context context) throws MailboxException {
+        return Flux.fromStream(ruleMatcher.findApplicableRules(messageResult))
+            .map(Rule::getAction)
+            .concatMap(action -> applyActionOnMessage(messageResult, action, mailboxSession, context));
+    }
+
+    private Mono<Result> applyActionOnMessage(MessageResult messageResult, Rule.Action action, MailboxSession mailboxSession, RunRulesOnMailboxTask.Context context) {
+        actionOnMessagePreconditions(action);
+        return appendInMailboxes(messageResult, action, mailboxSession, context);
+    }
+
+    private void actionOnMessagePreconditions(Rule.Action action) { // TODO move up to the task route?
+        if (action.isMarkAsSeen() || action.isMarkAsImportant() || action.isReject()
+            || action.getForward().isPresent() || !action.getWithKeywords().isEmpty()) {
+            throw new NotImplementedException("Only action on moving messages is supported for now");
+        }
+
+        if (action.getAppendInMailboxes().getMailboxIds().isEmpty()) {
+            throw new IllegalArgumentException("Move action should not be empty");
+        }
+    }
+
+    private Mono<Result> appendInMailboxes(MessageResult messageResult, Rule.Action action, MailboxSession mailboxSession, RunRulesOnMailboxTask.Context context) {
+        ImmutableList<String> mailboxIds = action.getAppendInMailboxes().getMailboxIds();
+
+        if (mailboxIds.isEmpty()) {
+            return Mono.just(Result.COMPLETED);
+        }
+
+        if (mailboxIds.contains(messageResult.getMailboxId().serialize())) {
+            return copyInMailboxes(messageResult.getUid(), messageResult.getMailboxId(), mailboxIds, mailboxSession, context);
+        } else {
+            return moveInMailboxes(messageResult, mailboxIds, mailboxSession, context);
+        }

Review Comment:
   We can rely on `MessageIdManager::setInMailboxesReactive` which better matches the "mailbox list" semantic. 



-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Webadmin route: Ability to run rules on folders for a specific user [james-project]

Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #2817:
URL: https://github.com/apache/james-project/pull/2817#discussion_r2376080714


##########
server/protocols/jmap-rfc-8621/src/main/java/org/apache/james/jmap/mailet/filter/FilteringHeaders.java:
##########
@@ -0,0 +1,94 @@
+/****************************************************************
+ * 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.jmap.mailet.filter;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import jakarta.mail.MessagingException;
+
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.Header;
+import org.apache.james.mailbox.model.Headers;
+import org.apache.james.mailbox.model.MessageResult;
+import org.apache.mailet.Mail;
+
+public interface FilteringHeaders {
+    class MailFilteringHeaders implements FilteringHeaders {
+        private final Mail mail;
+
+        public MailFilteringHeaders(Mail mail) {
+            this.mail = mail;
+        }
+
+
+        @Override
+        public String[] getHeader(String name) throws MessagingException {
+            return mail.getMessage().getHeader(name);
+        }
+
+        @Override
+        public String getSubject() throws MessagingException {
+            return mail.getMessage().getSubject();
+        }
+    }
+
+    class MessageResultFilteringHeaders implements FilteringHeaders {
+        private final Headers headers;
+
+        public MessageResultFilteringHeaders(MessageResult messageResult) throws MailboxException {
+            this.headers = messageResult.getHeaders();
+        }
+
+        @Override
+        public String[] getHeader(String name) throws MailboxException {
+            return getMatchingHeaders(name);
+        }
+
+        @Override
+        public String getSubject() throws MailboxException {
+            return Arrays.stream(getMatchingHeaders("Subject"))
+                .findFirst()
+                .orElse(null);
+
+        }

Review Comment:
   ```suggestion
                   .orElse(null);
           }
   ```



-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Ability to run rules on folders [james-project]

Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on PR #2817:
URL: https://github.com/apache/james-project/pull/2817#issuecomment-3315530503

   I gave a little try to this and quite like how abstractions are put together.
   
   I agree continuing building over this rule engine the Webadmin endpoints.
   
   Thanks for the thoughts put into this.


-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Webadmin route: Ability to run rules on folders for a specific user [james-project]

Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
Arsnael commented on PR #2817:
URL: https://github.com/apache/james-project/pull/2817#issuecomment-3327444674

   I will clean up the commit history later, to let the reviewers still having the follow up.
   
   More or less ok to review I think for the webadmin route for rule on mailbox for a user. I think I will do an other PR based on this for the same but cluster wise


-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Webadmin route: Ability to run rules on folders for a specific user [james-project]

Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
Arsnael commented on PR #2817:
URL: https://github.com/apache/james-project/pull/2817#issuecomment-3331601161

   Appreciate the quick fixes :)


-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Ability to run rules on folders [james-project]

Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on code in PR #2817:
URL: https://github.com/apache/james-project/pull/2817#discussion_r2372398652


##########
server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java:
##########
@@ -213,4 +222,81 @@ private Stream<MailboxMetaData> listUserMailboxes(MailboxSession mailboxSession)
             .toStream();
     }
 
+    public Mono<Result> runRulesOnMailbox(Username username, MailboxName mailboxName, Rules rules, RunRulesOnMailboxTask.Context 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, mailboxSession, context))))
+            .onErrorResume(e -> {
+                LOGGER.error("Error when applying rules to mailbox. Mailbox {} for user {}", mailboxName.asString(), username, e);
+                context.incrementFails();
+                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, MailboxSession mailboxSession, RunRulesOnMailboxTask.Context context) throws MailboxException {
+        return Flux.fromStream(ruleMatcher.findApplicableRules(messageResult))
+            .map(Rule::getAction)
+            .concatMap(action -> applyActionOnMessage(messageResult, action, mailboxSession, context));
+    }
+
+    private Mono<Result> applyActionOnMessage(MessageResult messageResult, Rule.Action action, MailboxSession mailboxSession, RunRulesOnMailboxTask.Context context) {
+        actionOnMessagePreconditions(action);
+        return appendInMailboxes(messageResult, action, mailboxSession, context);
+    }
+
+    private void actionOnMessagePreconditions(Rule.Action action) { // TODO move up to the task route?
+        if (action.isMarkAsSeen() || action.isMarkAsImportant() || action.isReject()
+            || action.getForward().isPresent() || !action.getWithKeywords().isEmpty()) {
+            throw new NotImplementedException("Only action on moving messages is supported for now");
+        }
+
+        if (action.getAppendInMailboxes().getMailboxIds().isEmpty()) {
+            throw new IllegalArgumentException("Move action should not be empty");
+        }
+    }
+
+    private Mono<Result> appendInMailboxes(MessageResult messageResult, Rule.Action action, MailboxSession mailboxSession, RunRulesOnMailboxTask.Context context) {
+        ImmutableList<String> mailboxIds = action.getAppendInMailboxes().getMailboxIds();
+
+        if (mailboxIds.isEmpty()) {
+            return Mono.just(Result.COMPLETED);
+        }
+
+        if (mailboxIds.contains(messageResult.getMailboxId().serialize())) {
+            return copyInMailboxes(messageResult.getUid(), messageResult.getMailboxId(), mailboxIds, mailboxSession, context);
+        } else {
+            return moveInMailboxes(messageResult, mailboxIds, mailboxSession, context);
+        }

Review Comment:
   We can rely on `MessageIdManager::setInMailboxesReactive` which better matches the "mailbox list" semantic?



-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Webadmin route: Ability to run rules on folders for a specific user [james-project]

Posted by "quantranhong1999 (via GitHub)" <gi...@apache.org>.
quantranhong1999 commented on PR #2817:
URL: https://github.com/apache/james-project/pull/2817#issuecomment-3327573097

   [ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.6.0:check (check-style) on project james-server-guice-webadmin-mailbox: You have 1 Checkstyle violation. -> [Help 1]


-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Webadmin route: Ability to run rules on folders for a specific user [james-project]

Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa merged PR #2817:
URL: https://github.com/apache/james-project/pull/2817


-- 
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: notifications-unsubscribe@james.apache.org

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


Re: [PR] Ability to run rules on folders [james-project]

Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
Arsnael commented on code in PR #2817:
URL: https://github.com/apache/james-project/pull/2817#discussion_r2373850277


##########
server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java:
##########
@@ -213,4 +222,81 @@ private Stream<MailboxMetaData> listUserMailboxes(MailboxSession mailboxSession)
             .toStream();
     }
 
+    public Mono<Result> runRulesOnMailbox(Username username, MailboxName mailboxName, Rules rules, RunRulesOnMailboxTask.Context 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, mailboxSession, context))))
+            .onErrorResume(e -> {
+                LOGGER.error("Error when applying rules to mailbox. Mailbox {} for user {}", mailboxName.asString(), username, e);
+                context.incrementFails();
+                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, MailboxSession mailboxSession, RunRulesOnMailboxTask.Context context) throws MailboxException {
+        return Flux.fromStream(ruleMatcher.findApplicableRules(messageResult))
+            .map(Rule::getAction)
+            .concatMap(action -> applyActionOnMessage(messageResult, action, mailboxSession, context));
+    }
+
+    private Mono<Result> applyActionOnMessage(MessageResult messageResult, Rule.Action action, MailboxSession mailboxSession, RunRulesOnMailboxTask.Context context) {
+        actionOnMessagePreconditions(action);
+        return appendInMailboxes(messageResult, action, mailboxSession, context);
+    }
+
+    private void actionOnMessagePreconditions(Rule.Action action) { // TODO move up to the task route?
+        if (action.isMarkAsSeen() || action.isMarkAsImportant() || action.isReject()
+            || action.getForward().isPresent() || !action.getWithKeywords().isEmpty()) {
+            throw new NotImplementedException("Only action on moving messages is supported for now");
+        }
+
+        if (action.getAppendInMailboxes().getMailboxIds().isEmpty()) {
+            throw new IllegalArgumentException("Move action should not be empty");
+        }
+    }
+
+    private Mono<Result> appendInMailboxes(MessageResult messageResult, Rule.Action action, MailboxSession mailboxSession, RunRulesOnMailboxTask.Context context) {
+        ImmutableList<String> mailboxIds = action.getAppendInMailboxes().getMailboxIds();
+
+        if (mailboxIds.isEmpty()) {
+            return Mono.just(Result.COMPLETED);
+        }
+
+        if (mailboxIds.contains(messageResult.getMailboxId().serialize())) {
+            return copyInMailboxes(messageResult.getUid(), messageResult.getMailboxId(), mailboxIds, mailboxSession, context);
+        } else {
+            return moveInMailboxes(messageResult, mailboxIds, mailboxSession, context);
+        }

Review Comment:
   Completely missed and forgot about that method... would defo make the logic easier, 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.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

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


Re: [PR] Ability to run rules on folders [james-project]

Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@james.apache.org

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