You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2021/06/08 11:39:52 UTC

[GitHub] [james-project] chibenwa commented on a change in pull request #479: JAMES-2989 Preview should not normalize spaces of the entire body

chibenwa commented on a change in pull request #479:
URL: https://github.com/apache/james-project/pull/479#discussion_r647356405



##########
File path: server/data/data-jmap/src/main/java/org/apache/james/jmap/api/model/Preview.java
##########
@@ -88,15 +89,30 @@ public static Preview from(String value) {
     }
 
     public static Preview compute(String textBody) {
+        int previewOffsetEstimate = estimatePreviewOffset(textBody, MAX_LENGTH);
+        String previewPart = textBody.substring(0, previewOffsetEstimate);
         return Preview.from(
             truncateToMaxLength(
-                StringUtils.normalizeSpace(textBody)));
+                StringUtils.normalizeSpace(previewPart)));
     }
 
     private static String truncateToMaxLength(String body) {
         return StringUtils.left(body, MAX_LENGTH);
     }
 
+    private static int estimatePreviewOffset(String body, int charCount) {
+        AtomicInteger position = new AtomicInteger(0);
+
+        body.chars()
+            .mapToObj(i -> (char) i)

Review comment:
       I must admit I hesitated with a loop version. Cleaner, agreed!




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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