You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2026/09/03 04:26:51 UTC
(james-mime4j) 03/04: [FIX] Linear accumulation of mime parameters
This is an automated email from the ASF dual-hosted git repository.
chibenwa pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-mime4j.git
commit f085de76bd926b33461ad07a28a8bcaf1acd7db4
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Mon Aug 31 16:08:41 2026 +0200
[FIX] Linear accumulation of mime parameters
---
.../james/mime4j/util/MimeParameterMapping.java | 14 ++----
.../mime4j/util/MimeParameterMappingTest.java | 55 ++++++++++++++++++++++
2 files changed, 60 insertions(+), 9 deletions(-)
diff --git a/core/src/main/java/org/apache/james/mime4j/util/MimeParameterMapping.java b/core/src/main/java/org/apache/james/mime4j/util/MimeParameterMapping.java
index 07d6b5d8..85c45398 100644
--- a/core/src/main/java/org/apache/james/mime4j/util/MimeParameterMapping.java
+++ b/core/src/main/java/org/apache/james/mime4j/util/MimeParameterMapping.java
@@ -73,7 +73,7 @@ public class MimeParameterMapping {
private final Set<String> parameterNames = new HashSet<>();
private final Map<String, String> standard = new HashMap<>();
private final Map<String, String> extended = new HashMap<>();
- private final Map<String, String> continuation = new HashMap<>();
+ private final Map<String, StringBuilder> continuation = new HashMap<>();
private final Map<String, String> parameters = new HashMap<>();
private boolean needToUpdate = true;
@@ -122,7 +122,7 @@ public class MimeParameterMapping {
}
if (continuation.containsKey(name)) {
try {
- return decodeParameterValue(continuation.get(name));
+ return decodeParameterValue(continuation.get(name).toString());
} catch (DecodeException e) {
//ignore and try standard
}
@@ -141,7 +141,7 @@ public class MimeParameterMapping {
}
if (continuation.containsKey(name)) {
- return continuation.get(name);
+ return continuation.get(name).toString();
}
if (extended.containsKey(name)) {
@@ -160,12 +160,8 @@ public class MimeParameterMapping {
extended.putIfAbsent(parameterTypePair.fieldName, value);
break;
case CONTINUATION:
- if (continuation.containsKey(parameterTypePair.fieldName)) {
- String newValue = continuation.get(parameterTypePair.fieldName) + value;
- continuation.put(parameterTypePair.fieldName, newValue);
- } else {
- continuation.put(parameterTypePair.fieldName, value);
- }
+ continuation.computeIfAbsent(parameterTypePair.fieldName, k -> new StringBuilder())
+ .append(value);
break;
case STANDARD:
standard.putIfAbsent(parameterTypePair.fieldName, value);
diff --git a/core/src/test/java/org/apache/james/mime4j/util/MimeParameterMappingTest.java b/core/src/test/java/org/apache/james/mime4j/util/MimeParameterMappingTest.java
new file mode 100644
index 00000000..90450845
--- /dev/null
+++ b/core/src/test/java/org/apache/james/mime4j/util/MimeParameterMappingTest.java
@@ -0,0 +1,55 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.mime4j.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class MimeParameterMappingTest {
+
+ @Test
+ public void continuationSegmentsShouldBeConcatenatedInOrder() {
+ MimeParameterMapping mapping = new MimeParameterMapping();
+ mapping.addParameter("filename*0", "abc");
+ mapping.addParameter("filename*1", "def");
+ mapping.addParameter("filename*2", "ghi");
+ Assert.assertEquals("abcdefghi", mapping.get("filename"));
+ }
+
+ @Test
+ public void continuationSegmentsShouldBeReadableRepeatedly() {
+ MimeParameterMapping mapping = new MimeParameterMapping();
+ mapping.addParameter("filename*0", "abc");
+ mapping.addParameter("filename*1", "def");
+ Assert.assertEquals("abcdef", mapping.get("filename"));
+ Assert.assertEquals("abcdef", mapping.get("filename"));
+ Assert.assertEquals("abcdef", mapping.getParameters().get("filename"));
+ }
+
+ @Test(timeout = 15000)
+ public void manyContinuationSegmentsShouldStayLinear() {
+ int segments = 200000;
+ MimeParameterMapping mapping = new MimeParameterMapping();
+ for (int i = 0; i < segments; i++) {
+ mapping.addParameter("filename*" + i, "0123456789");
+ }
+ Assert.assertEquals(segments * 10, mapping.get("filename").length());
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org