mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-24 02:12:15 -05:00
Fixed MimeUtility.getHeaderParameter() to not crash on unexpected input
This commit is contained in:
parent
561d2a1a44
commit
aeb0220e56
@ -953,16 +953,20 @@ public class MimeUtility {
|
|||||||
}
|
}
|
||||||
header = header.replaceAll("\r|\n", "");
|
header = header.replaceAll("\r|\n", "");
|
||||||
String[] parts = header.split(";");
|
String[] parts = header.split(";");
|
||||||
if (name == null) {
|
if (name == null && parts.length > 0) {
|
||||||
return parts[0];
|
return parts[0];
|
||||||
}
|
}
|
||||||
for (String part : parts) {
|
for (String part : parts) {
|
||||||
if (part.trim().toLowerCase(Locale.US).startsWith(name.toLowerCase(Locale.US))) {
|
if (part.trim().toLowerCase(Locale.US).startsWith(name.toLowerCase(Locale.US))) {
|
||||||
String parameter = part.split("=", 2)[1].trim();
|
String[] partParts = part.split("=", 2);
|
||||||
if (parameter.startsWith("\"") && parameter.endsWith("\"")) {
|
if (partParts.length == 2) {
|
||||||
return parameter.substring(1, parameter.length() - 1);
|
String parameter = partParts[1].trim();
|
||||||
} else {
|
int len = parameter.length();
|
||||||
return parameter;
|
if (len >= 2 && parameter.startsWith("\"") && parameter.endsWith("\"")) {
|
||||||
|
return parameter.substring(1, len - 1);
|
||||||
|
} else {
|
||||||
|
return parameter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user