You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/06/19 09:53:47 UTC
[1/8] james-project git commit: JAMES-2429 Simplify mailet
configuration with guice
Repository: james-project
Updated Branches:
refs/heads/master c0ea1007f -> 23d22a0e9
JAMES-2429 Simplify mailet configuration with guice
One should be able to omit the default package from a path.
This would allow us to better structure mailets without paying the cost of
FQDN in our configuration.
For instance we can write `<mailet match="dlp.DLP" class="...">` instead of being
forced to write `<mailet match="org.apache.james.transport.matchers.dlp.DLP" class="...">`
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/19caa770
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/19caa770
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/19caa770
Branch: refs/heads/master
Commit: 19caa770da809b386700c2739857f62f6eb66be5
Parents: 9cc86fe
Author: benwa <bt...@linagora.com>
Authored: Thu Jun 14 12:48:08 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Tue Jun 19 16:52:40 2018 +0700
----------------------------------------------------------------------
.../apache/james/utils/GuiceGenericLoader.java | 23 +++++++++++++----
.../james/transport/mailets/sub/TestMailet.java | 25 +++++++++++++++++++
.../transport/matchers/sub/TestMatcher.java | 26 ++++++++++++++++++++
.../james/utils/GuiceMailetLoaderTest.java | 14 +++++++++++
.../james/utils/GuiceMatcherLoaderTest.java | 13 ++++++++++
5 files changed, 96 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/19caa770/server/container/guice/mailet/src/main/java/org/apache/james/utils/GuiceGenericLoader.java
----------------------------------------------------------------------
diff --git a/server/container/guice/mailet/src/main/java/org/apache/james/utils/GuiceGenericLoader.java b/server/container/guice/mailet/src/main/java/org/apache/james/utils/GuiceGenericLoader.java
index a3f8130..cdd6d41 100644
--- a/server/container/guice/mailet/src/main/java/org/apache/james/utils/GuiceGenericLoader.java
+++ b/server/container/guice/mailet/src/main/java/org/apache/james/utils/GuiceGenericLoader.java
@@ -19,6 +19,10 @@
package org.apache.james.utils;
+import java.util.Optional;
+
+import org.apache.james.util.OptionalUtils;
+
import com.google.inject.Injector;
public class GuiceGenericLoader<T> {
@@ -34,15 +38,24 @@ public class GuiceGenericLoader<T> {
public T instanciate(String className) throws Exception {
- Class<T> clazz = extendedClassLoader.locateClass(constructFullName(className));
+ Class<T> clazz = locateClass(className);
return injector.getInstance(clazz);
}
- private String constructFullName(String name) {
- if (! name.contains(".")) {
- return defaultPackageName + name;
+ private Class<T> locateClass(String className) throws ClassNotFoundException {
+ return OptionalUtils.orSuppliers(
+ () -> tryLocateClass(className),
+ () -> tryLocateClass(defaultPackageName + className),
+ () -> tryLocateClass(defaultPackageName + "." + className))
+ .orElseThrow(() -> new ClassNotFoundException(className));
+ }
+
+ private Optional<Class<T>> tryLocateClass(String className) {
+ try {
+ return Optional.of(extendedClassLoader.locateClass(className));
+ } catch (ClassNotFoundException e) {
+ return Optional.empty();
}
- return name;
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/19caa770/server/container/guice/mailet/src/test/java/org/apache/james/transport/mailets/sub/TestMailet.java
----------------------------------------------------------------------
diff --git a/server/container/guice/mailet/src/test/java/org/apache/james/transport/mailets/sub/TestMailet.java b/server/container/guice/mailet/src/test/java/org/apache/james/transport/mailets/sub/TestMailet.java
new file mode 100644
index 0000000..1c9a98d
--- /dev/null
+++ b/server/container/guice/mailet/src/test/java/org/apache/james/transport/mailets/sub/TestMailet.java
@@ -0,0 +1,25 @@
+/****************************************************************
+ * 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.transport.mailets.sub;
+
+import org.apache.james.transport.mailets.Null;
+
+public class TestMailet extends Null {
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/19caa770/server/container/guice/mailet/src/test/java/org/apache/james/transport/matchers/sub/TestMatcher.java
----------------------------------------------------------------------
diff --git a/server/container/guice/mailet/src/test/java/org/apache/james/transport/matchers/sub/TestMatcher.java b/server/container/guice/mailet/src/test/java/org/apache/james/transport/matchers/sub/TestMatcher.java
new file mode 100644
index 0000000..c6b3b41
--- /dev/null
+++ b/server/container/guice/mailet/src/test/java/org/apache/james/transport/matchers/sub/TestMatcher.java
@@ -0,0 +1,26 @@
+/****************************************************************
+ * 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.transport.matchers.sub;
+
+import org.apache.james.transport.matchers.All;
+
+public class TestMatcher extends All {
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/19caa770/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java b/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java
index 446af81..0bafffd 100644
--- a/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java
+++ b/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMailetLoaderTest.java
@@ -27,6 +27,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import javax.mail.MessagingException;
import org.apache.james.transport.mailets.AddFooter;
+import org.apache.james.transport.mailets.sub.TestMailet;
import org.apache.mailet.Mailet;
import org.apache.mailet.base.test.FakeMailContext;
import org.apache.mailet.base.test.FakeMailetConfig;
@@ -57,6 +58,19 @@ public class GuiceMailetLoaderTest {
}
@Test
+ public void getMailetShouldLoadClassWhenInSubPackageFromDefaultPackage() throws Exception {
+ GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector,
+ new ExtendedClassLoader(THROWING_FILE_SYSTEM));
+
+ Mailet mailet = guiceMailetLoader.getMailet(FakeMailetConfig.builder()
+ .mailetName("sub.TestMailet")
+ .mailetContext(FakeMailContext.defaultContext())
+ .build());
+
+ assertThat(mailet).isInstanceOf(TestMailet.class);
+ }
+
+ @Test
public void getMailetShouldThrowOnBadType() throws Exception {
GuiceMailetLoader guiceMailetLoader = new GuiceMailetLoader(injector,
new ExtendedClassLoader(THROWING_FILE_SYSTEM));
http://git-wip-us.apache.org/repos/asf/james-project/blob/19caa770/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMatcherLoaderTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMatcherLoaderTest.java b/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMatcherLoaderTest.java
index b1c69cb..01e709b 100644
--- a/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMatcherLoaderTest.java
+++ b/server/container/guice/mailet/src/test/java/org/apache/james/utils/GuiceMatcherLoaderTest.java
@@ -57,6 +57,19 @@ public class GuiceMatcherLoaderTest {
}
@Test
+ public void getMatcherShouldLoadClassWhenInSubPackageFromDefaultPackage() throws Exception {
+ GuiceMatcherLoader guiceMailetLoader = new GuiceMatcherLoader(injector,
+ new ExtendedClassLoader(THROWING_FILE_SYSTEM));
+
+ Matcher matcher = guiceMailetLoader.getMatcher(FakeMatcherConfig.builder()
+ .matcherName("sub.TestMatcher")
+ .mailetContext(FakeMailContext.defaultContext())
+ .build());
+
+ assertThat(matcher).isInstanceOf(All.class);
+ }
+
+ @Test
public void getMatcherShouldThrowOnBadType() throws Exception {
GuiceMatcherLoader guiceMatcherLoader = new GuiceMatcherLoader(injector,
new ExtendedClassLoader(THROWING_FILE_SYSTEM));
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[4/8] james-project git commit: JAMES-2429 MimeMessageBuilder should
support embedded messages
Posted by bt...@apache.org.
JAMES-2429 MimeMessageBuilder should support embedded messages
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/9cc86feb
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/9cc86feb
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/9cc86feb
Branch: refs/heads/master
Commit: 9cc86feb7b16e12c5e76c7b0337b8b2f33e26972
Parents: c04fd75
Author: benwa <bt...@linagora.com>
Authored: Thu Jun 14 11:50:42 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Tue Jun 19 16:52:40 2018 +0700
----------------------------------------------------------------------
core/pom.xml | 11 +++++++++++
.../james/core/builder/MimeMessageBuilder.java | 11 +++++++++++
.../core/builder/MimeMessageBuilderTest.java | 20 ++++++++++++++++++++
3 files changed, 42 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/9cc86feb/core/pom.xml
----------------------------------------------------------------------
diff --git a/core/pom.xml b/core/pom.xml
index 3d70436..d096b67 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -35,6 +35,17 @@
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
+ <artifactId>javax-mail-extension</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>javax-mail-extension</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
<artifactId>james-server-util-java8</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/9cc86feb/core/src/main/java/org/apache/james/core/builder/MimeMessageBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/james/core/builder/MimeMessageBuilder.java b/core/src/main/java/org/apache/james/core/builder/MimeMessageBuilder.java
index 5a33892..254f17b 100644
--- a/core/src/main/java/org/apache/james/core/builder/MimeMessageBuilder.java
+++ b/core/src/main/java/org/apache/james/core/builder/MimeMessageBuilder.java
@@ -98,6 +98,17 @@ public class MimeMessageBuilder {
return this;
}
+ public MultipartBuilder addBody(MimeMessageBuilder builder) throws IOException, MessagingException {
+ return addBody(builder.build());
+ }
+
+ public MultipartBuilder addBody(MimeMessage mimeMessage) throws IOException, MessagingException {
+ MimeBodyPart mimeBodyPart = new MimeBodyPart();
+ mimeBodyPart.setContent(mimeMessage, "message/rfc822");
+ this.bodyParts.add(mimeBodyPart);
+ return this;
+ }
+
public MultipartBuilder addBodies(BodyPart... bodyParts) {
this.bodyParts.addAll(Arrays.asList(bodyParts));
return this;
http://git-wip-us.apache.org/repos/asf/james-project/blob/9cc86feb/core/src/test/java/org/apache/james/core/builder/MimeMessageBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/james/core/builder/MimeMessageBuilderTest.java b/core/src/test/java/org/apache/james/core/builder/MimeMessageBuilderTest.java
index 3b401a5..62b8c56 100644
--- a/core/src/test/java/org/apache/james/core/builder/MimeMessageBuilderTest.java
+++ b/core/src/test/java/org/apache/james/core/builder/MimeMessageBuilderTest.java
@@ -23,6 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import javax.mail.internet.MimeMessage;
+import org.apache.james.util.MimeMessageUtil;
import org.junit.Test;
public class MimeMessageBuilderTest {
@@ -62,6 +63,24 @@ public class MimeMessageBuilderTest {
}
@Test
+ public void embeddedMessagesShouldBeSupported() throws Exception {
+ MimeMessage embeddedMimeMessage = MimeMessageBuilder.mimeMessageBuilder()
+ .setSubject("A unicorn eat popcorn")
+ .setText("As studies demonstrated unicorns eats cereals.")
+ .build();
+ MimeMessage mimeMessage = MimeMessageBuilder.mimeMessageBuilder()
+ .setSubject("Internet is a strange place")
+ .setContent(MimeMessageBuilder.multipartBuilder()
+ .addBody(MimeMessageBuilder.bodyPartBuilder()
+ .data("The following embedded message is sooo funny!"))
+ .addBody(embeddedMimeMessage))
+ .build();
+
+ assertThat(MimeMessageUtil.asString(mimeMessage))
+ .contains(MimeMessageUtil.asString(embeddedMimeMessage));
+ }
+
+ @Test
public void buildShouldAllowToSpecifyMultipartSubtype() throws Exception {
MimeMessage mimeMessage = MimeMessageBuilder.mimeMessageBuilder()
.setContent(MimeMessageBuilder.multipartBuilder()
@@ -74,4 +93,5 @@ public class MimeMessageBuilderTest {
.startsWith("multipart/alternative");
}
+
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[5/8] james-project git commit: JAMES-2429 keep compiled Pattern once
checked for validity
Posted by bt...@apache.org.
JAMES-2429 keep compiled Pattern once checked for validity
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/9c67375e
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/9c67375e
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/9c67375e
Branch: refs/heads/master
Commit: 9c67375ea978e6f15535d9d63a81ba93ec4e1cfc
Parents: c0ea100
Author: Matthieu Baechler <ma...@apache.org>
Authored: Thu Jun 14 15:21:59 2018 +0200
Committer: benwa <bt...@linagora.com>
Committed: Tue Jun 19 16:52:40 2018 +0700
----------------------------------------------------------------------
.../james/dlp/api/DLPConfigurationItem.java | 25 ++++++++++++--------
.../james/dlp/api/DLPConfigurationItemTest.java | 2 +-
2 files changed, 16 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/9c67375e/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationItem.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationItem.java b/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationItem.java
index 6c48b8d..75c1b7d 100644
--- a/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationItem.java
+++ b/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationItem.java
@@ -148,24 +148,27 @@ public class DLPConfigurationItem {
public DLPConfigurationItem build() {
Preconditions.checkState(id.isPresent(), "`id` is mandatory");
Preconditions.checkState(expression.isPresent(), "`expression` is mandatory");
- Preconditions.checkState(isValidPattern(expression.get()), "`expression` must be a valid regex");
return new DLPConfigurationItem(
id.get(),
explanation,
- expression.get(),
+ ensureValidPattern(expression.get()),
new Targets(
targetsSender.orElse(NOT_TARGETED),
targetsRecipients.orElse(NOT_TARGETED),
targetsContent.orElse(NOT_TARGETED)));
}
- private static boolean isValidPattern(String regex) {
+ private Pattern ensureValidPattern(String input) {
+ return isValidPattern(input)
+ .orElseThrow(() -> new IllegalStateException("`expression` must be a valid regex"));
+ }
+
+ private static Optional<Pattern> isValidPattern(String regex) {
try {
- Pattern.compile(regex);
- return true;
+ return Optional.of(Pattern.compile(regex));
} catch (PatternSyntaxException e) {
- return false;
+ return Optional.empty();
}
}
}
@@ -226,10 +229,10 @@ public class DLPConfigurationItem {
private final Id id;
private final Optional<String> explanation;
- private final String regexp;
+ private final Pattern regexp;
private final Targets targets;
- private DLPConfigurationItem(Id id, Optional<String> explanation, String regexp, Targets targets) {
+ private DLPConfigurationItem(Id id, Optional<String> explanation, Pattern regexp, Targets targets) {
this.id = id;
this.explanation = explanation;
this.regexp = regexp;
@@ -240,7 +243,7 @@ public class DLPConfigurationItem {
return explanation;
}
- public String getRegexp() {
+ public Pattern getRegexp() {
return regexp;
}
@@ -257,9 +260,11 @@ public class DLPConfigurationItem {
if (o instanceof DLPConfigurationItem) {
DLPConfigurationItem dlpConfigurationItem = (DLPConfigurationItem) o;
+ Optional<String> regexp = Optional.ofNullable(this.regexp).map(Pattern::pattern);
+ Optional<String> otherRegexp = Optional.ofNullable(dlpConfigurationItem.regexp).map(Pattern::pattern);
return Objects.equals(this.id, dlpConfigurationItem.id)
&& Objects.equals(this.explanation, dlpConfigurationItem.explanation)
- && Objects.equals(this.regexp, dlpConfigurationItem.regexp)
+ && Objects.equals(regexp, otherRegexp)
&& Objects.equals(this.targets, dlpConfigurationItem.targets);
}
return false;
http://git-wip-us.apache.org/repos/asf/james-project/blob/9c67375e/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java b/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java
index b0d8f9b..8887568 100644
--- a/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java
+++ b/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java
@@ -124,7 +124,7 @@ public class DLPConfigurationItemTest {
.expression(REGEX)
.build();
- assertThat(dlpConfigurationItem.getRegexp()).isEqualTo(REGEX);
+ assertThat(dlpConfigurationItem.getRegexp().pattern()).isEqualTo(REGEX);
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[8/8] james-project git commit: JAMES-2429 Don't fail on never null
fields
Posted by bt...@apache.org.
JAMES-2429 Don't fail on never null fields
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/23d22a0e
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/23d22a0e
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/23d22a0e
Branch: refs/heads/master
Commit: 23d22a0e9cc9b00b25db2c32adb79d287e90cb0e
Parents: f109758
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Mon Jun 18 17:46:09 2018 +0200
Committer: benwa <bt...@linagora.com>
Committed: Tue Jun 19 16:53:02 2018 +0700
----------------------------------------------------------------------
.../main/java/org/apache/james/dlp/api/DLPConfigurationItem.java | 4 +---
.../java/org/apache/james/dlp/api/DLPConfigurationItemTest.java | 1 +
2 files changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/23d22a0e/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationItem.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationItem.java b/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationItem.java
index 79d5e94..9d4dbe6 100644
--- a/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationItem.java
+++ b/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationItem.java
@@ -263,11 +263,9 @@ public class DLPConfigurationItem {
if (o instanceof DLPConfigurationItem) {
DLPConfigurationItem dlpConfigurationItem = (DLPConfigurationItem) o;
- Optional<String> regexp = Optional.ofNullable(this.regexp).map(Pattern::pattern);
- Optional<String> otherRegexp = Optional.ofNullable(dlpConfigurationItem.regexp).map(Pattern::pattern);
return Objects.equals(this.id, dlpConfigurationItem.id)
&& Objects.equals(this.explanation, dlpConfigurationItem.explanation)
- && Objects.equals(regexp, otherRegexp)
+ && Objects.equals(this.regexp.pattern(), dlpConfigurationItem.regexp.pattern())
&& Objects.equals(this.targets, dlpConfigurationItem.targets);
}
return false;
http://git-wip-us.apache.org/repos/asf/james-project/blob/23d22a0e/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java b/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java
index 375b6c4..2cd7296 100644
--- a/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java
+++ b/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java
@@ -38,6 +38,7 @@ public class DLPConfigurationItemTest {
@Test
void shouldMatchBeanContract() {
EqualsVerifier.forClass(DLPConfigurationItem.class)
+ .withNonnullFields("regexp")
.verify();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[2/8] james-project git commit: JAMES-2429 Helper for iterating
multipart content
Posted by bt...@apache.org.
JAMES-2429 Helper for iterating multipart content
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/c04fd750
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/c04fd750
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/c04fd750
Branch: refs/heads/master
Commit: c04fd750442c942570133a183b5a50875392d700
Parents: 380721c
Author: benwa <bt...@linagora.com>
Authored: Thu Jun 14 11:25:33 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Tue Jun 19 16:52:40 2018 +0700
----------------------------------------------------------------------
javax-mail-extension/pom.xml | 4 +++
.../org/apache/james/javax/MultipartUtil.java | 38 ++++++++++++++++++++
.../transport/mailets/StripAttachment.java | 11 ++----
.../mailets/remote/delivery/Converter7Bit.java | 10 +++---
4 files changed, 50 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/c04fd750/javax-mail-extension/pom.xml
----------------------------------------------------------------------
diff --git a/javax-mail-extension/pom.xml b/javax-mail-extension/pom.xml
index fa9c00e..97cd119 100644
--- a/javax-mail-extension/pom.xml
+++ b/javax-mail-extension/pom.xml
@@ -36,5 +36,9 @@
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/james-project/blob/c04fd750/javax-mail-extension/src/main/java/org/apache/james/javax/MultipartUtil.java
----------------------------------------------------------------------
diff --git a/javax-mail-extension/src/main/java/org/apache/james/javax/MultipartUtil.java b/javax-mail-extension/src/main/java/org/apache/james/javax/MultipartUtil.java
new file mode 100644
index 0000000..b92e1e3
--- /dev/null
+++ b/javax-mail-extension/src/main/java/org/apache/james/javax/MultipartUtil.java
@@ -0,0 +1,38 @@
+/****************************************************************
+ * 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.javax;
+
+import java.util.List;
+
+import javax.mail.BodyPart;
+import javax.mail.MessagingException;
+import javax.mail.Multipart;
+
+import com.google.common.collect.ImmutableList;
+
+public class MultipartUtil {
+ public static List<BodyPart> retrieveBodyParts(Multipart multipart) throws MessagingException {
+ ImmutableList.Builder<BodyPart> builder = ImmutableList.builder();
+ for (int i = 0; i < multipart.getCount(); i++) {
+ builder.add(multipart.getBodyPart(i));
+ }
+ return builder.build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/c04fd750/mailet/standard/src/main/java/org/apache/james/transport/mailets/StripAttachment.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/mailets/StripAttachment.java b/mailet/standard/src/main/java/org/apache/james/transport/mailets/StripAttachment.java
index 891c448..2a82413 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/mailets/StripAttachment.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/mailets/StripAttachment.java
@@ -45,6 +45,7 @@ import javax.mail.internet.MimeUtility;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
+import org.apache.james.javax.MultipartUtil;
import org.apache.james.mime4j.codec.DecodeMonitor;
import org.apache.james.mime4j.codec.DecoderUtil;
import org.apache.mailet.Mail;
@@ -271,7 +272,7 @@ public class StripAttachment extends GenericMailet {
Multipart multipart = (Multipart) part.getContent();
boolean atLeastOneRemoved = false;
boolean subpartHasBeenChanged = false;
- List<BodyPart> bodyParts = retrieveBodyParts(multipart);
+ List<BodyPart> bodyParts = MultipartUtil.retrieveBodyParts(multipart);
for (BodyPart bodyPart: bodyParts) {
if (isMultipart(bodyPart)) {
if (processMultipartPartMessage(bodyPart, mail)) {
@@ -301,14 +302,6 @@ public class StripAttachment extends GenericMailet {
}
}
- private List<BodyPart> retrieveBodyParts(Multipart multipart) throws MessagingException {
- ImmutableList.Builder<BodyPart> builder = ImmutableList.builder();
- for (int i = 0; i < multipart.getCount(); i++) {
- builder.add(multipart.getBodyPart(i));
- }
- return builder.build();
- }
-
private boolean shouldBeRemoved(BodyPart bodyPart, Mail mail) throws MessagingException, Exception {
String fileName = getFilename(bodyPart);
http://git-wip-us.apache.org/repos/asf/james-project/blob/c04fd750/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/Converter7Bit.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/Converter7Bit.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/Converter7Bit.java
index 63b17f6..2eb44f4 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/Converter7Bit.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/Converter7Bit.java
@@ -20,11 +20,14 @@
package org.apache.james.transport.mailets.remote.delivery;
import java.io.IOException;
+import java.util.List;
+import javax.mail.BodyPart;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimePart;
+import org.apache.james.javax.MultipartUtil;
import org.apache.mailet.MailetContext;
public class Converter7Bit {
@@ -37,10 +40,9 @@ public class Converter7Bit {
public MimePart convertTo7Bit(MimePart part) throws MessagingException, IOException {
if (part.isMimeType("multipart/*")) {
- MimeMultipart parts = (MimeMultipart) part.getContent();
- int count = parts.getCount();
- for (int i = 0; i < count; i++) {
- convertTo7Bit((MimePart) parts.getBodyPart(i));
+ List<BodyPart> bodyParts = MultipartUtil.retrieveBodyParts((MimeMultipart) part.getContent());
+ for (BodyPart bodyPart : bodyParts) {
+ convertTo7Bit((MimePart) bodyPart);
}
} else if ("8bit".equals(part.getEncoding())) {
// The content may already be in encoded the form (likely with mail
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[7/8] james-project git commit: JAMES-2429 Upgrade EqualsVerifier
Posted by bt...@apache.org.
JAMES-2429 Upgrade EqualsVerifier
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f1097588
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f1097588
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f1097588
Branch: refs/heads/master
Commit: f1097588f380390913d82fce9bb2544df06cdf85
Parents: a8586df
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Mon Jun 18 17:53:01 2018 +0200
Committer: benwa <bt...@linagora.com>
Committed: Tue Jun 19 16:53:02 2018 +0700
----------------------------------------------------------------------
.../cassandra/init/CassandraConfigurationTest.java | 1 -
.../java/org/apache/james/domainlist/api/DomainTest.java | 4 +++-
.../java/org/apache/james/eventsourcing/EventIdTest.java | 1 -
.../james/eventsourcing/eventstore/HistoryTest.java | 1 -
.../james/mailbox/acl/PositiveUserACLChangedTest.java | 1 -
.../java/org/apache/james/mailbox/model/BlobIdTest.java | 1 -
.../java/org/apache/james/mailbox/model/BlobTest.java | 1 +
.../org/apache/james/mailbox/model/MailboxPathTest.java | 1 -
.../org/apache/james/mailbox/model/QuotaRatioTest.java | 1 -
.../org/apache/james/mailbox/model/SearchQueryTest.java | 4 +++-
.../mailbox/cassandra/mail/CassandraMessageDAOTest.java | 1 -
.../mailing/QuotaMailingListenerConfigurationTest.java | 1 -
.../quota/mailing/aggregates/UserQuotaThresholdsTest.java | 1 -
.../mailing/commands/DetectThresholdCrossingTest.java | 1 +
.../mailing/subscribers/QuotaThresholdNoticeTest.java | 1 -
.../james/mailbox/quota/model/HistoryEvolutionTest.java | 1 -
.../mailbox/quota/model/QuotaThresholdChangeTest.java | 1 -
.../mailbox/quota/model/QuotaThresholdHistoryTest.java | 1 -
.../james/mailbox/quota/model/QuotaThresholdTest.java | 1 -
.../james/mailbox/quota/model/QuotaThresholdsTest.java | 1 -
.../search/elasticsearch/json/QuotaRatioAsJsonTest.java | 1 -
.../java/org/apache/james/quota/search/LimitTest.java | 1 -
.../java/org/apache/james/quota/search/OffsetTest.java | 1 -
.../org/apache/james/quota/search/QuotaClauseTest.java | 4 ----
.../org/apache/james/quota/search/QuotaQueryTest.java | 1 -
.../spamassassin/SpamAssassinConfigurationTest.java | 1 -
.../james/mailbox/store/mail/model/UsernameTest.java | 1 -
.../test/java/org/apache/mailet/base/test/FakeMail.java | 4 +++-
mdn/src/test/java/org/apache/james/mdn/MDNReportTest.java | 1 -
mdn/src/test/java/org/apache/james/mdn/MDNTest.java | 1 -
.../java/org/apache/james/mdn/fields/AddressTypeTest.java | 1 -
.../java/org/apache/james/mdn/fields/DispositionTest.java | 1 -
.../test/java/org/apache/james/mdn/fields/ErrorTest.java | 1 -
.../org/apache/james/mdn/fields/ExtensionFieldTest.java | 1 -
.../org/apache/james/mdn/fields/FinalRecipientTest.java | 1 -
.../java/org/apache/james/mdn/fields/GatewayTest.java | 1 -
.../apache/james/mdn/fields/OriginalMessageIdTest.java | 1 -
.../apache/james/mdn/fields/OriginalRecipientTest.java | 1 -
.../apache/james/mdn/fields/ReportingUserAgentTest.java | 1 -
.../test/java/org/apache/james/mdn/fields/TextTest.java | 1 -
.../james/mdn/modifier/DispositionModifierTest.java | 1 -
pom.xml | 2 +-
.../james/imap/api/message/request/SearchKeyTest.java | 10 ++++++++++
.../apache/james/protocols/smtp/hook/HookResultTest.java | 1 -
.../java/org/apache/james/util/streams/OffsetTest.java | 1 -
.../apache/james/dlp/api/DLPConfigurationItemTest.java | 3 ---
.../test/java/org/apache/james/rrt/lib/MappingTest.java | 1 +
.../dlp/eventsourcing/aggregates/DLPAggregateIdTest.java | 1 -
.../dlp/eventsourcing/commands/ClearCommandTest.java | 1 -
.../dlp/eventsourcing/commands/StoreCommandTest.java | 1 -
.../eventsourcing/events/ConfigurationItemsAddedTest.java | 1 -
.../events/ConfigurationItemsRemovedTest.java | 1 -
.../james/mailrepository/api/MailRepositoryUrlTest.java | 1 +
.../java/org/apache/james/jmap/model/JmapMDNTest.java | 1 -
.../org/apache/james/jmap/model/MDNDispositionTest.java | 1 -
.../james/jmap/model/mailbox/MailboxNamespaceTest.java | 1 -
.../org/apache/james/jmap/model/mailbox/RightsTest.java | 2 --
.../src/test/java/org/apache/james/task/TaskIdTest.java | 1 -
58 files changed, 24 insertions(+), 59 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/CassandraConfigurationTest.java
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/CassandraConfigurationTest.java b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/CassandraConfigurationTest.java
index c59fc6c..6c2b4ce 100644
--- a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/CassandraConfigurationTest.java
+++ b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/CassandraConfigurationTest.java
@@ -35,7 +35,6 @@ public class CassandraConfigurationTest {
@Test
public void cassandraConfigurationShouldRespectBeanContract() {
EqualsVerifier.forClass(CassandraConfiguration.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/core/src/test/java/org/apache/james/domainlist/api/DomainTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/james/domainlist/api/DomainTest.java b/core/src/test/java/org/apache/james/domainlist/api/DomainTest.java
index ef2821c..5073d02 100644
--- a/core/src/test/java/org/apache/james/domainlist/api/DomainTest.java
+++ b/core/src/test/java/org/apache/james/domainlist/api/DomainTest.java
@@ -31,7 +31,9 @@ public class DomainTest {
@Test
public void shouldRespectBeanContract() {
- EqualsVerifier.forClass(Domain.class).verify();
+ EqualsVerifier.forClass(Domain.class)
+ .withIgnoredFields("domainName")
+ .verify();
}
@Test
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/event-sourcing/event-sourcing-pojo/src/test/java/org/apache/james/eventsourcing/EventIdTest.java
----------------------------------------------------------------------
diff --git a/event-sourcing/event-sourcing-pojo/src/test/java/org/apache/james/eventsourcing/EventIdTest.java b/event-sourcing/event-sourcing-pojo/src/test/java/org/apache/james/eventsourcing/EventIdTest.java
index 1b46fbf..ea566f8 100644
--- a/event-sourcing/event-sourcing-pojo/src/test/java/org/apache/james/eventsourcing/EventIdTest.java
+++ b/event-sourcing/event-sourcing-pojo/src/test/java/org/apache/james/eventsourcing/EventIdTest.java
@@ -30,7 +30,6 @@ class EventIdTest {
@Test
void shouldMatchBeanContract() {
EqualsVerifier.forClass(EventId.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/event-sourcing/event-store-api/src/test/java/org/apache/james/eventsourcing/eventstore/HistoryTest.java
----------------------------------------------------------------------
diff --git a/event-sourcing/event-store-api/src/test/java/org/apache/james/eventsourcing/eventstore/HistoryTest.java b/event-sourcing/event-store-api/src/test/java/org/apache/james/eventsourcing/eventstore/HistoryTest.java
index 2945b92..db5e79e 100644
--- a/event-sourcing/event-store-api/src/test/java/org/apache/james/eventsourcing/eventstore/HistoryTest.java
+++ b/event-sourcing/event-store-api/src/test/java/org/apache/james/eventsourcing/eventstore/HistoryTest.java
@@ -34,7 +34,6 @@ class HistoryTest {
@Test
void shouldMatchBeanContract() {
EqualsVerifier.forClass(History.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/api/src/test/java/org/apache/james/mailbox/acl/PositiveUserACLChangedTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/acl/PositiveUserACLChangedTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/acl/PositiveUserACLChangedTest.java
index 3581aa2..70a5ee7 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/acl/PositiveUserACLChangedTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/acl/PositiveUserACLChangedTest.java
@@ -28,7 +28,6 @@ public class PositiveUserACLChangedTest {
@Test
public void shouldMatchBeanContact() {
EqualsVerifier.forClass(PositiveUserACLChanged.class)
- .allFieldsShouldBeUsed()
.verify();
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/api/src/test/java/org/apache/james/mailbox/model/BlobIdTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/BlobIdTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/BlobIdTest.java
index c5a5740..f91b9c7 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/BlobIdTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/BlobIdTest.java
@@ -33,7 +33,6 @@ public class BlobIdTest {
@Test
public void shouldMatchBeanContact() {
EqualsVerifier.forClass(BlobId.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/api/src/test/java/org/apache/james/mailbox/model/BlobTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/BlobTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/BlobTest.java
index ed35795..0c306d4 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/BlobTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/BlobTest.java
@@ -37,6 +37,7 @@ public class BlobTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(Blob.class)
+ .withIgnoredFields("payload", "size")
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java
index 7e0d330..422d587 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java
@@ -32,7 +32,6 @@ public class MailboxPathTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(MailboxPath.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/api/src/test/java/org/apache/james/mailbox/model/QuotaRatioTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/QuotaRatioTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/QuotaRatioTest.java
index 3940068..ac3ad9c 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/QuotaRatioTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/QuotaRatioTest.java
@@ -41,7 +41,6 @@ class QuotaRatioTest {
@Test
void shouldMatchBeanContact() {
EqualsVerifier.forClass(QuotaRatio.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/api/src/test/java/org/apache/james/mailbox/model/SearchQueryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/SearchQueryTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/SearchQueryTest.java
index b6ed574..b5725a6 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/SearchQueryTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/SearchQueryTest.java
@@ -30,7 +30,9 @@ public class SearchQueryTest {
@Test
public void searchQueryShouldRespectBeanContract() {
- EqualsVerifier.forClass(SearchQuery.class).verify();
+ EqualsVerifier.forClass(SearchQuery.class)
+ .withOnlyTheseFields("criterias")
+ .verify();
}
@Test
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java
index 8e00d7b..8d4c963 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java
@@ -332,7 +332,6 @@ public class CassandraMessageDAOTest {
@Test
public void messageIdAttachmentIdsShouldMatchBeanContract() {
EqualsVerifier.forClass(MessageIdAttachmentIds.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/QuotaMailingListenerConfigurationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/QuotaMailingListenerConfigurationTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/QuotaMailingListenerConfigurationTest.java
index e2c39ea..9f76365 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/QuotaMailingListenerConfigurationTest.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/QuotaMailingListenerConfigurationTest.java
@@ -47,7 +47,6 @@ public class QuotaMailingListenerConfigurationTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(QuotaMailingListenerConfiguration.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/aggregates/UserQuotaThresholdsTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/aggregates/UserQuotaThresholdsTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/aggregates/UserQuotaThresholdsTest.java
index 52d7ff4..bc1390a 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/aggregates/UserQuotaThresholdsTest.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/aggregates/UserQuotaThresholdsTest.java
@@ -34,7 +34,6 @@ public class UserQuotaThresholdsTest {
@Test
public void aggregateShouldMatchBeanContract() {
EqualsVerifier.forClass(UserQuotaThresholds.Id.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/commands/DetectThresholdCrossingTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/commands/DetectThresholdCrossingTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/commands/DetectThresholdCrossingTest.java
index 9a287c2..2b6b942 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/commands/DetectThresholdCrossingTest.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/commands/DetectThresholdCrossingTest.java
@@ -28,6 +28,7 @@ public class DetectThresholdCrossingTest {
@Test
public void aggregateShouldMatchBeanContract() {
EqualsVerifier.forClass(DetectThresholdCrossing.class)
+ .withIgnoredFields("instant")
.verify();
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/subscribers/QuotaThresholdNoticeTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/subscribers/QuotaThresholdNoticeTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/subscribers/QuotaThresholdNoticeTest.java
index 576ae0a..8ddcf64 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/subscribers/QuotaThresholdNoticeTest.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/subscribers/QuotaThresholdNoticeTest.java
@@ -59,7 +59,6 @@ class QuotaThresholdNoticeTest {
@Test
void shouldMatchBeanContract() {
EqualsVerifier.forClass(QuotaThresholdNotice.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/HistoryEvolutionTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/HistoryEvolutionTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/HistoryEvolutionTest.java
index 2855e6f..d6771ce 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/HistoryEvolutionTest.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/HistoryEvolutionTest.java
@@ -34,7 +34,6 @@ class HistoryEvolutionTest {
@Test
void shouldMatchBeanContract() {
EqualsVerifier.forClass(HistoryEvolution.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdChangeTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdChangeTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdChangeTest.java
index 5fb150e..b556c80 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdChangeTest.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdChangeTest.java
@@ -33,7 +33,6 @@ class QuotaThresholdChangeTest {
@Test
void shouldMatchBeanContract() {
EqualsVerifier.forClass(QuotaThresholdChange.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdHistoryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdHistoryTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdHistoryTest.java
index a4bf51c..2a68910 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdHistoryTest.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdHistoryTest.java
@@ -38,7 +38,6 @@ public class QuotaThresholdHistoryTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(QuotaThresholdHistory.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdTest.java
index ca2f5b0..2d850be 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdTest.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdTest.java
@@ -38,7 +38,6 @@ public class QuotaThresholdTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(QuotaThreshold.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdsTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdsTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdsTest.java
index b871296..f7f18f6 100644
--- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdsTest.java
+++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/model/QuotaThresholdsTest.java
@@ -39,7 +39,6 @@ public class QuotaThresholdsTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(QuotaThresholds.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJsonTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJsonTest.java b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJsonTest.java
index e5046ba..32a1aca 100644
--- a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJsonTest.java
+++ b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioAsJsonTest.java
@@ -45,7 +45,6 @@ public class QuotaRatioAsJsonTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(QuotaRatioAsJson.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/LimitTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/LimitTest.java b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/LimitTest.java
index 4e8387a..9bd6e8e 100644
--- a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/LimitTest.java
+++ b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/LimitTest.java
@@ -30,7 +30,6 @@ public class LimitTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(Limit.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/OffsetTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/OffsetTest.java b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/OffsetTest.java
index 50ae174..99486ff 100644
--- a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/OffsetTest.java
+++ b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/OffsetTest.java
@@ -30,7 +30,6 @@ public class OffsetTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(Offset.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaClauseTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaClauseTest.java b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaClauseTest.java
index ff7a5ab..414b4d3 100644
--- a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaClauseTest.java
+++ b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaClauseTest.java
@@ -35,28 +35,24 @@ public class QuotaClauseTest {
@Test
public void lessThanShouldMatchBeanContract() {
EqualsVerifier.forClass(QuotaClause.LessThan.class)
- .allFieldsShouldBeUsed()
.verify();
}
@Test
public void moreThanShouldMatchBeanContract() {
EqualsVerifier.forClass(QuotaClause.MoreThan.class)
- .allFieldsShouldBeUsed()
.verify();
}
@Test
public void hasDomainShouldMatchBeanContract() {
EqualsVerifier.forClass(QuotaClause.HasDomain.class)
- .allFieldsShouldBeUsed()
.verify();
}
@Test
public void andShouldMatchBeanContract() {
EqualsVerifier.forClass(QuotaClause.And.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaQueryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaQueryTest.java b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaQueryTest.java
index c2371db..654e503 100644
--- a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaQueryTest.java
+++ b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaQueryTest.java
@@ -33,7 +33,6 @@ public class QuotaQueryTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(QuotaQuery.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinConfigurationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinConfigurationTest.java b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinConfigurationTest.java
index 40f4423..5136daa 100644
--- a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinConfigurationTest.java
+++ b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinConfigurationTest.java
@@ -32,7 +32,6 @@ public class SpamAssassinConfigurationTest {
@Test
public void spamAssassinConfigurationShouldRespectBeanContract() {
EqualsVerifier.forClass(SpamAssassinConfiguration.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/UsernameTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/UsernameTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/UsernameTest.java
index 225449b..0ec4eed 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/UsernameTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/UsernameTest.java
@@ -33,7 +33,6 @@ public class UsernameTest {
@Test
public void shouldRespectBeanContract() {
EqualsVerifier.forClass(Username.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java
index 6a5bf52..6791a1f 100644
--- a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java
+++ b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java
@@ -424,6 +424,8 @@ public class FakeMail implements Mail, Serializable {
&& Objects.equal(this.errorMessage, that.errorMessage)
&& Objects.equal(this.lastUpdated, that.lastUpdated)
&& Objects.equal(this.attributes, that.attributes)
+ && Objects.equal(this.remoteHost, that.remoteHost)
+ && Objects.equal(this.perRecipientHeaders, that.perRecipientHeaders)
&& Objects.equal(this.remoteAddr, that.remoteAddr);
}
return false;
@@ -431,7 +433,7 @@ public class FakeMail implements Mail, Serializable {
@Override
public final int hashCode() {
- return Objects.hashCode(name, sender, recipients, state, errorMessage, lastUpdated, attributes, size, remoteAddr);
+ return Objects.hashCode(name, sender, recipients, state, errorMessage, lastUpdated, attributes, size, remoteAddr, remoteHost, perRecipientHeaders);
}
@Override
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mdn/src/test/java/org/apache/james/mdn/MDNReportTest.java
----------------------------------------------------------------------
diff --git a/mdn/src/test/java/org/apache/james/mdn/MDNReportTest.java b/mdn/src/test/java/org/apache/james/mdn/MDNReportTest.java
index 5c65916..cc8ffaa 100644
--- a/mdn/src/test/java/org/apache/james/mdn/MDNReportTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/MDNReportTest.java
@@ -52,7 +52,6 @@ public class MDNReportTest {
@Test
public void shouldMatchBeanContact() {
EqualsVerifier.forClass(MDNReport.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mdn/src/test/java/org/apache/james/mdn/MDNTest.java
----------------------------------------------------------------------
diff --git a/mdn/src/test/java/org/apache/james/mdn/MDNTest.java b/mdn/src/test/java/org/apache/james/mdn/MDNTest.java
index 905a209..7362cf6 100644
--- a/mdn/src/test/java/org/apache/james/mdn/MDNTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/MDNTest.java
@@ -55,7 +55,6 @@ public class MDNTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(MDN.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mdn/src/test/java/org/apache/james/mdn/fields/AddressTypeTest.java
----------------------------------------------------------------------
diff --git a/mdn/src/test/java/org/apache/james/mdn/fields/AddressTypeTest.java b/mdn/src/test/java/org/apache/james/mdn/fields/AddressTypeTest.java
index ee2520b..527d6d7 100644
--- a/mdn/src/test/java/org/apache/james/mdn/fields/AddressTypeTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/fields/AddressTypeTest.java
@@ -34,7 +34,6 @@ public class AddressTypeTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(AddressType.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mdn/src/test/java/org/apache/james/mdn/fields/DispositionTest.java
----------------------------------------------------------------------
diff --git a/mdn/src/test/java/org/apache/james/mdn/fields/DispositionTest.java b/mdn/src/test/java/org/apache/james/mdn/fields/DispositionTest.java
index 817d731..05ddf9e 100644
--- a/mdn/src/test/java/org/apache/james/mdn/fields/DispositionTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/fields/DispositionTest.java
@@ -41,7 +41,6 @@ public class DispositionTest {
@Test
public void shouldMatchBeanContract() throws Exception {
EqualsVerifier.forClass(Disposition.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mdn/src/test/java/org/apache/james/mdn/fields/ErrorTest.java
----------------------------------------------------------------------
diff --git a/mdn/src/test/java/org/apache/james/mdn/fields/ErrorTest.java b/mdn/src/test/java/org/apache/james/mdn/fields/ErrorTest.java
index 294b90b..0f50d48 100644
--- a/mdn/src/test/java/org/apache/james/mdn/fields/ErrorTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/fields/ErrorTest.java
@@ -35,7 +35,6 @@ public class ErrorTest {
@Test
public void shouldMatchBeanContract() throws Exception {
EqualsVerifier.forClass(Error.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mdn/src/test/java/org/apache/james/mdn/fields/ExtensionFieldTest.java
----------------------------------------------------------------------
diff --git a/mdn/src/test/java/org/apache/james/mdn/fields/ExtensionFieldTest.java b/mdn/src/test/java/org/apache/james/mdn/fields/ExtensionFieldTest.java
index 5d9ff6b..d487d5f 100644
--- a/mdn/src/test/java/org/apache/james/mdn/fields/ExtensionFieldTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/fields/ExtensionFieldTest.java
@@ -35,7 +35,6 @@ public class ExtensionFieldTest {
@Test
public void shouldMatchBeanContract() throws Exception {
EqualsVerifier.forClass(ExtensionField.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mdn/src/test/java/org/apache/james/mdn/fields/FinalRecipientTest.java
----------------------------------------------------------------------
diff --git a/mdn/src/test/java/org/apache/james/mdn/fields/FinalRecipientTest.java b/mdn/src/test/java/org/apache/james/mdn/fields/FinalRecipientTest.java
index ef4cd69..24595a3 100644
--- a/mdn/src/test/java/org/apache/james/mdn/fields/FinalRecipientTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/fields/FinalRecipientTest.java
@@ -35,7 +35,6 @@ public class FinalRecipientTest {
@Test
public void shouldMatchBeanContract() throws Exception {
EqualsVerifier.forClass(FinalRecipient.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mdn/src/test/java/org/apache/james/mdn/fields/GatewayTest.java
----------------------------------------------------------------------
diff --git a/mdn/src/test/java/org/apache/james/mdn/fields/GatewayTest.java b/mdn/src/test/java/org/apache/james/mdn/fields/GatewayTest.java
index a276d19..7132c6b 100644
--- a/mdn/src/test/java/org/apache/james/mdn/fields/GatewayTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/fields/GatewayTest.java
@@ -35,7 +35,6 @@ public class GatewayTest {
@Test
public void shouldMatchBeanContract() throws Exception {
EqualsVerifier.forClass(Gateway.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mdn/src/test/java/org/apache/james/mdn/fields/OriginalMessageIdTest.java
----------------------------------------------------------------------
diff --git a/mdn/src/test/java/org/apache/james/mdn/fields/OriginalMessageIdTest.java b/mdn/src/test/java/org/apache/james/mdn/fields/OriginalMessageIdTest.java
index fb5719a..2c6b1b2 100644
--- a/mdn/src/test/java/org/apache/james/mdn/fields/OriginalMessageIdTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/fields/OriginalMessageIdTest.java
@@ -35,7 +35,6 @@ public class OriginalMessageIdTest {
@Test
public void shouldMatchBeanContract() throws Exception {
EqualsVerifier.forClass(OriginalMessageId.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mdn/src/test/java/org/apache/james/mdn/fields/OriginalRecipientTest.java
----------------------------------------------------------------------
diff --git a/mdn/src/test/java/org/apache/james/mdn/fields/OriginalRecipientTest.java b/mdn/src/test/java/org/apache/james/mdn/fields/OriginalRecipientTest.java
index fcc6756..9723951 100644
--- a/mdn/src/test/java/org/apache/james/mdn/fields/OriginalRecipientTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/fields/OriginalRecipientTest.java
@@ -36,7 +36,6 @@ public class OriginalRecipientTest {
@Test
public void shouldMatchBeanContract() throws Exception {
EqualsVerifier.forClass(OriginalRecipient.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mdn/src/test/java/org/apache/james/mdn/fields/ReportingUserAgentTest.java
----------------------------------------------------------------------
diff --git a/mdn/src/test/java/org/apache/james/mdn/fields/ReportingUserAgentTest.java b/mdn/src/test/java/org/apache/james/mdn/fields/ReportingUserAgentTest.java
index abd5f1c..e425f63 100644
--- a/mdn/src/test/java/org/apache/james/mdn/fields/ReportingUserAgentTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/fields/ReportingUserAgentTest.java
@@ -37,7 +37,6 @@ public class ReportingUserAgentTest {
@Test
public void shouldMatchBeanContact() {
EqualsVerifier.forClass(ReportingUserAgent.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mdn/src/test/java/org/apache/james/mdn/fields/TextTest.java
----------------------------------------------------------------------
diff --git a/mdn/src/test/java/org/apache/james/mdn/fields/TextTest.java b/mdn/src/test/java/org/apache/james/mdn/fields/TextTest.java
index 0d82c28..f64804c 100644
--- a/mdn/src/test/java/org/apache/james/mdn/fields/TextTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/fields/TextTest.java
@@ -35,7 +35,6 @@ public class TextTest {
@Test
public void shouldMatchBeanContact() {
EqualsVerifier.forClass(Text.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/mdn/src/test/java/org/apache/james/mdn/modifier/DispositionModifierTest.java
----------------------------------------------------------------------
diff --git a/mdn/src/test/java/org/apache/james/mdn/modifier/DispositionModifierTest.java b/mdn/src/test/java/org/apache/james/mdn/modifier/DispositionModifierTest.java
index dccf3dd..64ee91b 100644
--- a/mdn/src/test/java/org/apache/james/mdn/modifier/DispositionModifierTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/modifier/DispositionModifierTest.java
@@ -33,7 +33,6 @@ public class DispositionModifierTest {
@Test
public void shouldMatchBeanContract() throws Exception {
EqualsVerifier.forClass(DispositionModifier.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index baece46..7b93832 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1959,7 +1959,7 @@
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
- <version>1.7.6</version>
+ <version>2.4.6</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/protocols/imap/src/test/java/org/apache/james/imap/api/message/request/SearchKeyTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/api/message/request/SearchKeyTest.java b/protocols/imap/src/test/java/org/apache/james/imap/api/message/request/SearchKeyTest.java
index 9630f7b..e8a962d 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/api/message/request/SearchKeyTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/api/message/request/SearchKeyTest.java
@@ -21,14 +21,24 @@ package org.apache.james.imap.api.message.request;
import static org.assertj.core.api.Assertions.assertThat;
+import java.util.List;
+
import org.junit.Test;
+import com.google.common.collect.ImmutableList;
+
import nl.jqno.equalsverifier.EqualsVerifier;
public class SearchKeyTest {
+
+ private static final SearchKey RED = SearchKey.buildFrom("red");
+ private static final SearchKey BLACK = SearchKey.buildTo("black");
+
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(SearchKey.class)
+ .withPrefabValues(SearchKey.class, RED, BLACK)
+ .withPrefabValues(List.class, ImmutableList.of(RED), ImmutableList.of(BLACK))
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/hook/HookResultTest.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/hook/HookResultTest.java b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/hook/HookResultTest.java
index 8c6db85..a76d50a 100644
--- a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/hook/HookResultTest.java
+++ b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/hook/HookResultTest.java
@@ -28,7 +28,6 @@ public class HookResultTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(HookResult.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/server/container/util-java8/src/test/java/org/apache/james/util/streams/OffsetTest.java
----------------------------------------------------------------------
diff --git a/server/container/util-java8/src/test/java/org/apache/james/util/streams/OffsetTest.java b/server/container/util-java8/src/test/java/org/apache/james/util/streams/OffsetTest.java
index 5a5b2b0..45d8e6d 100644
--- a/server/container/util-java8/src/test/java/org/apache/james/util/streams/OffsetTest.java
+++ b/server/container/util-java8/src/test/java/org/apache/james/util/streams/OffsetTest.java
@@ -34,7 +34,6 @@ public class OffsetTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(Offset.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java b/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java
index e185d15..375b6c4 100644
--- a/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java
+++ b/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java
@@ -38,21 +38,18 @@ public class DLPConfigurationItemTest {
@Test
void shouldMatchBeanContract() {
EqualsVerifier.forClass(DLPConfigurationItem.class)
- .allFieldsShouldBeUsed()
.verify();
}
@Test
void innerClassTargetsShouldMatchBeanContract() {
EqualsVerifier.forClass(DLPConfigurationItem.Targets.class)
- .allFieldsShouldBeUsed()
.verify();
}
@Test
void innerClassIdShouldMatchBeanContract() {
EqualsVerifier.forClass(DLPConfigurationItem.Targets.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/server/data/data-api/src/test/java/org/apache/james/rrt/lib/MappingTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/test/java/org/apache/james/rrt/lib/MappingTest.java b/server/data/data-api/src/test/java/org/apache/james/rrt/lib/MappingTest.java
index 63fd182..6c49e8d 100644
--- a/server/data/data-api/src/test/java/org/apache/james/rrt/lib/MappingTest.java
+++ b/server/data/data-api/src/test/java/org/apache/james/rrt/lib/MappingTest.java
@@ -147,6 +147,7 @@ public class MappingTest {
@Test
void beanShouldRespectBeanContract() {
EqualsVerifier.forClass(Mapping.Impl.class)
+ .withOnlyTheseFields("type", "mapping")
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/aggregates/DLPAggregateIdTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/aggregates/DLPAggregateIdTest.java b/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/aggregates/DLPAggregateIdTest.java
index 3604974..a5f740b 100644
--- a/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/aggregates/DLPAggregateIdTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/aggregates/DLPAggregateIdTest.java
@@ -32,7 +32,6 @@ public class DLPAggregateIdTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(DLPAggregateId.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/commands/ClearCommandTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/commands/ClearCommandTest.java b/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/commands/ClearCommandTest.java
index d859728..34a1289 100644
--- a/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/commands/ClearCommandTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/commands/ClearCommandTest.java
@@ -30,7 +30,6 @@ public class ClearCommandTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(ClearCommand.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/commands/StoreCommandTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/commands/StoreCommandTest.java b/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/commands/StoreCommandTest.java
index 5b6b473..b8be60f 100644
--- a/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/commands/StoreCommandTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/commands/StoreCommandTest.java
@@ -34,7 +34,6 @@ public class StoreCommandTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(StoreCommand.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/events/ConfigurationItemsAddedTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/events/ConfigurationItemsAddedTest.java b/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/events/ConfigurationItemsAddedTest.java
index 3aa81b5..3a62657 100644
--- a/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/events/ConfigurationItemsAddedTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/events/ConfigurationItemsAddedTest.java
@@ -36,7 +36,6 @@ public class ConfigurationItemsAddedTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(ConfigurationItemsAdded.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/events/ConfigurationItemsRemovedTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/events/ConfigurationItemsRemovedTest.java b/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/events/ConfigurationItemsRemovedTest.java
index 2a2027b..a6d4ecc 100644
--- a/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/events/ConfigurationItemsRemovedTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/dlp/eventsourcing/events/ConfigurationItemsRemovedTest.java
@@ -36,7 +36,6 @@ public class ConfigurationItemsRemovedTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(ConfigurationItemsRemoved.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/api/MailRepositoryUrlTest.java
----------------------------------------------------------------------
diff --git a/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/api/MailRepositoryUrlTest.java b/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/api/MailRepositoryUrlTest.java
index 7b14795..83766b3 100644
--- a/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/api/MailRepositoryUrlTest.java
+++ b/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/api/MailRepositoryUrlTest.java
@@ -30,6 +30,7 @@ public class MailRepositoryUrlTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(MailRepositoryUrl.class)
+ .withIgnoredFields("protocol")
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/JmapMDNTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/JmapMDNTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/JmapMDNTest.java
index e692d87..064a0be 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/JmapMDNTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/JmapMDNTest.java
@@ -60,7 +60,6 @@ public class JmapMDNTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(JmapMDN.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MDNDispositionTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MDNDispositionTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MDNDispositionTest.java
index f5f5d57..916b905 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MDNDispositionTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MDNDispositionTest.java
@@ -34,7 +34,6 @@ public class MDNDispositionTest {
@Test
public void shouldMatchBeanContract() {
EqualsVerifier.forClass(MDNDisposition.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxNamespaceTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxNamespaceTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxNamespaceTest.java
index 1836b1a..e8e2234 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxNamespaceTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxNamespaceTest.java
@@ -30,7 +30,6 @@ public class MailboxNamespaceTest {
@Test
public void shouldRespectJavaBeanContract() throws Exception {
EqualsVerifier.forClass(MailboxNamespace.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/RightsTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/RightsTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/RightsTest.java
index 2b54b19..9e40ec2 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/RightsTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/RightsTest.java
@@ -42,14 +42,12 @@ public class RightsTest {
@Test
public void rightsShouldMatchBeanContract() {
EqualsVerifier.forClass(Rights.class)
- .allFieldsShouldBeUsed()
.verify();
}
@Test
public void usernameShouldMatchBeanContract() {
EqualsVerifier.forClass(Rights.Username.class)
- .allFieldsShouldBeUsed()
.verify();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1097588/server/task/src/test/java/org/apache/james/task/TaskIdTest.java
----------------------------------------------------------------------
diff --git a/server/task/src/test/java/org/apache/james/task/TaskIdTest.java b/server/task/src/test/java/org/apache/james/task/TaskIdTest.java
index c1f378a..24c3a03 100644
--- a/server/task/src/test/java/org/apache/james/task/TaskIdTest.java
+++ b/server/task/src/test/java/org/apache/james/task/TaskIdTest.java
@@ -28,7 +28,6 @@ public class TaskIdTest {
@Test
public void taskIdShouldMatchBeanContract() {
EqualsVerifier.forClass(TaskId.class)
- .allFieldsShouldBeUsed()
.verify();
}
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[3/8] james-project git commit: JAMES-2429 provide Targets as a
Stream of enum value
Posted by bt...@apache.org.
JAMES-2429 provide Targets as a Stream of enum value
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/380721c0
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/380721c0
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/380721c0
Branch: refs/heads/master
Commit: 380721c0c3b03a2d181e9d61c3332f7d94c958cb
Parents: 9c67375
Author: Matthieu Baechler <ma...@apache.org>
Authored: Thu Jun 14 15:42:52 2018 +0200
Committer: benwa <bt...@linagora.com>
Committed: Tue Jun 19 16:52:40 2018 +0700
----------------------------------------------------------------------
.../james/dlp/api/DLPConfigurationItem.java | 73 ++++++++++----------
.../james/dlp/api/DLPConfigurationItemTest.java | 6 ++
.../cassandra/DLPConfigurationItemDTO.java | 2 +-
3 files changed, 45 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/380721c0/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationItem.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationItem.java b/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationItem.java
index 75c1b7d..79d5e94 100644
--- a/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationItem.java
+++ b/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationItem.java
@@ -19,10 +19,12 @@
package org.apache.james.dlp.api;
+import java.util.EnumSet;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
+import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
@@ -72,51 +74,52 @@ public class DLPConfigurationItem {
}
public static class Builder {
- private static final boolean NOT_TARGETED = false;
- private Optional<Boolean> targetsSender;
- private Optional<Boolean> targetsRecipients;
- private Optional<Boolean> targetsContent;
+ private EnumSet<Targets.Type> targets;
private Optional<String> explanation;
private Optional<String> expression;
private Optional<Id> id;
public Builder() {
- targetsSender = Optional.empty();
- targetsRecipients = Optional.empty();
- targetsContent = Optional.empty();
+ targets = EnumSet.noneOf(Targets.Type.class);
explanation = Optional.empty();
expression = Optional.empty();
id = Optional.empty();
}
public Builder targetsSender() {
- this.targetsSender = Optional.of(true);
+ this.targets.add(Targets.Type.Sender);
return this;
}
public Builder targetsSender(boolean targetsSender) {
- this.targetsSender = Optional.of(targetsSender);
+ if (targetsSender) {
+ return targetsSender();
+ }
return this;
}
public Builder targetsRecipients() {
- this.targetsRecipients = Optional.of(true);
+ this.targets.add(Targets.Type.Recipient);
return this;
}
public Builder targetsRecipients(boolean targetsRecipients) {
- this.targetsRecipients = Optional.of(targetsRecipients);
+ if (targetsRecipients) {
+ return targetsRecipients();
+ }
return this;
}
public Builder targetsContent() {
- this.targetsContent = Optional.of(true);
+ this.targets.add(Targets.Type.Content);
return this;
}
public Builder targetsContent(boolean targetsContent) {
- this.targetsContent = Optional.of(targetsContent);
+ if (targetsContent) {
+ return targetsContent();
+ }
return this;
}
@@ -153,10 +156,7 @@ public class DLPConfigurationItem {
id.get(),
explanation,
ensureValidPattern(expression.get()),
- new Targets(
- targetsSender.orElse(NOT_TARGETED),
- targetsRecipients.orElse(NOT_TARGETED),
- targetsContent.orElse(NOT_TARGETED)));
+ new Targets(targets));
}
private Pattern ensureValidPattern(String input) {
@@ -174,26 +174,33 @@ public class DLPConfigurationItem {
}
public static class Targets {
- private final boolean senderTargeted;
- private final boolean recipientTargeted;
- private final boolean contentTargeted;
-
- public Targets(boolean senderTargeted, boolean recipientTargeted, boolean contentTargeted) {
- this.senderTargeted = senderTargeted;
- this.recipientTargeted = recipientTargeted;
- this.contentTargeted = contentTargeted;
+
+ public enum Type {
+ Sender,
+ Recipient,
+ Content
+ }
+
+ private final EnumSet<Type> targets;
+
+ private Targets(EnumSet<Type> targets) {
+ this.targets = targets;
}
public boolean isSenderTargeted() {
- return senderTargeted;
+ return targets.contains(Type.Sender);
}
public boolean isRecipientTargeted() {
- return recipientTargeted;
+ return targets.contains(Type.Recipient);
}
public boolean isContentTargeted() {
- return contentTargeted;
+ return targets.contains(Type.Content);
+ }
+
+ public Stream<Type> list() {
+ return targets.stream();
}
@Override
@@ -201,24 +208,20 @@ public class DLPConfigurationItem {
if (o instanceof Targets) {
Targets targets = (Targets) o;
- return Objects.equals(this.senderTargeted, targets.senderTargeted)
- && Objects.equals(this.recipientTargeted, targets.recipientTargeted)
- && Objects.equals(this.contentTargeted, targets.contentTargeted);
+ return Objects.equals(this.targets, targets.targets);
}
return false;
}
@Override
public final int hashCode() {
- return Objects.hash(senderTargeted, recipientTargeted, contentTargeted);
+ return Objects.hash(targets);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
- .add("senderTargeted", senderTargeted)
- .add("recipientTargeted", recipientTargeted)
- .add("contentTargeted", contentTargeted)
+ .add("targets", targets)
.toString();
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/380721c0/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java b/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java
index 8887568..e185d15 100644
--- a/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java
+++ b/server/data/data-api/src/test/java/org/apache/james/dlp/api/DLPConfigurationItemTest.java
@@ -23,6 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import org.apache.james.dlp.api.DLPConfigurationItem.Targets.Type;
import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.Test;
@@ -149,6 +150,7 @@ public class DLPConfigurationItemTest {
softly.assertThat(dlpConfigurationItem.getTargets().isContentTargeted()).isFalse();
softly.assertThat(dlpConfigurationItem.getTargets().isRecipientTargeted()).isFalse();
softly.assertThat(dlpConfigurationItem.getTargets().isSenderTargeted()).isFalse();
+ softly.assertThat(dlpConfigurationItem.getTargets().list()).isEmpty();
});
}
@@ -164,6 +166,7 @@ public class DLPConfigurationItemTest {
softly.assertThat(dlpConfigurationItem.getTargets().isContentTargeted()).isFalse();
softly.assertThat(dlpConfigurationItem.getTargets().isRecipientTargeted()).isTrue();
softly.assertThat(dlpConfigurationItem.getTargets().isSenderTargeted()).isFalse();
+ softly.assertThat(dlpConfigurationItem.getTargets().list()).contains(Type.Recipient);
});
}
@@ -179,6 +182,7 @@ public class DLPConfigurationItemTest {
softly.assertThat(dlpConfigurationItem.getTargets().isContentTargeted()).isFalse();
softly.assertThat(dlpConfigurationItem.getTargets().isRecipientTargeted()).isFalse();
softly.assertThat(dlpConfigurationItem.getTargets().isSenderTargeted()).isTrue();
+ softly.assertThat(dlpConfigurationItem.getTargets().list()).contains(Type.Sender);
});
}
@@ -194,6 +198,7 @@ public class DLPConfigurationItemTest {
softly.assertThat(dlpConfigurationItem.getTargets().isContentTargeted()).isTrue();
softly.assertThat(dlpConfigurationItem.getTargets().isRecipientTargeted()).isFalse();
softly.assertThat(dlpConfigurationItem.getTargets().isSenderTargeted()).isFalse();
+ softly.assertThat(dlpConfigurationItem.getTargets().list()).contains(Type.Content);
});
}
@@ -211,6 +216,7 @@ public class DLPConfigurationItemTest {
softly.assertThat(dlpConfigurationItem.getTargets().isContentTargeted()).isTrue();
softly.assertThat(dlpConfigurationItem.getTargets().isRecipientTargeted()).isTrue();
softly.assertThat(dlpConfigurationItem.getTargets().isSenderTargeted()).isTrue();
+ softly.assertThat(dlpConfigurationItem.getTargets().list()).contains(Type.Content, Type.Sender, Type.Recipient);
});
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/380721c0/server/data/data-cassandra/src/main/java/org/apache/james/dlp/eventsourcing/cassandra/DLPConfigurationItemDTO.java
----------------------------------------------------------------------
diff --git a/server/data/data-cassandra/src/main/java/org/apache/james/dlp/eventsourcing/cassandra/DLPConfigurationItemDTO.java b/server/data/data-cassandra/src/main/java/org/apache/james/dlp/eventsourcing/cassandra/DLPConfigurationItemDTO.java
index 02b6e4e..433e07f 100644
--- a/server/data/data-cassandra/src/main/java/org/apache/james/dlp/eventsourcing/cassandra/DLPConfigurationItemDTO.java
+++ b/server/data/data-cassandra/src/main/java/org/apache/james/dlp/eventsourcing/cassandra/DLPConfigurationItemDTO.java
@@ -40,7 +40,7 @@ public class DLPConfigurationItemDTO {
return new DLPConfigurationItemDTO(
dlpConfiguration.getId().asString(),
dlpConfiguration.getExplanation(),
- dlpConfiguration.getRegexp(),
+ dlpConfiguration.getRegexp().pattern(),
targets.isContentTargeted(),
targets.isSenderTargeted(),
targets.isRecipientTargeted());
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[6/8] james-project git commit: JAMES-2429 Implement basic Dlp matcher
Posted by bt...@apache.org.
JAMES-2429 Implement basic Dlp matcher
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/a8586df3
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/a8586df3
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/a8586df3
Branch: refs/heads/master
Commit: a8586df34d82dd50e9ea387e6b0becdc34fbae66
Parents: 19caa77
Author: Matthieu Baechler <ma...@apache.org>
Authored: Wed Jun 6 08:55:24 2018 +0200
Committer: benwa <bt...@linagora.com>
Committed: Tue Jun 19 16:53:02 2018 +0700
----------------------------------------------------------------------
.../apache/mailet/base/MailAddressFixture.java | 5 +
.../james/dlp/api/DLPConfigurationLoader.java | 28 +
.../james/dlp/api/DLPConfigurationStore.java | 5 +-
.../james/transport/matchers/dlp/Dlp.java | 78 +++
.../transport/matchers/dlp/DlpDomainRules.java | 300 +++++++++++
.../transport/matchers/dlp/DlpRulesLoader.java | 57 ++
.../matchers/dlp/DlpDomainRulesTest.java | 60 +++
.../james/transport/matchers/dlp/DlpTest.java | 514 +++++++++++++++++++
8 files changed, 1043 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/a8586df3/mailet/base/src/test/java/org/apache/mailet/base/MailAddressFixture.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/test/java/org/apache/mailet/base/MailAddressFixture.java b/mailet/base/src/test/java/org/apache/mailet/base/MailAddressFixture.java
index 51bd487..4efe093 100644
--- a/mailet/base/src/test/java/org/apache/mailet/base/MailAddressFixture.java
+++ b/mailet/base/src/test/java/org/apache/mailet/base/MailAddressFixture.java
@@ -21,6 +21,7 @@ package org.apache.mailet.base;
import javax.mail.internet.AddressException;
+import org.apache.james.core.Domain;
import org.apache.james.core.MailAddress;
public class MailAddressFixture {
@@ -28,6 +29,10 @@ public class MailAddressFixture {
public static final String JAMES_APACHE_ORG = "james.apache.org";
public static final String JAMES2_APACHE_ORG = "james2.apache.org";
+ public static final Domain JAMES_LOCAL_DOMAIN = Domain.of(JAMES_LOCAL);
+ public static final Domain JAMES_APACHE_ORG_DOMAIN = Domain.of(JAMES_APACHE_ORG);
+ public static final Domain JAMES2_APACHE_ORG_DOMAIN = Domain.of(JAMES2_APACHE_ORG);
+
public static final MailAddress SENDER = createMailAddress("sender@" + JAMES_LOCAL);
public static final MailAddress RECIPIENT1 = createMailAddress("recipient1@" + JAMES_LOCAL);
public static final MailAddress RECIPIENT2 = createMailAddress("recipient2@" + JAMES_LOCAL);
http://git-wip-us.apache.org/repos/asf/james-project/blob/a8586df3/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationLoader.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationLoader.java b/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationLoader.java
new file mode 100644
index 0000000..e2d27f5
--- /dev/null
+++ b/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationLoader.java
@@ -0,0 +1,28 @@
+/****************************************************************
+ * 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.dlp.api;
+
+import java.util.stream.Stream;
+
+import org.apache.james.core.Domain;
+
+public interface DLPConfigurationLoader {
+ Stream<DLPConfigurationItem> list(Domain domain);
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a8586df3/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationStore.java
----------------------------------------------------------------------
diff --git a/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationStore.java b/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationStore.java
index 457341e..4272f49 100644
--- a/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationStore.java
+++ b/server/data/data-api/src/main/java/org/apache/james/dlp/api/DLPConfigurationStore.java
@@ -20,15 +20,12 @@
package org.apache.james.dlp.api;
import java.util.List;
-import java.util.stream.Stream;
import org.apache.james.core.Domain;
import com.google.common.collect.ImmutableList;
-public interface DLPConfigurationStore {
-
- Stream<DLPConfigurationItem> list(Domain domain);
+public interface DLPConfigurationStore extends DLPConfigurationLoader {
void store(Domain domain, List<DLPConfigurationItem> rule);
http://git-wip-us.apache.org/repos/asf/james-project/blob/a8586df3/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/dlp/Dlp.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/dlp/Dlp.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/dlp/Dlp.java
new file mode 100644
index 0000000..cb7fc72
--- /dev/null
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/dlp/Dlp.java
@@ -0,0 +1,78 @@
+/****************************************************************
+ * 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.transport.matchers.dlp;
+
+import java.util.Collection;
+import java.util.Optional;
+
+import javax.inject.Inject;
+import javax.mail.MessagingException;
+
+import org.apache.james.core.MailAddress;
+import org.apache.james.dlp.api.DLPConfigurationItem;
+import org.apache.mailet.Mail;
+import org.apache.mailet.base.GenericMatcher;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableList;
+
+public class Dlp extends GenericMatcher {
+
+ public static final String DLP_MATCHED_RULE = "DlpMatchedRule";
+
+ private final DlpRulesLoader rulesLoader;
+
+ @Inject
+ @VisibleForTesting
+ Dlp(DlpRulesLoader rulesLoader) {
+ this.rulesLoader = rulesLoader;
+ }
+
+ @Override
+ public Collection<MailAddress> match(Mail mail) throws MessagingException {
+ Optional<DLPConfigurationItem.Id> firstMatchingRuleId = findFirstMatchingRule(mail);
+
+ if (firstMatchingRuleId.isPresent()) {
+ DLPConfigurationItem.Id ruleId = firstMatchingRuleId.get();
+ setRuleIdAsMailAttribute(mail, ruleId);
+ return mail.getRecipients();
+ }
+ return ImmutableList.of();
+ }
+
+ private void setRuleIdAsMailAttribute(Mail mail, DLPConfigurationItem.Id ruleId) {
+ mail.setAttribute(DLP_MATCHED_RULE, ruleId.asString());
+ }
+
+ private Optional<DLPConfigurationItem.Id> findFirstMatchingRule(Mail mail) {
+ return Optional
+ .ofNullable(mail.getSender())
+ .flatMap(sender -> matchingRule(sender, mail));
+ }
+
+ private Optional<DLPConfigurationItem.Id> matchingRule(MailAddress address, Mail mail) {
+ return rulesLoader.load(address.getDomain()).match(mail);
+ }
+
+ @Override
+ public String getMatcherInfo() {
+ return "Data Leak Prevention Matcher";
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a8586df3/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/dlp/DlpDomainRules.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/dlp/DlpDomainRules.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/dlp/DlpDomainRules.java
new file mode 100644
index 0000000..f44a60e
--- /dev/null
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/dlp/DlpDomainRules.java
@@ -0,0 +1,300 @@
+/****************************************************************
+ * 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.transport.matchers.dlp;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.regex.Pattern;
+import java.util.stream.Stream;
+
+import javax.mail.Address;
+import javax.mail.BodyPart;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Multipart;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.james.core.MailAddress;
+import org.apache.james.dlp.api.DLPConfigurationItem;
+import org.apache.james.dlp.api.DLPConfigurationItem.Targets;
+import org.apache.james.javax.MultipartUtil;
+import org.apache.james.mime4j.util.MimeUtil;
+import org.apache.james.util.OptionalUtils;
+import org.apache.mailet.Mail;
+
+import com.github.fge.lambdas.Throwing;
+import com.github.fge.lambdas.predicates.ThrowingPredicate;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableCollection;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMultimap;
+
+public class DlpDomainRules {
+
+ @VisibleForTesting static DlpDomainRules matchNothing() {
+ return DlpDomainRules.of(new Rule(DLPConfigurationItem.Id.of("always false"), (mail) -> false));
+ }
+
+ @VisibleForTesting static DlpDomainRules matchAll() {
+ return DlpDomainRules.of(new Rule(DLPConfigurationItem.Id.of("always true"), (mail) -> true));
+ }
+
+ private static DlpDomainRules of(Rule rule) {
+ return new DlpDomainRules(ImmutableList.of(rule));
+ }
+
+ public static DlpDomainRulesBuilder builder() {
+ return new DlpDomainRulesBuilder();
+ }
+
+ static class Rule {
+
+ interface MatcherFunction extends ThrowingPredicate<Mail> { }
+
+
+ private static Stream<String> asStringStream(Address[] addresses) {
+ return Arrays.stream(addresses).map(Rule::asString);
+ }
+
+ private static String asString(Address address) {
+ return MimeUtil.unscrambleHeaderValue(address.toString());
+ }
+
+ private static class ContentMatcher implements Rule.MatcherFunction {
+
+ private final Pattern pattern;
+
+ private ContentMatcher(Pattern pattern) {
+ this.pattern = pattern;
+ }
+
+ @Override
+ public boolean doTest(Mail mail) throws MessagingException, IOException {
+ return Stream
+ .concat(getMessageSubjects(mail), getMessageBodies(mail.getMessage()))
+ .anyMatch(pattern.asPredicate());
+ }
+
+ private Stream<String> getMessageSubjects(Mail mail) throws MessagingException {
+ MimeMessage message = mail.getMessage();
+ if (message != null) {
+ return OptionalUtils.toStream(
+ Optional.ofNullable(message.getSubject()));
+ }
+ return Stream.of();
+ }
+
+ private Stream<String> getMessageBodies(Message message) throws MessagingException, IOException {
+ if (message != null) {
+ return getMessageBodiesFromContent(message.getContent());
+ }
+ return Stream.of();
+ }
+
+ private Stream<String> getMessageBodiesFromContent(Object content) throws IOException, MessagingException {
+ if (content instanceof String) {
+ return Stream.of((String) content);
+ }
+ if (content instanceof Message) {
+ Message message = (Message) content;
+ return getMessageBodiesFromContent(message.getContent());
+ }
+ if (content instanceof Multipart) {
+ return MultipartUtil.retrieveBodyParts((Multipart) content)
+ .stream()
+ .map(Throwing.function(BodyPart::getContent).sneakyThrow())
+ .flatMap(Throwing.function(this::getMessageBodiesFromContent).sneakyThrow());
+ }
+ return Stream.of();
+ }
+ }
+
+ private static class RecipientsMatcher implements Rule.MatcherFunction {
+
+ private final Pattern pattern;
+
+ private RecipientsMatcher(Pattern pattern) {
+ this.pattern = pattern;
+ }
+
+ @Override
+ public boolean doTest(Mail mail) throws MessagingException, IOException {
+ return listRecipientsAsString(mail).anyMatch(pattern.asPredicate());
+ }
+
+ private Stream<String> listRecipientsAsString(Mail mail) throws MessagingException {
+ return Stream.concat(listEnvelopRecipients(mail), listHeaderRecipients(mail));
+ }
+
+ private Stream<String> listEnvelopRecipients(Mail mail) {
+ return mail.getRecipients().stream().map(MailAddress::asString);
+ }
+
+ private Stream<String> listHeaderRecipients(Mail mail) throws MessagingException {
+ return Optional.ofNullable(mail.getMessage())
+ .flatMap(Throwing.function(m -> Optional.ofNullable(m.getAllRecipients())))
+ .map(Rule::asStringStream)
+ .orElse(Stream.of());
+ }
+
+ }
+
+ private static class SenderMatcher implements Rule.MatcherFunction {
+
+ private final Pattern pattern;
+
+ private SenderMatcher(Pattern pattern) {
+ this.pattern = pattern;
+ }
+
+ @Override
+ public boolean doTest(Mail mail) throws MessagingException {
+ return listSenders(mail).anyMatch(pattern.asPredicate());
+ }
+
+ private Stream<String> listSenders(Mail mail) throws MessagingException {
+ return Stream.concat(listEnvelopSender(mail), listFromHeaders(mail));
+ }
+
+ private Stream<String> listEnvelopSender(Mail mail) {
+ return OptionalUtils.toStream(Optional.ofNullable(mail.getSender()).map(MailAddress::asString));
+ }
+
+ private Stream<String> listFromHeaders(Mail mail) throws MessagingException {
+ MimeMessage message = mail.getMessage();
+ if (message != null) {
+ return asStringStream(message.getFrom());
+ }
+ return Stream.of();
+ }
+
+ }
+
+ private final DLPConfigurationItem.Id id;
+ private final MatcherFunction matcher;
+
+ public Rule(DLPConfigurationItem.Id id, MatcherFunction matcher) {
+ this.id = id;
+ this.matcher = matcher;
+ }
+
+ public DLPConfigurationItem.Id id() {
+ return id;
+ }
+
+ public boolean match(Mail mail) {
+ return matcher.test(mail);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof Rule) {
+ Rule other = (Rule) o;
+ return Objects.equals(id, other.id) &&
+ Objects.equals(matcher, other.matcher);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, matcher);
+ }
+
+ }
+
+ public static class DlpDomainRulesBuilder {
+
+ private final ImmutableMultimap.Builder<Targets.Type, Rule> rules;
+
+ private DlpDomainRulesBuilder() {
+ rules = ImmutableMultimap.builder();
+ }
+
+ public DlpDomainRulesBuilder recipientRule(DLPConfigurationItem.Id id, Pattern pattern) {
+ return rule(Targets.Type.Recipient, id, pattern);
+ }
+
+ public DlpDomainRulesBuilder senderRule(DLPConfigurationItem.Id id, Pattern pattern) {
+ return rule(Targets.Type.Sender, id, pattern);
+ }
+
+ public DlpDomainRulesBuilder contentRule(DLPConfigurationItem.Id id, Pattern pattern) {
+ return rule(Targets.Type.Content, id, pattern);
+ }
+
+ public DlpDomainRulesBuilder rule(Targets.Type type, DLPConfigurationItem.Id id, Pattern regexp) {
+ rules.put(type, toRule(type, id, regexp));
+ return this;
+ }
+
+ private Rule toRule(Targets.Type type, DLPConfigurationItem.Id id, Pattern pattern) {
+ switch (type) {
+ case Sender:
+ return new Rule(id, new Rule.SenderMatcher(pattern));
+ case Content:
+ return new Rule(id, new Rule.ContentMatcher(pattern));
+ case Recipient:
+ return new Rule(id, new Rule.RecipientsMatcher(pattern));
+ default:
+ throw new IllegalArgumentException("unexpected value");
+ }
+ }
+
+ public DlpDomainRules build() {
+ ImmutableMultimap<Targets.Type, Rule> rules = this.rules.build();
+ Preconditions.checkState(!containsDuplicateIds(rules), "Rules should not contain duplicated `id`");
+ return new DlpDomainRules(rules.values());
+ }
+
+ private boolean containsDuplicateIds(ImmutableMultimap<Targets.Type, Rule> rules) {
+ return
+ Stream.of(Targets.Type.values())
+ .map(rules::get)
+ .anyMatch(this::containsDuplicateIds);
+ }
+
+ private boolean containsDuplicateIds(ImmutableCollection<Rule> rules) {
+ long distinctIdCount = rules.stream()
+ .map(Rule::id)
+ .distinct()
+ .count();
+ return distinctIdCount != rules.size();
+ }
+
+ }
+
+ private final ImmutableCollection<Rule> rules;
+
+ private DlpDomainRules(ImmutableCollection<Rule> rules) {
+ this.rules = rules;
+ }
+
+ public Optional<DLPConfigurationItem.Id> match(Mail mail) {
+ return rules.stream()
+ .filter(rule -> rule.match(mail))
+ .map(Rule::id)
+ .findFirst();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a8586df3/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/dlp/DlpRulesLoader.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/dlp/DlpRulesLoader.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/dlp/DlpRulesLoader.java
new file mode 100644
index 0000000..13430d9
--- /dev/null
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/dlp/DlpRulesLoader.java
@@ -0,0 +1,57 @@
+/****************************************************************
+ * 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.transport.matchers.dlp;
+
+import java.util.stream.Stream;
+
+import javax.inject.Inject;
+
+import org.apache.james.core.Domain;
+import org.apache.james.dlp.api.DLPConfigurationItem;
+import org.apache.james.dlp.api.DLPConfigurationStore;
+
+public interface DlpRulesLoader {
+
+ DlpDomainRules load(Domain domain);
+
+ class Impl implements DlpRulesLoader {
+
+ private final DLPConfigurationStore configurationStore;
+
+ @Inject
+ public Impl(DLPConfigurationStore configurationStore) {
+ this.configurationStore = configurationStore;
+ }
+
+ @Override
+ public DlpDomainRules load(Domain domain) {
+ return toRules(configurationStore.list(domain));
+ }
+
+ private DlpDomainRules toRules(Stream<DLPConfigurationItem> items) {
+ DlpDomainRules.DlpDomainRulesBuilder builder = DlpDomainRules.builder();
+ items.forEach(item ->
+ item.getTargets().list().forEach(type ->
+ builder.rule(type, item.getId(), item.getRegexp())
+ ));
+ return builder.build();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a8586df3/server/mailet/mailets/src/test/java/org/apache/james/transport/matchers/dlp/DlpDomainRulesTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/matchers/dlp/DlpDomainRulesTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/matchers/dlp/DlpDomainRulesTest.java
new file mode 100644
index 0000000..155795f
--- /dev/null
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/matchers/dlp/DlpDomainRulesTest.java
@@ -0,0 +1,60 @@
+/****************************************************************
+ * 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.transport.matchers.dlp;
+
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.regex.Pattern;
+
+import org.apache.james.dlp.api.DLPConfigurationItem.Id;
+import org.junit.jupiter.api.Test;
+
+class DlpDomainRulesTest {
+
+ private static final Pattern PATTERN_1 = Pattern.compile("1");
+ private static final Pattern PATTERN_2 = Pattern.compile("2");
+
+ @Test
+ void builderShouldThrowWhenDuplicateIds() {
+ assertThatThrownBy(() -> DlpDomainRules.builder()
+ .senderRule(Id.of("1"), PATTERN_1)
+ .senderRule(Id.of("1"), PATTERN_2)
+ .build())
+ .isInstanceOf(IllegalStateException.class);
+ }
+
+ @Test
+ void builderShouldNotThrowWhenDuplicateIdsOnDifferentTypes() {
+ assertThatCode(() -> DlpDomainRules.builder()
+ .senderRule(Id.of("1"), PATTERN_1)
+ .contentRule(Id.of("1"), PATTERN_2)
+ .build())
+ .doesNotThrowAnyException();
+ }
+
+
+ @Test
+ void builderShouldNotThrowWhenEmpty() {
+ assertThatCode(() -> DlpDomainRules.builder().build())
+ .doesNotThrowAnyException();
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/a8586df3/server/mailet/mailets/src/test/java/org/apache/james/transport/matchers/dlp/DlpTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/matchers/dlp/DlpTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/matchers/dlp/DlpTest.java
new file mode 100644
index 0000000..12aa394
--- /dev/null
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/matchers/dlp/DlpTest.java
@@ -0,0 +1,514 @@
+/****************************************************************
+ * 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.transport.matchers.dlp;
+
+import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES;
+import static org.apache.mailet.base.MailAddressFixture.JAMES_APACHE_ORG;
+import static org.apache.mailet.base.MailAddressFixture.JAMES_APACHE_ORG_DOMAIN;
+import static org.apache.mailet.base.MailAddressFixture.OTHER_AT_JAMES;
+import static org.apache.mailet.base.MailAddressFixture.RECIPIENT1;
+import static org.apache.mailet.base.MailAddressFixture.RECIPIENT2;
+import static org.apache.mailet.base.MailAddressFixture.RECIPIENT3;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Optional;
+import java.util.regex.Pattern;
+
+import org.apache.james.core.Domain;
+import org.apache.james.core.builder.MimeMessageBuilder;
+import org.apache.james.dlp.api.DLPConfigurationItem.Id;
+import org.apache.mailet.base.test.FakeMail;
+import org.junit.jupiter.api.Test;
+
+class DlpTest {
+
+ private static final DlpRulesLoader MATCH_ALL_FOR_ALL_DOMAINS = (Domain domain) -> DlpDomainRules.matchAll();
+ private static final DlpRulesLoader MATCH_NOTHING_FOR_ALL_DOMAINS = (Domain domain) -> DlpDomainRules.matchNothing();
+
+ private static DlpRulesLoader asRulesLoaderFor(Domain domain, DlpDomainRules rules) {
+ return (Domain d) -> Optional
+ .of(d)
+ .filter(domain::equals)
+ .map(ignore -> rules)
+ .orElse(DlpDomainRules.matchNothing());
+ }
+
+ @Test
+ void matchShouldReturnEmptyWhenNoRecipient() throws Exception {
+ Dlp dlp = new Dlp(MATCH_ALL_FOR_ALL_DOMAINS);
+
+ FakeMail mail = FakeMail.builder().sender(RECIPIENT1).build();
+
+ assertThat(dlp.match(mail)).isEmpty();
+ }
+
+ @Test
+ void matchShouldReturnEmptyWhenNoSender() throws Exception {
+ Dlp dlp = new Dlp(MATCH_ALL_FOR_ALL_DOMAINS);
+
+ FakeMail mail = FakeMail.builder().recipient(RECIPIENT1).build();
+
+ assertThat(dlp.match(mail)).isEmpty();
+ }
+
+ @Test
+ void matchShouldThrowOnNullMail() {
+ Dlp dlp = new Dlp(MATCH_ALL_FOR_ALL_DOMAINS);
+
+ assertThatThrownBy(() -> dlp.match(null)).isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ void matchShouldReturnEmptyWhenNoRuleMatch() throws Exception {
+ Dlp dlp = new Dlp(MATCH_NOTHING_FOR_ALL_DOMAINS);
+
+ FakeMail mail = FakeMail.builder()
+ .sender(ANY_AT_JAMES)
+ .recipient(RECIPIENT1)
+ .recipient(RECIPIENT2)
+ .build();
+
+ assertThat(dlp.match(mail)).isEmpty();
+ }
+
+ @Test
+ void matchSenderShouldReturnRecipientsWhenEnvelopSenderMatches() throws Exception {
+ Dlp dlp = new Dlp(
+ asRulesLoaderFor(
+ JAMES_APACHE_ORG_DOMAIN,
+ DlpDomainRules.builder().senderRule(Id.of("match sender"), Pattern.compile(ANY_AT_JAMES.asString())).build()));
+
+ FakeMail mail = FakeMail.builder().sender(ANY_AT_JAMES).recipient(RECIPIENT1).build();
+
+ assertThat(dlp.match(mail)).contains(RECIPIENT1);
+ }
+
+ @Test
+ void matchSenderShouldReturnRecipientsWhenFromHeaderMatches() throws Exception {
+ Dlp dlp = new Dlp(
+ asRulesLoaderFor(
+ JAMES_APACHE_ORG_DOMAIN,
+ DlpDomainRules.builder().senderRule(Id.of("match sender"), Pattern.compile(ANY_AT_JAMES.asString())).build()));
+
+ FakeMail mail = FakeMail
+ .builder()
+ .sender(OTHER_AT_JAMES)
+ .recipient(RECIPIENT1)
+ .mimeMessage(MimeMessageBuilder
+ .mimeMessageBuilder()
+ .addFrom(ANY_AT_JAMES.toInternetAddress()))
+ .build();
+
+ assertThat(dlp.match(mail)).contains(RECIPIENT1);
+ }
+
+ @Test
+ void matchShouldReturnRecipientsWhenEnvelopRecipientsMatches() throws Exception {
+ Dlp dlp = new Dlp(
+ asRulesLoaderFor(
+ JAMES_APACHE_ORG_DOMAIN,
+ DlpDomainRules.builder().recipientRule(Id.of("match recipient"), Pattern.compile(RECIPIENT1.asString())).build()));
+
+ FakeMail mail = FakeMail.builder()
+ .sender(ANY_AT_JAMES)
+ .recipient(RECIPIENT1)
+ .recipient(RECIPIENT2)
+ .build();
+
+ assertThat(dlp.match(mail)).contains(RECIPIENT1, RECIPIENT2);
+ }
+
+ @Test
+ void matchShouldReturnRecipientsWhenToHeaderMatches() throws Exception {
+ Dlp dlp = new Dlp(
+ asRulesLoaderFor(
+ JAMES_APACHE_ORG_DOMAIN,
+ DlpDomainRules.builder().recipientRule(Id.of("match recipient"), Pattern.compile(RECIPIENT2.asString())).build()));
+
+ FakeMail mail = FakeMail
+ .builder()
+ .sender(OTHER_AT_JAMES)
+ .recipient(RECIPIENT1)
+ .mimeMessage(MimeMessageBuilder
+ .mimeMessageBuilder()
+ .addToRecipient(RECIPIENT2.toInternetAddress()))
+ .build();
+
+ assertThat(dlp.match(mail)).contains(RECIPIENT1);
+ }
+
+ @Test
+ void matchShouldReturnRecipientsWhenCcHeaderMatches() throws Exception {
+ Dlp dlp = new Dlp(
+ asRulesLoaderFor(
+ JAMES_APACHE_ORG_DOMAIN,
+ DlpDomainRules.builder().recipientRule(Id.of("match recipient"), Pattern.compile(RECIPIENT2.asString())).build()));
+
+ FakeMail mail = FakeMail
+ .builder()
+ .sender(OTHER_AT_JAMES)
+ .recipient(RECIPIENT1)
+ .mimeMessage(MimeMessageBuilder
+ .mimeMessageBuilder()
+ .addCcRecipient(RECIPIENT2.toInternetAddress()))
+ .build();
+
+ assertThat(dlp.match(mail)).contains(RECIPIENT1);
+ }
+
+ @Test
+ void matchShouldReturnRecipientsWhenBccHeaderMatches() throws Exception {
+ Dlp dlp = new Dlp(
+ asRulesLoaderFor(
+ JAMES_APACHE_ORG_DOMAIN,
+ DlpDomainRules.builder().recipientRule(Id.of("match recipient"), Pattern.compile(RECIPIENT2.asString())).build()));
+
+ FakeMail mail = FakeMail
+ .builder()
+ .sender(OTHER_AT_JAMES)
+ .recipient(RECIPIENT1)
+ .mimeMessage(MimeMessageBuilder
+ .mimeMessageBuilder()
+ .addBccRecipient(RECIPIENT2.toInternetAddress()))
+ .build();
+
+ assertThat(dlp.match(mail)).contains(RECIPIENT1);
+ }
+
+ @Test
+ void matchShouldReturnRecipientsWhenSubjectHeaderMatches() throws Exception {
+ Dlp dlp = new Dlp(
+ asRulesLoaderFor(
+ JAMES_APACHE_ORG_DOMAIN,
+ DlpDomainRules.builder().contentRule(Id.of("match subject"), Pattern.compile("pony")).build()));
+
+ FakeMail mail = FakeMail
+ .builder()
+ .sender(OTHER_AT_JAMES)
+ .recipient(RECIPIENT1)
+ .mimeMessage(MimeMessageBuilder
+ .mimeMessageBuilder()
+ .setSubject("I just bought a pony"))
+ .build();
+
+ assertThat(dlp.match(mail)).contains(RECIPIENT1);
+ }
+
+ @Test
+ void matchShouldReturnRecipientsWhenMessageBodyMatches() throws Exception {
+ Dlp dlp = new Dlp(
+ asRulesLoaderFor(
+ JAMES_APACHE_ORG_DOMAIN,
+ DlpDomainRules.builder().contentRule(Id.of("match content"), Pattern.compile("horse")).build()));
+
+ FakeMail mail = FakeMail
+ .builder()
+ .sender(OTHER_AT_JAMES)
+ .recipient(RECIPIENT1)
+ .mimeMessage(MimeMessageBuilder
+ .mimeMessageBuilder()
+ .setSubject("I just bought a pony")
+ .setText("It's actually a horse, not a pony"))
+ .build();
+
+ assertThat(dlp.match(mail)).contains(RECIPIENT1);
+ }
+
+ @Test
+ void matchShouldReturnRecipientsWhenMessageBodyMatchesWithNoSubject() throws Exception {
+ Dlp dlp = new Dlp(
+ asRulesLoaderFor(
+ JAMES_APACHE_ORG_DOMAIN,
+ DlpDomainRules.builder().contentRule(Id.of("match content"), Pattern.compile("horse")).build()));
+
+ FakeMail mail = FakeMail
+ .builder()
+ .sender(OTHER_AT_JAMES)
+ .recipient(RECIPIENT1)
+ .mimeMessage(MimeMessageBuilder
+ .mimeMessageBuilder()
+ .setText("It's actually a horse, not a pony"))
+ .build();
+
+ assertThat(dlp.match(mail)).contains(RECIPIENT1);
+ }
+
+ @Test
+ void matchShouldReturnRecipientsWhenMessageMultipartBodyMatches() throws Exception {
+ Dlp dlp = new Dlp(
+ asRulesLoaderFor(
+ JAMES_APACHE_ORG_DOMAIN,
+ DlpDomainRules.builder().contentRule(Id.of("match content"), Pattern.compile("horse")).build()));
+
+ FakeMail mail = FakeMail
+ .builder()
+ .sender(OTHER_AT_JAMES)
+ .recipient(RECIPIENT1)
+ .mimeMessage(MimeMessageBuilder
+ .mimeMessageBuilder()
+ .setSubject("I just bought a pony")
+ .setMultipartWithBodyParts(
+ MimeMessageBuilder.bodyPartBuilder()
+ .data("It's actually a donkey, not a pony"),
+ MimeMessageBuilder.bodyPartBuilder()
+ .data("What??? No it's a horse!!!")))
+ .build();
+
+ assertThat(dlp.match(mail)).contains(RECIPIENT1);
+ }
+
+ @Test
+ void matchShouldReturnRecipientsWhenEmbeddedMessageContentMatches() throws Exception {
+ Dlp dlp = new Dlp(
+ asRulesLoaderFor(
+ JAMES_APACHE_ORG_DOMAIN,
+ DlpDomainRules.builder().contentRule(Id.of("match content"), Pattern.compile("horse")).build()));
+
+ FakeMail mail = FakeMail
+ .builder()
+ .sender(OTHER_AT_JAMES)
+ .recipient(RECIPIENT1)
+ .mimeMessage(MimeMessageBuilder
+ .mimeMessageBuilder()
+ .setSubject("I just bought a pony")
+ .setContent(
+ MimeMessageBuilder.multipartBuilder()
+ .addBody(
+ MimeMessageBuilder.bodyPartBuilder()
+ .data("It's actually a donkey, not a pony"))
+ .addBody(
+ MimeMessageBuilder.mimeMessageBuilder()
+ .setSender(RECIPIENT2.asString())
+ .setSubject("Embedded message with truth")
+ .setText("What??? No it's a horse!!!"))))
+ .build();
+
+ assertThat(dlp.match(mail)).contains(RECIPIENT1);
+ }
+
+ @Test
+ void matchShouldReturnEmptyWhenEmbeddedSenderMatchesInSubMessage() throws Exception {
+ Dlp dlp = new Dlp(
+ asRulesLoaderFor(
+ JAMES_APACHE_ORG_DOMAIN,
+ DlpDomainRules.builder()
+ .senderRule(Id.of("match content"), Pattern.compile(RECIPIENT2.asString()))
+ .build()));
+
+ FakeMail mail = FakeMail
+ .builder()
+ .sender(OTHER_AT_JAMES)
+ .recipient(RECIPIENT1)
+ .mimeMessage(MimeMessageBuilder
+ .mimeMessageBuilder()
+ .setSubject("I just bought a pony")
+ .setSender(RECIPIENT1.asString())
+ .setContent(
+ MimeMessageBuilder.multipartBuilder()
+ .addBody(
+ MimeMessageBuilder.bodyPartBuilder()
+ .data("It's actually a donkey, not a pony"))
+ .addBody(
+ MimeMessageBuilder.mimeMessageBuilder()
+ .setSender(RECIPIENT2.asString())
+ .setSubject("Embedded message with truth")
+ .setText("What??? No it's a horse!!!"))))
+ .build();
+
+ assertThat(dlp.match(mail)).isEmpty();
+ }
+
+ @Test
+ void matchShouldReturnEmptyWhenEmbeddedRecipientMatchesInSubMessage() throws Exception {
+ Dlp dlp = new Dlp(
+ asRulesLoaderFor(
+ JAMES_APACHE_ORG_DOMAIN,
+ DlpDomainRules.builder()
+ .recipientRule(Id.of("match content"), Pattern.compile(RECIPIENT2.asString()))
+ .build()));
+
+ FakeMail mail = FakeMail
+ .builder()
+ .sender(OTHER_AT_JAMES)
+ .recipient(RECIPIENT1)
+ .mimeMessage(MimeMessageBuilder
+ .mimeMessageBuilder()
+ .setSubject("I just bought a pony")
+ .setSender(RECIPIENT1.asString())
+ .setContent(
+ MimeMessageBuilder.multipartBuilder()
+ .addBody(
+ MimeMessageBuilder.bodyPartBuilder()
+ .data("It's actually a donkey, not a pony"))
+ .addBody(
+ MimeMessageBuilder.mimeMessageBuilder()
+ .addToRecipient(RECIPIENT1.asString())
+ .setSubject("Embedded message with truth")
+ .setText("What??? No it's a horse!!!"))))
+ .build();
+
+ assertThat(dlp.match(mail)).isEmpty();
+ }
+
+ @Test
+ void matchShouldReturnRecipientsWhenEncodedSubjectMatchesContentRule() throws Exception {
+ Dlp dlp = new Dlp(
+ asRulesLoaderFor(
+ JAMES_APACHE_ORG_DOMAIN,
+ DlpDomainRules.builder()
+ .contentRule(Id.of("match content"), Pattern.compile("poné"))
+ .build()));
+
+ FakeMail mail = FakeMail
+ .builder()
+ .sender(OTHER_AT_JAMES)
+ .recipient(RECIPIENT1)
+ .mimeMessage(MimeMessageBuilder
+ .mimeMessageBuilder()
+ .setSubject("=?ISO-8859-1?Q?I_just_bought_a_pon=E9?=")
+ .setSender(RECIPIENT1.asString())
+ .setText("Meaningless text"))
+ .build();
+
+ assertThat(dlp.match(mail)).containsOnly(RECIPIENT1);
+ }
+
+ @Test
+ void matchShouldReturnRecipientsWhenEncodedTextMatchesContentRule() throws Exception {
+ Dlp dlp = new Dlp(
+ asRulesLoaderFor(
+ JAMES_APACHE_ORG_DOMAIN,
+ DlpDomainRules.builder()
+ .contentRule(Id.of("match content"), Pattern.compile("poné"))
+ .build()));
+
+ FakeMail mail = FakeMail
+ .builder()
+ .sender(OTHER_AT_JAMES)
+ .recipient(RECIPIENT1)
+ .mimeMessage(MimeMessageBuilder
+ .mimeMessageBuilder()
+ .setSubject("you know what ?")
+ .setSender(RECIPIENT1.asString())
+ .setText("I bought a poné", "text/plain; charset=" + StandardCharsets.ISO_8859_1.name()))
+ .build();
+
+ assertThat(dlp.match(mail)).containsOnly(RECIPIENT1);
+ }
+
+ @Test
+ void matchShouldReturnRecipientsWhenRulesMatchesAMailboxRecipient() throws Exception {
+ Dlp dlp = new Dlp(
+ asRulesLoaderFor(
+ JAMES_APACHE_ORG_DOMAIN,
+ DlpDomainRules.builder()
+ .recipientRule(Id.of("id1"), Pattern.compile(RECIPIENT1.asString()))
+ .build()));
+
+ MimeMessageBuilder meaninglessText = MimeMessageBuilder
+ .mimeMessageBuilder()
+ .addToRecipient("Name <" + RECIPIENT1.asString() + " >")
+ .setSubject("=?ISO-8859-1?Q?I_just_bought_a_pon=E9?=")
+ .setText("Meaningless text");
+
+ FakeMail mail = FakeMail
+ .builder()
+ .sender(OTHER_AT_JAMES)
+ .recipient(RECIPIENT2)
+ .mimeMessage(meaninglessText)
+ .build();
+
+ assertThat(dlp.match(mail)).containsOnly(RECIPIENT2);
+ }
+
+ @Test
+ void matchShouldReturnRecipientsWhenRulesMatchesAQuotedPrintableRecipient() throws Exception {
+ Dlp dlp = new Dlp(
+ asRulesLoaderFor(
+ JAMES_APACHE_ORG_DOMAIN,
+ DlpDomainRules.builder()
+ .recipientRule(Id.of("id1"), Pattern.compile("Benoît"))
+ .build()));
+
+ MimeMessageBuilder meaninglessText = MimeMessageBuilder
+ .mimeMessageBuilder()
+ .addToRecipient("=?ISO-8859-1?Q?Beno=EEt_TELLIER?=")
+ .setSubject("=?ISO-8859-1?Q?I_just_bought_a_pon=E9?=")
+ .setText("Meaningless text");
+
+ FakeMail mail = FakeMail
+ .builder()
+ .sender(OTHER_AT_JAMES)
+ .recipient(RECIPIENT2)
+ .mimeMessage(meaninglessText)
+ .build();
+
+ assertThat(dlp.match(mail)).containsOnly(RECIPIENT2);
+ }
+
+ @Test
+ void matchShouldReturnRecipientsWhenRulesMatchesAQuotedPrintableSender() throws Exception {
+ Dlp dlp = new Dlp(
+ asRulesLoaderFor(
+ JAMES_APACHE_ORG_DOMAIN,
+ DlpDomainRules.builder()
+ .senderRule(Id.of("id1"), Pattern.compile("Benoît"))
+ .build()));
+
+ MimeMessageBuilder meaninglessText = MimeMessageBuilder
+ .mimeMessageBuilder()
+ .addFrom("=?ISO-8859-1?Q?Beno=EEt_TELLIER?=")
+ .setSubject("=?ISO-8859-1?Q?I_just_bought_a_pon=E9?=")
+ .setText("Meaningless text");
+
+ FakeMail mail = FakeMail
+ .builder()
+ .sender(OTHER_AT_JAMES)
+ .recipient(RECIPIENT2)
+ .mimeMessage(meaninglessText)
+ .build();
+
+ assertThat(dlp.match(mail)).containsOnly(RECIPIENT2);
+ }
+
+ @Test
+ void matchShouldAttachMatchingRuleNameToMail() throws Exception {
+ Dlp dlp = new Dlp(
+ asRulesLoaderFor(
+ JAMES_APACHE_ORG_DOMAIN,
+ DlpDomainRules.builder()
+ .recipientRule(Id.of("should not match recipient"), Pattern.compile(RECIPIENT3.asString()))
+ .senderRule(Id.of("should match sender"), Pattern.compile(JAMES_APACHE_ORG))
+ .build()));
+
+ FakeMail mail = FakeMail.builder()
+ .sender(ANY_AT_JAMES)
+ .recipient(RECIPIENT1)
+ .recipient(RECIPIENT2)
+ .build();
+
+ dlp.match(mail);
+
+ assertThat(mail.getAttribute("DlpMatchedRule")).isEqualTo("should match sender");
+ }
+
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org