Repository: james-project
Updated Branches:
  refs/heads/master 7db19eca7 -> ed4660dcf


JAMES-2017 Preview message should not contain ellipsis


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

Branch: refs/heads/master
Commit: ed4660dcf9d98a928deb7aa3f69c8584e6c3e1ac
Parents: 7db19ec
Author: quynhn <qngu...@linagora.com>
Authored: Fri May 5 15:41:38 2017 +0700
Committer: quynhn <qngu...@linagora.com>
Committed: Mon May 8 16:34:42 2017 +0700

----------------------------------------------------------------------
 .../apache/james/jmap/model/MessagePreviewGenerator.java |  6 +++---
 .../org/apache/james/jmap/model/MessageFactoryTest.java  |  4 ++--
 .../james/jmap/model/MessagePreviewGeneratorTest.java    | 11 ++++++++++-
 3 files changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/ed4660dc/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 b5a15ea..dd1a831 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
@@ -30,11 +30,11 @@ public class MessagePreviewGenerator {
 
     public String compute(Optional<String> textBody) {
         return textBody.filter(text -> !text.isEmpty())
-                .map(this::abbreviate)
+                .map(this::truncateToMaxLength)
                 .orElse(NO_BODY);
     }
 
-    private String abbreviate(String body) {
-        return StringUtils.abbreviate(body, MAX_PREVIEW_LENGTH);
+    private String truncateToMaxLength(String body) {
+        return StringUtils.left(body, MAX_PREVIEW_LENGTH);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/ed4660dc/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 af0abd2..992c6ab 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
@@ -234,7 +234,7 @@ public class MessageFactoryTest {
                 + 
"0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999";
         String expectedPreview = 
"0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999"
 
                 + 
"0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999"
 
-                + "00000000001111111111222222222233333333334444444444555...";
+                + "00000000001111111111222222222233333333334444444444555555";
         assertThat(body300.length()).isEqualTo(300);
         assertThat(expectedPreview.length()).isEqualTo(256);
         String mail = headers + "\n" + body300;
@@ -408,7 +408,7 @@ public class MessageFactoryTest {
             + "000000000011111111112222222222333333333344444444445555555";
         String expected = "This is a HTML mail containing underlined part, 
italic part and underlined AND italic part9999999999"
             + 
"0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999"
-            + "00000000001111111111222222222233333333334444444444555...";
+            + "00000000001111111111222222222233333333334444444444555555";
 
         ByteArrayInputStream messageContent = new 
ByteArrayInputStream(("CContent-Type: text/html\r\n"
             + "Subject: message 1 subject\r\n"

http://git-wip-us.apache.org/repos/asf/james-project/blob/ed4660dc/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 7874117..54930a9 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,9 +47,18 @@ public class MessagePreviewGeneratorTest {
     }
 
     @Test
+    public void computeShouldReturnStringWithoutTruncation() throws Exception {
+        String body = StringUtils.leftPad("a", 100, "b");
+
+        assertThat(testee.compute(Optional.of(body)))
+                .hasSize(100)
+                .isEqualTo(body);
+    }
+
+    @Test
     public void computeShouldReturnStringIsLimitedTo256Length() throws 
Exception {
         String body = StringUtils.leftPad("a", 300, "b");
-        String expected = StringUtils.leftPad("b", 
MessagePreviewGenerator.MAX_PREVIEW_LENGTH - 3, "b") + "...";
+        String expected = StringUtils.leftPad("b", 
MessagePreviewGenerator.MAX_PREVIEW_LENGTH, "b");
 
         assertThat(testee.compute(Optional.of(body)))
             .hasSize(MessagePreviewGenerator.MAX_PREVIEW_LENGTH)


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to