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


##########
server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/mailet/filter/MailMatcher.java:
##########
@@ -30,18 +33,51 @@
 import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Preconditions;
+import com.google.common.base.Predicate;
 
 public interface MailMatcher {
 
     class HeaderMatcher implements MailMatcher {
 
         private static final Logger LOGGER = 
LoggerFactory.getLogger(HeaderMatcher.class);
 
+        private List<MailMatchingCondition> mailMatchingConditions;
+        private final Rule.ConditionCombiner conditionCombiner;
+
+        private HeaderMatcher(List<MailMatchingCondition> 
mailMatchingConditions, Rule.ConditionCombiner conditionCombiner) {
+            this.mailMatchingConditions = mailMatchingConditions;
+            this.conditionCombiner = conditionCombiner;
+        }
+
+        @Override
+        public boolean match(Mail mail) {
+            try {
+                Predicate<MailMatchingCondition> predicate = 
(MailMatchingCondition mailMatchingCondition) -> {
+                    Stream<String> headerLines = 
mailMatchingCondition.getHeaderExtractor().apply(mail);
+                    return 
mailMatchingCondition.getContentMatcher().match(headerLines, 
mailMatchingCondition.getRuleValue());
+                };
+
+                switch (conditionCombiner) {
+                    case AND:
+                        return 
mailMatchingConditions.stream().allMatch(predicate);
+                    case OR:
+                        return 
mailMatchingConditions.stream().anyMatch(predicate);
+                    default:
+                        return false;

Review Comment:
   Explicitly throw on unmanaged cases?



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