Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIME4J-283 DecoderUtil performance fix #26

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -35,7 +35,7 @@
public class DecoderUtil {

private static final Pattern PATTERN_ENCODED_WORD = Pattern.compile(
"(.*?)=\\?(.+?)\\?(\\w)\\?(.*?)\\?=", Pattern.DOTALL);
"=\\?(.+?)\\?(\\w)\\?(.*?)\\?=", Pattern.DOTALL);

/**
* Decodes a string containing quoted-printable encoded data.
Expand Down Expand Up @@ -178,17 +178,18 @@ public static String decodeEncodedWords(String body, DecodeMonitor monitor, Char
StringBuilder sb = new StringBuilder();

for (Matcher matcher = PATTERN_ENCODED_WORD.matcher(body); matcher.find();) {
String separator = matcher.group(1);
String mimeCharset = matcher.group(2);
String encoding = matcher.group(3);
String encodedText = matcher.group(4);
String separator = body.substring(tailIndex, matcher.start());
String mimeCharset = matcher.group(1);
String encoding = matcher.group(2);
String encodedText = matcher.group(3);

if ("".equals(encodedText))
if (encodedText.isEmpty())
return "";

String decoded;
decoded = tryDecodeEncodedWord(mimeCharset, encoding, encodedText, monitor, fallback);
if (decoded == null) {
sb.append(separator);
sb.append(matcher.group(0));
} else {
if (!lastMatchValid || !CharsetUtil.isWhitespace(separator)) {
Expand Down