You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by ka...@apache.org on 2022/11/03 07:53:31 UTC

[james-project] branch master updated: JAMES-3846 Improve vacation notice appearance

This is an automated email from the ASF dual-hosted git repository.

kao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git


The following commit(s) were added to refs/heads/master by this push:
     new f1496567bc JAMES-3846 Improve vacation notice appearance
f1496567bc is described below

commit f1496567bcd4220ddfeac2c79a7532fa3fe14f72
Author: Karsten Otto <ka...@akquinet.de>
AuthorDate: Wed Nov 2 13:15:18 2022 +0100

    JAMES-3846 Improve vacation notice appearance
---
 .../james/transport/util/MimeMessageBodyGenerator.java   |  6 +++---
 .../transport/util/MimeMessageBodyGeneratorTest.java     | 16 ++++++++++++++++
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/util/MimeMessageBodyGenerator.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/util/MimeMessageBodyGenerator.java
index 374b069a9e..5673b4aa9b 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/util/MimeMessageBodyGenerator.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/util/MimeMessageBodyGenerator.java
@@ -38,7 +38,7 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 
 public class MimeMessageBodyGenerator {
-    public static final String MIXED = "mixed";
+    public static final String ALTERNATIVE = "alternative";
     public static final String EMPTY_TEXT = "";
 
     private final HtmlTextExtractor htmlTextExtractor;
@@ -63,7 +63,7 @@ public class MimeMessageBodyGenerator {
 
     private Multipart generateMultipart(String htmlText, Optional<String> plainText) throws MessagingException {
         try {
-            Multipart multipart = new MimeMultipart(MIXED);
+            Multipart multipart = new MimeMultipart(ALTERNATIVE);
             addTextPart(multipart, htmlText, "text/html");
             addTextPart(multipart, retrievePlainTextMessage(plainText, htmlText), ContentTypeField.TYPE_TEXT_PLAIN);
             return multipart;
@@ -84,7 +84,7 @@ public class MimeMessageBodyGenerator {
     }
 
     private String retrievePlainTextMessage(Optional<String> plainText, String htmlText) {
-        return plainText.orElseGet(() -> htmlTextExtractor.toPlainText(htmlText));
+        return plainText.filter(text -> !text.isBlank()).orElseGet(() -> htmlTextExtractor.toPlainText(htmlText));
     }
 
 }
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/util/MimeMessageBodyGeneratorTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/util/MimeMessageBodyGeneratorTest.java
index 4dc4a6b09a..7d669eb883 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/util/MimeMessageBodyGeneratorTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/util/MimeMessageBodyGeneratorTest.java
@@ -90,6 +90,22 @@ public class MimeMessageBodyGeneratorTest {
         assertThat(rowContent).containsSequence(plainText);
     }
 
+    @Test
+    public void fromShouldProvideAPlainTextVersionWhenHtmlAndEmptyText() throws Exception {
+        String htmlText = "<p>HTML text</p>";
+        String plainText = "Plain text";
+        when(htmlTextExtractor.toPlainText(htmlText)).thenReturn(plainText);
+
+        String rowContent = IOUtils.toString(
+            mimeMessageBodyGenerator.from(original,
+                    Optional.of(""),
+                    Optional.of(htmlText))
+                .getInputStream(), StandardCharsets.UTF_8);
+
+        assertThat(rowContent).containsSequence(htmlText);
+        assertThat(rowContent).containsSequence(plainText);
+    }
+
     @Test
     public void fromShouldCombinePlainTextAndHtml() throws Exception {
         String htmlText = "<p>HTML text</p>";


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