JAMES-1781 MimeBodyMessageGenerator should back up to an empty text
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/9f4efcdf Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/9f4efcdf Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/9f4efcdf Branch: refs/heads/master Commit: 9f4efcdfbd2f10bb2e734fdf8ead720149123616 Parents: 6da5984 Author: Benoit Tellier <[email protected]> Authored: Tue Jun 28 10:52:22 2016 +0700 Committer: Benoit Tellier <[email protected]> Committed: Thu Sep 29 12:48:14 2016 +0200 ---------------------------------------------------------------------- .../apache/james/jmap/utils/MimeMessageBodyGenerator.java | 4 ++-- .../james/jmap/utils/MimeMessageBodyGeneratorTest.java | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/9f4efcdf/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MimeMessageBodyGenerator.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MimeMessageBodyGenerator.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MimeMessageBodyGenerator.java index e0704ca..9573c42 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MimeMessageBodyGenerator.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MimeMessageBodyGenerator.java @@ -39,6 +39,7 @@ import com.google.common.base.Preconditions; public class MimeMessageBodyGenerator { public static final String MIXED = "mixed"; + public static final String EMPTY_TEXT = ""; private final HtmlTextExtractor htmlTextExtractor; @@ -52,11 +53,10 @@ public class MimeMessageBodyGenerator { Preconditions.checkNotNull(messageHoldingHeaders); Preconditions.checkNotNull(plainText); Preconditions.checkNotNull(htmlText); - Preconditions.checkState(plainText.isPresent() || htmlText.isPresent(), "MimeMessageBodyGenerator needs at least plainText or html text"); if (htmlText.isPresent()) { messageHoldingHeaders.setContent(generateMultipart(htmlText.get(), plainText)); } else { - plainText.ifPresent(Throwing.consumer(messageHoldingHeaders::setText)); + messageHoldingHeaders.setText(plainText.orElse(EMPTY_TEXT)); } return messageHoldingHeaders; } http://git-wip-us.apache.org/repos/asf/james-project/blob/9f4efcdf/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MimeMessageBodyGeneratorTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MimeMessageBodyGeneratorTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MimeMessageBodyGeneratorTest.java index b525660..0eb2880 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MimeMessageBodyGeneratorTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MimeMessageBodyGeneratorTest.java @@ -106,11 +106,13 @@ public class MimeMessageBodyGeneratorTest { } @Test - public void fromShouldThrowWhenNoPlainTextNorHtmlBody() throws Exception { - assertThatThrownBy(() -> mimeMessageBodyGenerator.from(original, + public void fromShouldUseEmptyTextWhenNoPlainTextNorHtmlBody() throws Exception { + String rowContent = IOUtils.toString(mimeMessageBodyGenerator.from(original, Optional.empty(), - Optional.empty())) - .isInstanceOf(IllegalStateException.class); + Optional.empty()) + .getInputStream()); + + assertThat(rowContent).isEmpty(); } @Test --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
