Repository: james-project Updated Branches: refs/heads/master ff5743731 -> 73a7c4682
JAMES-1861 Don't fail with mail with lines with more than 1000 characters (which is the default mime4j 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/71c05bde Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/71c05bde Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/71c05bde Branch: refs/heads/master Commit: 71c05bdec6d2073314fb06305c682faa8c46b0eb Parents: 17c79db Author: Raphael Ouazana <raphael.ouaz...@linagora.com> Authored: Wed Nov 16 17:57:16 2016 +0100 Committer: Raphael Ouazana <raphael.ouaz...@linagora.com> Committed: Thu Nov 17 14:29:47 2016 +0100 ---------------------------------------------------------------------- .../cucumber/GetMessagesMethodStepdefs.java | 5 +++++ .../test/resources/cucumber/GetMessages.feature | 7 +++++++ .../src/test/resources/eml/longLine.eml | 1 + .../apache/james/jmap/model/MessageFactory.java | 8 +++++++- .../james/jmap/model/MessageFactoryTest.java | 21 ++++++++++++++++++++ 5 files changed, 41 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/71c05bde/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java index 5bbc254..39dc1a3 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java @@ -150,6 +150,11 @@ public class GetMessagesMethodStepdefs { appendMessage("eml/multipartRelated.eml"); } + @Given("^the user has a message in \"([^\"]*)\" mailbox beginning by a long line$") + public void appendMessageBeginningByALongLine(String mailbox) throws Throwable { + appendMessage("eml/longLine.eml"); + } + private void appendMessage(String emlFileName) throws Exception { ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z"); mainStepdefs.jmapServer.serverProbe().appendMessage(userStepdefs.lastConnectedUser, http://git-wip-us.apache.org/repos/asf/james-project/blob/71c05bde/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature index 377a306..23615aa 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature @@ -207,3 +207,10 @@ Feature: GetMessages method And the list should contain 1 message And the textBody of the message is "Hello text body\n" And the htmlBody of the message is "<html>Hello html body</html>\n" + +Scenario: Retrieving message with more than 1000 char by line should return message when exists + Given the user has a message in "inbox" mailbox beginning by a long line + When the user ask for messages "["usern...@domain.tld|inbox|1"]" + Then no error is returned + And the list should contain 1 message + And the id of the message is "usern...@domain.tld|inbox|1" http://git-wip-us.apache.org/repos/asf/james-project/blob/71c05bde/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/longLine.eml ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/longLine.eml b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/longLine.eml new file mode 100644 index 0000000..84b285e --- /dev/null +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/longLine.eml @@ -0,0 +1 @@ +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456 7890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 http://git-wip-us.apache.org/repos/asf/james-project/blob/71c05bde/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java index ec12e59..d63fa4c 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java @@ -47,6 +47,7 @@ import org.apache.james.mime4j.dom.address.Mailbox; import org.apache.james.mime4j.dom.address.MailboxList; import org.apache.james.mime4j.message.MessageBuilder; import org.apache.james.mime4j.stream.Field; +import org.apache.james.mime4j.stream.MimeConfig; import com.github.steveash.guavate.Guavate; import com.google.common.base.Preconditions; @@ -57,6 +58,8 @@ import com.google.common.collect.Multimaps; public class MessageFactory { + private static final int NO_LINE_LENGTH_LIMIT_PARSING = -1; + public static final ZoneId UTC_ZONE_ID = ZoneId.of("Z"); private final MessagePreviewGenerator messagePreview; @@ -100,7 +103,10 @@ public class MessageFactory { private org.apache.james.mime4j.dom.Message parse(MetaDataWithContent message) throws MailboxException { try { - return MessageBuilder.read(message.getContent()) + return MessageBuilder + .create() + .use(MimeConfig.custom().setMaxLineLen(NO_LINE_LENGTH_LIMIT_PARSING).build()) + .parse(message.getContent()) .setDate(message.getInternalDate(), TimeZone.getTimeZone(UTC_ZONE_ID)) .build(); } catch (IOException e) { http://git-wip-us.apache.org/repos/asf/james-project/blob/71c05bde/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java index c9a7b26..33e2d76 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java @@ -30,6 +30,7 @@ import javax.mail.Flags; import javax.mail.Flags.Flag; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.james.jmap.model.MessageFactory.MetaDataWithContent; import org.apache.james.jmap.utils.HtmlTextExtractor; import org.apache.james.mailbox.MessageUid; @@ -292,4 +293,24 @@ public class MessageFactoryTest { assertThat(testee.getCc()).contains(usercc); assertThat(testee.getBcc()).contains(userbcc); } + + @Test + public void mailWithBigLinesShouldBeLoadedIntoMessage() throws Exception { + MetaDataWithContent testMail = MetaDataWithContent.builder() + .uid(MessageUid.of(2)) + .flags(new Flags(Flag.SEEN)) + .size(1010) + .internalDate(INTERNAL_DATE) + .content(new ByteArrayInputStream((StringUtils.repeat("0123456789", 101).getBytes(Charsets.UTF_8)))) + .attachments(ImmutableList.of()) + .mailboxId(MAILBOX_ID) + .messageId(MessageId.of("test|test|2")) + .build(); + + Message testee = messageFactory.fromMetaDataWithContent(testMail); + assertThat(testee) + .extracting(Message::getPreview, Message::getSize, Message::getSubject, Message::getHeaders, Message::getDate) + .containsExactly("(Empty)", 1010L, "", ImmutableMap.of("Date", "Tue, 14 Jul 2015 12:30:42 +0000", "MIME-Version", "1.0"), ZONED_DATE); + } + } --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org