james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [6/6] james-project git commit: MAILET-156 AutomaticallySentMailDetectorImpl should not rely on Mime4J default configuration
Date Thu, 01 Jun 2017 09:05:04 GMT
MAILET-156 AutomaticallySentMailDetectorImpl should not rely on Mime4J default configuration


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

Branch: refs/heads/master
Commit: f19648a517232337b1c93fdb096590da8d801d41
Parents: 49fbba7
Author: benwa <btellier@linagora.com>
Authored: Wed May 31 09:37:24 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Thu Jun 1 16:04:03 2017 +0700

----------------------------------------------------------------------
 .../base/AutomaticallySentMailDetectorImpl.java | 10 +++++++--
 .../AutomaticallySentMailDetectorImplTest.java  | 22 ++++++++++++++++++++
 .../mailet/base/test/MimeMessageBuilder.java    | 13 ++++++++++--
 3 files changed, 41 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f19648a5/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetectorImpl.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetectorImpl.java
b/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetectorImpl.java
index 0d1b634..cdf9e50 100644
--- a/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetectorImpl.java
+++ b/mailet/base/src/main/java/org/apache/mailet/base/AutomaticallySentMailDetectorImpl.java
@@ -36,6 +36,13 @@ import org.apache.mailet.MailAddress;
 
 public class AutomaticallySentMailDetectorImpl implements AutomaticallySentMailDetector {
 
+    private static final MimeConfig MIME_ENTITY_CONFIG = MimeConfig.custom()
+        .setMaxContentLen(-1)
+        .setMaxHeaderCount(-1)
+        .setMaxHeaderLen(-1)
+        .setMaxLineLen(-1)
+        .build();
+
     private static final String[] MAILING_LIST_HEADERS = new String[] {
             "List-Help",
             "List-Subscribe",
@@ -91,8 +98,7 @@ public class AutomaticallySentMailDetectorImpl implements AutomaticallySentMailD
 
     public boolean isMdnSentAutomatically(Mail mail) throws MessagingException {
         ResultCollector resultCollector = new ResultCollector(false);
-        MimeConfig config = MimeConfig.custom().setMaxLineLen(-1).setMaxHeaderLen(-1).build();
-        MimeStreamParser parser = new MimeStreamParser(config);
+        MimeStreamParser parser = new MimeStreamParser(MIME_ENTITY_CONFIG);
         parser.setContentHandler(createMdnContentHandler(resultCollector));
         try {
             parser.parse(mail.getMessage().getInputStream());

http://git-wip-us.apache.org/repos/asf/james-project/blob/f19648a5/mailet/base/src/test/java/org/apache/mailet/base/AutomaticallySentMailDetectorImplTest.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/test/java/org/apache/mailet/base/AutomaticallySentMailDetectorImplTest.java
b/mailet/base/src/test/java/org/apache/mailet/base/AutomaticallySentMailDetectorImplTest.java
index 8a0147d..99d0095 100644
--- a/mailet/base/src/test/java/org/apache/mailet/base/AutomaticallySentMailDetectorImplTest.java
+++ b/mailet/base/src/test/java/org/apache/mailet/base/AutomaticallySentMailDetectorImplTest.java
@@ -22,6 +22,7 @@ package org.apache.mailet.base;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.ByteArrayInputStream;
+import java.util.Collections;
 import java.util.Properties;
 
 import javax.activation.DataHandler;
@@ -33,6 +34,7 @@ import javax.mail.util.ByteArrayDataSource;
 
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.base.test.FakeMail;
+import org.apache.mailet.base.test.MimeMessageBuilder;
 import org.junit.Test;
 
 public class AutomaticallySentMailDetectorImplTest {
@@ -286,4 +288,24 @@ public class AutomaticallySentMailDetectorImplTest {
         assertThat(new AutomaticallySentMailDetectorImpl().isMdnSentAutomatically(fakeMail)).isFalse();
     }
 
+    @Test
+    public void isMdnSentAutomaticallyShouldNotThrowOnBodyPartsWithManyLines() throws Exception
{
+        int mime4jDefaultMaxHeaderCount = 1000;
+        int headerCount = mime4jDefaultMaxHeaderCount + 10;
+        MimeMessage message = MimeMessageBuilder.mimeMessageBuilder()
+            .addHeaders()
+            .setMultipartWithBodyParts(MimeMessageBuilder.bodyPartBuilder()
+                .addHeaders(Collections.nCopies(headerCount, new MimeMessageBuilder.Header("name",
"value")))
+                .data("The body part have 1010 headers, which overpass MIME4J default limits")
+                .build())
+            .build();
+
+        FakeMail fakeMail = FakeMail.builder()
+            .sender(MailAddressFixture.ANY_AT_JAMES)
+            .mimeMessage(message)
+            .build();
+
+        assertThat(new AutomaticallySentMailDetectorImpl().isMdnSentAutomatically(fakeMail)).isFalse();
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f19648a5/mailet/base/src/test/java/org/apache/mailet/base/test/MimeMessageBuilder.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/test/java/org/apache/mailet/base/test/MimeMessageBuilder.java
b/mailet/base/src/test/java/org/apache/mailet/base/test/MimeMessageBuilder.java
index 666803a..f00d9c9 100644
--- a/mailet/base/src/test/java/org/apache/mailet/base/test/MimeMessageBuilder.java
+++ b/mailet/base/src/test/java/org/apache/mailet/base/test/MimeMessageBuilder.java
@@ -23,6 +23,7 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.List;
 import java.util.Properties;
 
@@ -132,7 +133,11 @@ public class MimeMessageBuilder {
         }
 
         public BodyPartBuilder addHeaders(Header... headers) {
-            this.headers.addAll(Arrays.asList(headers));
+            return addHeaders(Arrays.asList(headers));
+        }
+
+        public BodyPartBuilder addHeaders(Collection<Header> headers) {
+            this.headers.addAll(headers);
             return this;
         }
 
@@ -317,7 +322,11 @@ public class MimeMessageBuilder {
     }
 
     public MimeMessageBuilder addHeaders(Header... headers) {
-        this.headers.addAll(Arrays.asList(headers));
+        return addHeaders(Arrays.asList(headers));
+    }
+
+    public MimeMessageBuilder addHeaders(Collection<Header> headers) {
+        this.headers.addAll(headers);
         return this;
     }
 


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