james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [4/8] james-project git commit: JAMES-2042 MessagePreviewGenerator was not filtering mails with only spaces
Date Fri, 02 Jun 2017 12:02:19 GMT
JAMES-2042 MessagePreviewGenerator was not filtering mails with only spaces

Leading to empty preview, violating assumptions later on in MessageFactory


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

Branch: refs/heads/master
Commit: 58f626f1fe6c9cc02a3a274dc1ea0556c9eafa63
Parents: 9914890
Author: benwa <btellier@linagora.com>
Authored: Fri Jun 2 10:07:40 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Fri Jun 2 18:59:08 2017 +0700

----------------------------------------------------------------------
 .../jmap/model/MessagePreviewGenerator.java     |  9 +++++----
 .../jmap/model/MessagePreviewGeneratorTest.java | 20 ++++++++++++++++++++
 2 files changed, 25 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/58f626f1/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessagePreviewGenerator.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessagePreviewGenerator.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessagePreviewGenerator.java
index 3e4ed12..249a546 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessagePreviewGenerator.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessagePreviewGenerator.java
@@ -29,12 +29,13 @@ public class MessagePreviewGenerator {
     public static final int MAX_PREVIEW_LENGTH = 256;
 
     public String compute(Optional<String> textBody) {
-        return textBody.filter(text -> !text.isEmpty())
-                .map(this::truncateToMaxLength)
-                .orElse(NO_BODY);
+        return textBody.map(StringUtils::normalizeSpace)
+            .filter(text -> !text.isEmpty())
+            .map(this::truncateToMaxLength)
+            .orElse(NO_BODY);
     }
 
     private String truncateToMaxLength(String body) {
-        return StringUtils.left(StringUtils.normalizeSpace(body), MAX_PREVIEW_LENGTH);
+        return StringUtils.left(body, MAX_PREVIEW_LENGTH);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/58f626f1/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessagePreviewGeneratorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessagePreviewGeneratorTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessagePreviewGeneratorTest.java
index dd7eef0..bc5ba51 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessagePreviewGeneratorTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessagePreviewGeneratorTest.java
@@ -47,6 +47,26 @@ public class MessagePreviewGeneratorTest {
     }
 
     @Test
+    public void computeShouldReturnStringEmptyWhenOnlySpaceTabAndBreakLines() throws Exception
{
+        assertThat(testee.compute(Optional.of(" \n\t "))).isEqualTo(MessagePreviewGenerator.NO_BODY);
+    }
+
+    @Test
+    public void computeShouldReturnStringEmptyWhenOnlySpace() throws Exception {
+        assertThat(testee.compute(Optional.of(" "))).isEqualTo(MessagePreviewGenerator.NO_BODY);
+    }
+
+    @Test
+    public void computeShouldReturnStringEmptyWhenOnlyTab() throws Exception {
+        assertThat(testee.compute(Optional.of("\t"))).isEqualTo(MessagePreviewGenerator.NO_BODY);
+    }
+
+    @Test
+    public void computeShouldReturnStringEmptyWhenOnlyBreakLines() throws Exception {
+        assertThat(testee.compute(Optional.of("\n"))).isEqualTo(MessagePreviewGenerator.NO_BODY);
+    }
+
+    @Test
     public void computeShouldReturnStringWithoutTruncation() throws Exception {
         String body = StringUtils.leftPad("a", 100, "b");
 


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