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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to