hungphan227 commented on code in PR #1643:
URL: https://github.com/apache/james-project/pull/1643#discussion_r1264809087
##########
server/protocols/jmap-draft/src/main/java/org/apache/james/jmap/mailet/filter/MailMatcher.java:
##########
@@ -51,27 +83,28 @@ private HeaderMatcher(ContentMatcher contentMatcher, String
ruleValue,
this.headerExtractor = headerExtractor;
}
- @Override
- public boolean match(Mail mail) {
- try {
- Stream<String> headerLines = headerExtractor.apply(mail);
- return contentMatcher.match(headerLines, ruleValue);
- } catch (Exception e) {
- LOGGER.error("error while extracting mail header", e);
- return false;
- }
+ public ContentMatcher getContentMatcher() {
+ return contentMatcher;
+ }
+
+ public String getRuleValue() {
+ return ruleValue;
+ }
+
+ public HeaderExtractor getHeaderExtractor() {
+ return headerExtractor;
}
}
static MailMatcher from(Rule rule) {
- Condition ruleCondition = rule.getCondition();
- Optional<ContentMatcher> maybeContentMatcher =
ContentMatcher.asContentMatcher(ruleCondition.getField(),
ruleCondition.getComparator());
- Optional<HeaderExtractor> maybeHeaderExtractor =
HeaderExtractor.asHeaderExtractor(ruleCondition.getField());
-
- return new HeaderMatcher(
- maybeContentMatcher.orElseThrow(() -> new RuntimeException("No
content matcher associated with field " + ruleCondition.getField())),
- rule.getCondition().getValue(),
- maybeHeaderExtractor.orElseThrow(() -> new RuntimeException("No
content matcher associated with comparator " + ruleCondition.getComparator())));
+ return new
HeaderMatcher(rule.getConditionGroup().getConditions().stream()
+ .map(ruleCondition -> new MailMatchingCondition(
+ ContentMatcher.asContentMatcher(ruleCondition.getField(),
ruleCondition.getComparator())
+ .orElseThrow(() -> new RuntimeException("No content
matcher associated with field " + ruleCondition.getField())),
+ ruleCondition.getValue(),
+ HeaderExtractor.asHeaderExtractor(ruleCondition.getField())
+ .orElseThrow(() -> new RuntimeException("No content
matcher associated with comparator " + ruleCondition.getComparator())))
+ ).collect(Collectors.toList()),
rule.getConditionGroup().getConditionCombiner());
Review Comment:
`Collectors.toList()` => `ImmutableList.toImmutableList()`
--
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]