This is an automated email from the ASF dual-hosted git repository. chibenwa pushed a commit to branch fetch-packet-fragmentation in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 6f9d2a041728a6b3f8e7c36628b22d45ee2fda6d Author: Benoit TELLIER <[email protected]> AuthorDate: Tue Jul 21 08:46:24 2026 +0200 fixup! fixup! fixup! [ENHANCEMENT] Prevent FETCH fragmentation --- .../apache/james/imap/message/SequencedLiteral.java | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/SequencedLiteral.java b/protocols/imap/src/main/java/org/apache/james/imap/message/SequencedLiteral.java index 4623d7f25d..0fb6e7705d 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/message/SequencedLiteral.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/message/SequencedLiteral.java @@ -22,8 +22,6 @@ package org.apache.james.imap.message; import java.io.IOException; import java.io.InputStream; import java.io.SequenceInputStream; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.Vector; @@ -60,15 +58,24 @@ public class SequencedLiteral implements Literal { @Override public Optional<byte[][]> asBytesSequence() { - List<byte[]> chunks = new ArrayList<>(); - for (Literal part : parts) { - Optional<byte[][]> partChunks = part.asBytesSequence(); + byte[][][] partsChunks = new byte[parts.size()][][]; + int count = 0; + for (int i = 0; i < parts.size(); i++) { + Optional<byte[][]> partChunks = parts.get(i).asBytesSequence(); if (partChunks.isEmpty()) { // A single non-in-memory part forces the whole sequence to be streamed. return Optional.empty(); } - Collections.addAll(chunks, partChunks.get()); + partsChunks[i] = partChunks.get(); + count += partsChunks[i].length; + } + byte[][] chunks = new byte[count][]; + int index = 0; + for (byte[][] partChunks : partsChunks) { + for (byte[] chunk : partChunks) { + chunks[index++] = chunk; + } } - return Optional.of(chunks.toArray(new byte[0][])); + return Optional.of(chunks); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
