This is an automated email from the ASF dual-hosted git repository.
Arsnael pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-mime4j.git
The following commit(s) were added to refs/heads/master by this push:
new 2dee0e7a MIME4J-335 DecoderUtil: treat a null DecodeMonitor as SILENT
2dee0e7a is described below
commit 2dee0e7a2ef4df0f246cdacbd727e359ac61ba89
Author: OldTruckDriver <[email protected]>
AuthorDate: Sun Nov 8 02:19:30 2026 +1100
MIME4J-335 DecoderUtil: treat a null DecodeMonitor as SILENT
decodeEncodedWords(String, Charset) passed null as the DecodeMonitor to
the four-argument implementation. The monitor is dereferenced by
DecoderUtil.monitor(...) and by the decoding streams, so any encoded
word that could not be decoded, such as a base64 word without padding,
an unknown encoding or malformed Q text, made this overload throw a
NullPointerException.
A null monitor is now replaced by DecodeMonitor.SILENT at the entry of
the four-argument implementation. This also covers callers that pass
null explicitly to the three- and four-argument overloads, and makes the
Charset overload return what the DecodeMonitor.SILENT overload returns.
---
.../org/apache/james/mime4j/codec/DecoderUtil.java | 3 +++
.../apache/james/mime4j/codec/DecoderUtilTest.java | 25 ++++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/core/src/main/java/org/apache/james/mime4j/codec/DecoderUtil.java
b/core/src/main/java/org/apache/james/mime4j/codec/DecoderUtil.java
index feffa60e..9cd44c7d 100644
--- a/core/src/main/java/org/apache/james/mime4j/codec/DecoderUtil.java
+++ b/core/src/main/java/org/apache/james/mime4j/codec/DecoderUtil.java
@@ -215,6 +215,9 @@ public class DecoderUtil {
public static String decodeEncodedWords(String body, DecodeMonitor
monitor, Charset fallback,
Map<Charset, Charset> charsetOverrides)
throws IllegalArgumentException {
+ if (monitor == null) {
+ monitor = DecodeMonitor.SILENT;
+ }
ByteArrayOutputStream out = new ByteArrayOutputStream();
StringBuilder sb = new StringBuilder();
diff --git
a/core/src/test/java/org/apache/james/mime4j/codec/DecoderUtilTest.java
b/core/src/test/java/org/apache/james/mime4j/codec/DecoderUtilTest.java
index c65574e0..816ab944 100644
--- a/core/src/test/java/org/apache/james/mime4j/codec/DecoderUtilTest.java
+++ b/core/src/test/java/org/apache/james/mime4j/codec/DecoderUtilTest.java
@@ -209,4 +209,29 @@ public class DecoderUtilTest {
Assert.assertEquals("ab =?x?q?c =?y",
DecoderUtil.decodeEncodedWords("=?utf-8?q?a?= =?utf-8?q?b?=
=?x?q?c =?y", DecodeMonitor.SILENT));
}
+
+ @Test
+ public void
decodeEncodedWordsWithFallbackShouldBehaveLikeSilentMonitorOnUndecodableWords()
{
+ Charset fallback = Charset.forName("ISO-8859-1");
+ String[] inputs = {
+ "=?UTF-8?B?QQ?=",
+ "=?ISO-8859-1?R?abc?=",
+ "=?ISO-8859-1?Q?=ZZ?=",
+ "=?ISO-8859-1?B?@@@@?=",
+ "test =?ISO-8859-1?R?abc?="
+ };
+ for (String input : inputs) {
+ Assert.assertEquals(input,
+ DecoderUtil.decodeEncodedWords(input, DecodeMonitor.SILENT,
fallback),
+ DecoderUtil.decodeEncodedWords(input, fallback));
+ }
+ }
+
+ @Test
+ public void decodeEncodedWordsShouldTreatNullMonitorAsSilent() {
+ String input = "=?FOO-BAR?Q?abc?=";
+ Assert.assertEquals(
+ DecoderUtil.decodeEncodedWords(input, DecodeMonitor.SILENT, null),
+ DecoderUtil.decodeEncodedWords(input, (DecodeMonitor) null, null));
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]