This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit ce6297a98f460259f041e180b06c90b1a6d9ab36
Author: Quan Tran <hqt...@linagora.com>
AuthorDate: Fri Nov 8 11:24:14 2024 +0700

    JAMES-4087 Allow chaining composite matcher
    
    ```
    <matcher name="relay-allowed" 
match="org.apache.james.mailetcontainer.impl.matchers.Or">
        <matcher match="SMTPAuthSuccessful"/>
        <matcher match="SMTPIsAuthNetwork"/>
        <matcher match="SentByMailet"/>
        <matcher match="org.apache.james.jmap.mailet.SentByJmap"/>
    </matcher>
    <matcher name="should-check-spam" 
match="org.apache.james.mailetcontainer.impl.matchers.Not">
        <matcher match="relay-allowed"/>
    </matcher>
    ```
    was not possible before.
    
    Loading the matcher from composite matchers collection also, not only using 
class loader solves the issue.
---
 .../src/test/resources/mailetcontainer.xml         |  9 +++++++++
 .../lib/AbstractStateMailetProcessor.java          | 22 ++++++++++++++--------
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/server/apps/memory-app/src/test/resources/mailetcontainer.xml 
b/server/apps/memory-app/src/test/resources/mailetcontainer.xml
index 7784d05997..dd129e44f6 100644
--- a/server/apps/memory-app/src/test/resources/mailetcontainer.xml
+++ b/server/apps/memory-app/src/test/resources/mailetcontainer.xml
@@ -54,6 +54,15 @@
 
 
         <processor state="transport" enableJmx="false">
+            <matcher name="relay-allowed" 
match="org.apache.james.mailetcontainer.impl.matchers.Or">
+                <matcher match="SMTPAuthSuccessful"/>
+                <matcher match="SMTPIsAuthNetwork"/>
+                <matcher match="SentByMailet"/>
+                <matcher match="org.apache.james.jmap.mailet.SentByJmap"/>
+            </matcher>
+            <matcher name="chaining-matcher" 
match="org.apache.james.mailetcontainer.impl.matchers.Not">
+                <matcher match="relay-allowed"/>
+            </matcher>
             <mailet match="SMTPAuthSuccessful" class="SetMimeHeader">
                 <name>X-UserIsAuth</name>
                 <value>true</value>
diff --git 
a/server/mailet/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java
 
b/server/mailet/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java
index 7305e716f0..6dd4b7ae26 100644
--- 
a/server/mailet/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java
+++ 
b/server/mailet/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/lib/AbstractStateMailetProcessor.java
@@ -232,7 +232,7 @@ public abstract class AbstractStateMailetProcessor 
implements MailProcessor, Con
                 // if no matcher is configured throw an Exception
                 throw new ConfigurationException("Please configure only match 
or nomatch per mailet");
             } else if (matcherName != null) {
-                matcher = 
matcherLoader.getMatcher(createMatcherConfig(matcherName));
+                matcher = loadMatcher(compMap, matcherName);
                 if (matcher instanceof CompositeMatcher) {
                     CompositeMatcher compMatcher = (CompositeMatcher) matcher;
 
@@ -295,13 +295,7 @@ public abstract class AbstractStateMailetProcessor 
implements MailProcessor, Con
                     // if no matcher is configured throw an Exception
                     throw new ConfigurationException("Please configure only 
match or nomatch per mailet");
                 } else if (matcherName != null) {
-                    // try to load from compositeMatchers first
-                    matcher = compositeMatchers.get(matcherName);
-                    if (matcher == null) {
-                        // no composite Matcher found, try to load it via
-                        // MatcherLoader
-                        matcher = 
matcherLoader.getMatcher(createMatcherConfig(matcherName));
-                    }
+                    matcher = loadMatcher(compositeMatchers, matcherName);
                 } else if (invertedMatcherName != null) {
                     // no composite Matcher found, try to load it via 
MatcherLoader
                     matcher = 
matcherLoader.getMatcher(createMatcherConfig(invertedMatcherName));
@@ -343,6 +337,18 @@ public abstract class AbstractStateMailetProcessor 
implements MailProcessor, Con
         }
     }
 
+    private Matcher loadMatcher(Map<String, Matcher> compositeMatchers, String 
matcherName) throws MessagingException {
+        Matcher matcher;
+        // try to load from compositeMatchers first
+        matcher = compositeMatchers.get(matcherName);
+        if (matcher == null) {
+            // no composite Matcher found, try to load it via
+            // MatcherLoader
+            matcher = 
matcherLoader.getMatcher(createMatcherConfig(matcherName));
+        }
+        return matcher;
+    }
+
     /**
      * Setup the routing for the configured {@link MatcherMailetPair}'s for 
this
      * {@link ProcessorImpl}


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org
For additional commands, e-mail: notifications-h...@james.apache.org

Reply via email to