Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ private static String decodeWord(final String word) throws ParseException, Unsup

final var encodedData = encodedText.getBytes(StandardCharsets.US_ASCII);

// Base64 encoded?
if (encoding.equals(BASE64_ENCODING_MARKER)) {
// Base64 encoded? RFC 2047 section 2 defines the encoding token as case-independent, so 'b' and 'q' are also valid.
if (encoding.equalsIgnoreCase(BASE64_ENCODING_MARKER)) {
out.write(Base64.getMimeDecoder().decode(encodedData));
} else if (encoding.equals(QUOTEDPRINTABLE_ENCODING_MARKER)) { // maybe quoted printable.
} else if (encoding.equalsIgnoreCase(QUOTEDPRINTABLE_ENCODING_MARKER)) { // maybe quoted printable.
QuotedPrintableDecoder.decode(encodedData, out);
} else {
throw new UnsupportedEncodingException("Unknown RFC 2047 encoding: " + encoding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,23 @@ void testDecodeUtf8Base64Encoded() throws Exception {
assertEncoded(" h\u00e9! \u00e0\u00e8\u00f4u !!!", "=?UTF-8?B?IGjDqSEgw6DDqMO0dSAhISE=?=");
}

@Test
void testDecodeUtf8Base64EncodedLowerCaseMarker() throws Exception {
// RFC 2047 section 2: the encoding token is case-independent, so 'b' decodes like 'B'.
assertEncoded(" h\u00e9! \u00e0\u00e8\u00f4u !!!", "=?UTF-8?b?IGjDqSEgw6DDqMO0dSAhISE=?=");
}

@Test
void testDecodeUtf8QuotedPrintableEncoded() throws Exception {
assertEncoded(" h\u00e9! \u00e0\u00e8\u00f4u !!!", "=?UTF-8?Q?_h=C3=A9!_=C3=A0=C3=A8=C3=B4u_!!!?=");
}

@Test
void testDecodeUtf8QuotedPrintableEncodedLowerCaseMarker() throws Exception {
// RFC 2047 section 2: the encoding token is case-independent, so 'q' decodes like 'Q'.
assertEncoded(" h\u00e9! \u00e0\u00e8\u00f4u !!!", "=?UTF-8?q?_h=C3=A9!_=C3=A0=C3=A8=C3=B4u_!!!?=");
}

@Test
void testNoNeedToDecode() throws Exception {
assertEncoded("abc", "abc");
Expand Down
Loading