james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [02/14] james-project git commit: JAMES-2557 DLP should ignore null sender
Date Wed, 10 Oct 2018 08:48:15 GMT
JAMES-2557 DLP should ignore null sender


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/0d8c68ab
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/0d8c68ab
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/0d8c68ab

Branch: refs/heads/master
Commit: 0d8c68ab7860f69eb1c376fc89ab04f0926e223c
Parents: 0135291
Author: Benoit Tellier <btellier@linagora.com>
Authored: Tue Oct 9 11:44:27 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Wed Oct 10 15:45:50 2018 +0700

----------------------------------------------------------------------
 .../org/apache/james/transport/matchers/dlp/Dlp.java   |  4 ++--
 .../james/transport/matchers/dlp/DlpDomainRules.java   |  4 +++-
 .../apache/james/transport/matchers/dlp/DlpTest.java   | 13 +++++++++++++
 3 files changed, 18 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/0d8c68ab/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
index 1f65082..a82dc06 100644
--- 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
@@ -23,7 +23,6 @@ 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;
@@ -51,7 +50,7 @@ public class Dlp extends GenericMatcher {
     }
 
     @Override
-    public Collection<MailAddress> match(Mail mail) throws MessagingException {
+    public Collection<MailAddress> match(Mail mail) {
         Optional<DLPConfigurationItem.Id> firstMatchingRuleId = findFirstMatchingRule(mail);
 
         if (firstMatchingRuleId.isPresent()) {
@@ -69,6 +68,7 @@ public class Dlp extends GenericMatcher {
     private Optional<DLPConfigurationItem.Id> findFirstMatchingRule(Mail mail) {
         return Optional
                 .ofNullable(mail.getSender())
+                .filter(sender -> !sender.isNullSender())
                 .flatMap(sender -> matchingRule(sender, mail));
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/0d8c68ab/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
index b954801..031f306 100644
--- 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
@@ -169,7 +169,9 @@ public class DlpDomainRules {
             }
 
             private Stream<String> listEnvelopSender(Mail mail) {
-                return StreamUtils.ofNullables(mail.getSender()).map(MailAddress::asString);
+                return StreamUtils.ofNullables(mail.getSender())
+                    .filter(sender -> !sender.isNullSender())
+                    .map(MailAddress::asString);
             }
 
             private Stream<String> listFromHeaders(Mail mail) throws MessagingException
{

http://git-wip-us.apache.org/repos/asf/james-project/blob/0d8c68ab/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
index 12aa394..88266d6 100644
--- 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
@@ -34,6 +34,7 @@ import java.util.Optional;
 import java.util.regex.Pattern;
 
 import org.apache.james.core.Domain;
+import org.apache.james.core.MailAddress;
 import org.apache.james.core.builder.MimeMessageBuilder;
 import org.apache.james.dlp.api.DLPConfigurationItem.Id;
 import org.apache.mailet.base.test.FakeMail;
@@ -103,6 +104,18 @@ class DlpTest {
     }
 
     @Test
+    void nullSenderShouldBeIgnored() throws Exception {
+        Dlp dlp = new Dlp(
+            asRulesLoaderFor(
+                JAMES_APACHE_ORG_DOMAIN,
+                DlpDomainRules.builder().recipientRule(Id.of("match all recipient"), Pattern.compile(".*")).build()));
+
+        FakeMail mail = FakeMail.builder().sender(MailAddress.nullSender()).recipient(RECIPIENT1).build();
+
+        assertThat(dlp.match(mail)).isEmpty();
+    }
+
+    @Test
     void matchSenderShouldReturnRecipientsWhenFromHeaderMatches() throws Exception {
         Dlp dlp = new Dlp(
             asRulesLoaderFor(


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message